Compare commits

...

2 Commits

Author SHA1 Message Date
348ee8ea2a revert pixiv-embedded to using html because ajax not work on R-18
infer all "page" urls based on pageCount

!@
2021-08-23 17:08:14 -07:00
47d33f6667 commit wip before reverse plan 2021-08-23 16:53:38 -07:00

View File

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