Compare commits
No commits in common. "0626be1ec37883035e0ad530d9c1e8ff635bb89f" and "491af971dc61d4e6bf1d0fded61415d7287ee228" have entirely different histories.
0626be1ec3
...
491af971dc
@ -8,11 +8,9 @@ client.on("messageCreate", async message => {
|
||||
if (message.guild.id != config.guild) 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));
|
||||
let include_url = pixiv_urls.size > 1;
|
||||
if (!pixiv_urls.size) {
|
||||
//todo refactor to implement this properly
|
||||
if (message.content.toLowerCase().startsWith("!miku")) {
|
||||
include_url = true;
|
||||
pixiv_urls.add(`https://www.pixiv.net/en/artworks/${random(mikutachi)}`);
|
||||
} else return;
|
||||
}
|
||||
@ -32,7 +30,7 @@ client.on("messageCreate", async message => {
|
||||
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 content;
|
||||
if (include_url || illust.illustType == 2) {
|
||||
if (pixiv_urls.size > 1 || illust.illustType == 2) {
|
||||
content = `<${pixiv_url}>${illust.illustType == 2 ? " is an animation (must open link to play)" : ''}`;
|
||||
}
|
||||
let images = [];
|
||||
@ -44,7 +42,7 @@ client.on("messageCreate", async message => {
|
||||
}
|
||||
await message.channel.send({
|
||||
content,
|
||||
files: images.map(image => ({attachment: image.data || "error", name: ((illust.xRestrict && !message.channel.nsfw) ? 'SPOILER_' : '') + image.url.split('/').pop()}))
|
||||
files: images.map(image => ({attachment: image.data || "error", name: (illust.xRestrict ? 'SPOILER_' : '') + image.url.split('/').pop()}))
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.message == "Request entity too large") await fallback();
|
||||
@ -55,7 +53,7 @@ client.on("messageCreate", async message => {
|
||||
// save the data already downloaded
|
||||
for (let image of images) if (image.data) fs.writeFileSync(config.data_dir + "pixiv-cache/" + image.url.split('?')[0].replace(/\//g, '\\'), image.data);
|
||||
let urls = images.map(image => image.url.replace("https://i.pximg.net/", `https://${config.web_hostname}/pixiv-proxy/`));
|
||||
if (illust.xRestrict && !message.channel.nsfw) urls = urls.map(url => `||${url} ||`);
|
||||
if (illust.xRestrict) urls = urls.map(url => `||${url} ||`);
|
||||
urls = urls.join('\n');
|
||||
if (urls.length > 2000) {
|
||||
return message.channel.send({content, files:[{attachment: Buffer.from(urls), name:"message.txt"}]});
|
||||
@ -65,7 +63,7 @@ client.on("messageCreate", async message => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("pixiv embed error,", error.stack);
|
||||
if (include_url) {
|
||||
if (pixiv_urls.size > 1) {
|
||||
message.channel.send(`<${pixiv_url}> failed to be embedded`);
|
||||
} else {
|
||||
message.react('⚠');
|
||||
|
Loading…
Reference in New Issue
Block a user