Compare commits

..

No commits in common. "348ee8ea2a5e1798dd42f118e072fdc903e7c438" and "ce435d01a16bc5dfcd15c63182a7728b3edb47cc" have entirely different histories.

View File

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