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