Compare commits
2 Commits
ce435d01a1
...
348ee8ea2a
Author | SHA1 | Date | |
---|---|---|---|
348ee8ea2a | |||
47d33f6667 |
@ -4,8 +4,9 @@ var fs = require("fs");
|
||||
|
||||
client.on("messageCreate", async message => {
|
||||
if (message.guild.id != config.guild) return;
|
||||
let pixiv_ids = new Set(Array.from(message.content.matchAll(/https?:\/\/www\.pixiv\.net\/en\/artworks\/(\d+)\b/g)).map(x=>x[1]));
|
||||
if (!pixiv_ids.size) return;
|
||||
if (message.author.id == client.user.id) return;
|
||||
let pixiv_urls = new Set(message.content.match(/https?:\/\/www\.pixiv\.net\/en\/artworks\/\d+\b/g));
|
||||
if (!pixiv_urls.size) return;
|
||||
message.suppressEmbeds();
|
||||
// suppressing embeds doesn't work on embeds that load after
|
||||
client.on("messageUpdate", function arf(g,updatedMessage) {
|
||||
@ -18,14 +19,17 @@ client.on("messageCreate", async message => {
|
||||
client.removeListener("messageUpdate", arf);
|
||||
}
|
||||
});
|
||||
for (let pixiv_id of pixiv_ids) {
|
||||
for (let pixiv_url of pixiv_urls) {
|
||||
try {
|
||||
let json = await (await fetch(`https://www.pixiv.net/ajax/illust/${pixiv_id}/pages`)).text();
|
||||
let data = JSON.parse(json);
|
||||
if (data.error) { console.error(`pixiv ajax said error for ${pixiv_id}: ${data.error}`); continue}
|
||||
await message.channel.send(data.body.map(o => o.urls.original.replace("https://i.pximg.net/", `https://${config.web_hostname}/pixiv-proxy/`)).join('\n'));
|
||||
let illust = Object.values(JSON.parse((await (await fetch(pixiv_url)).text()).match(/<meta name="preload-data" id="meta-preload-data" content='(.*)'>/)[1]).illust)[0];
|
||||
let msg = "";
|
||||
for (let i = 0; i < illust.pageCount; i++) {
|
||||
msg += illust.urls.original.replace('p0', 'p'+i).replace("https://i.pximg.net/", `https://${config.web_hostname}/pixiv-proxy/`) + '\n';
|
||||
}
|
||||
await message.channel.send(msg);
|
||||
} catch (error) {
|
||||
console.error("pixiv embed error,", error.message);
|
||||
message.react('⚠');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user