multiple images in one upload

master
Kit Kasune 3 years ago
parent 02468f48e1
commit c3888af276
  1. 108
      commands/anime/char.js
  2. 82
      commands/anime/charimage.js

@ -301,6 +301,11 @@ module.exports = {
if (['i', 'im', 'img', 'image'].includes(args[0].toLowerCase())) { if (['i', 'im', 'img', 'image'].includes(args[0].toLowerCase())) {
args.shift(); args.shift();
let list = false;
if (args[0] && ['l', 'list'].includes(args[0].toLowerCase())) {
list = true;
args.shift();
}
if (!args[0]) { if (!args[0]) {
let tempchar = await ask(message, "What character would you like to add to add an image to?", 60000, false, true); let tempchar = await ask(message, "What character would you like to add to add an image to?", 60000, false, true);
if (!tempchar) {return;} if (!tempchar) {return;}
@ -331,35 +336,80 @@ module.exports = {
queue = true; queue = true;
} }
let ch = await Char.findOne({id: fn}); let ch = await Char.findOne({id: fn});
args.shift();
if (!args[0]) { if (list) {
let tempchar = message.attachments.size let pages = ch.images.map(im => new Discord.MessageEmbed()
? message.attachments.first().url .setTitle(ch.name)
: await ask(message, "Please paste the image or a link to the image you'd like to add.", 60000, false, true); .setDescription(`**Name:** ${ch.name}`)
if (!tempchar) {return;} .addField('Other', `**Anime**: ${client.misc.cache.animeID.get(ch.anime)}\n\n**Gender**: ${ch.gender}\n`)
args = tempchar.split(/\s+/g); .setColor("c375f0")
} .setImage(im)
let img = args.join(" "); );
if (!img.match(/^https:\/\/(?:[\w\-].?)+[\/\w\-%()_]+\.(?:png|jpg|jpeg|gif|webp)$/gm)) {return message.channel.send("I don't think that's an image. Try again?");} if (pages.length > 1) {
if (!queue) { let pag = new Pagination(message.channel, pages, message, client, true);
ch.images.push(img); return await pag.start({user: message.author.id, time: 60000});
ch.markModified('images'); } else {return message.channel.send(pages[0].setTimestamp());}
ch.save(); } else {
args.shift();
let images = [];
if (message.attachments.size > 1) {
Array.from(message.attachments.keys()).forEach(i => images.push(message.attachments.get(i).url));
} else {
if (!args[0]) {
let tempchar = message.attachments.size
? message.attachments.first().url
: await ask(message, "Please paste the image or a link to the image you'd like to add.", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
images.push(args.join(" "));
}
let f;
images.forEach(img => {if (!img.match(/^https:\/\/(?:[\w\-].?)+[\/\w\-%()_]+\.(?:png|jpg|jpeg|gif|webp)$/gm)) {f = true; return message.channel.send("I don't think that's an image. Try again?");}})
if (f) {return;}
if (images.length === 1) {
let img = images[0];
if (!queue) {
ch.images.push(img);
ch.markModified('images');
ch.save();
}
client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('817466729293938698').send({
embeds: [
new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setTitle(`New Image ${queue ? "Submitted" : "Added"}`)
.setDescription(`For **${ch.name}** | \`${ch.id}\` from ${client.misc.cache.animeID.get(ch.anime)}`)
.setThumbnail(ch.thumbnail)
.setImage(img)
.setColor('c375f0')
.setTimestamp()
.setFooter("Natsuki")
], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {})).catch(() => {});
return message.channel.send(`Character image ${queue ? "submitted" : "added"}.`);
} else {
if (!queue) {
images.forEach(img => ch.images.push(img));
ch.markModified('images');
ch.save();
}
client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('817466729293938698').send({
embeds: [
new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setTitle(`New Images ${queue ? "Submitted" : "Added"}`)
.setDescription(`For **${ch.name}** | \`${ch.id}\` from ${client.misc.cache.animeID.get(ch.anime)}`)
.addField("Images", images.map(img => `${img}\n`).join(""))
.setThumbnail(ch.thumbnail)
.setColor('c375f0')
.setTimestamp()
.setFooter("Natsuki")
], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {})).catch(() => {});
return message.channel.send(`Character images ${queue ? "submitted" : "added"}.`);
}
} }
client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('817466729293938698').send({
embeds: [
new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setTitle(`New Image ${queue ? "Submitted" : "Added"}`)
.setDescription(`For **${ch.name}** | \`${ch.id}\` from ${client.misc.cache.animeID.get(ch.anime)}`)
.setThumbnail(ch.thumbnail)
.setImage(img)
.setColor('c375f0')
.setTimestamp()
.setFooter("Natsuki")
], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {})).catch(() => {});
return message.channel.send(`Character image ${queue ? "submitted" : "added"}.`);
} }
if (['la', 'listani', 'listanime', 'inani', 'inanime', 'ia'].includes(args[0].toLowerCase())) { if (['la', 'listani', 'listanime', 'inani', 'inanime', 'ia'].includes(args[0].toLowerCase())) {
@ -420,7 +470,7 @@ module.exports = {
} }
} }
if (['nn', 'nicknane', 'altname', 'nick'].includes(args[0].toLowerCase())) { if (['nn', 'nickname', 'altname', 'nick'].includes(args[0].toLowerCase())) {
args.shift(); args.shift();
if (!args[0]) { if (!args[0]) {
let tempchar = await ask(message, "What character would you like to add to add a nickname to?", 60000, false, true); let tempchar = await ask(message, "What character would you like to add to add a nickname to?", 60000, false, true);

@ -72,34 +72,64 @@ module.exports = {
} else {return message.channel.send(pages[0].setTimestamp());} } else {return message.channel.send(pages[0].setTimestamp());}
} else { } else {
args.shift(); args.shift();
if (!args[0]) { let images = [];
let tempchar = message.attachments.size if (message.attachments.size > 1) {
? message.attachments.first().url Array.from(message.attachments.keys()).forEach(i => images.push(message.attachments.get(i).url));
: await ask(message, "Please paste the image or a link to the image you'd like to add.", 60000, false, true); } else {
if (!tempchar) {return;} if (!args[0]) {
args = tempchar.split(/\s+/g); let tempchar = message.attachments.size
? message.attachments.first().url
: await ask(message, "Please paste the image or a link to the image you'd like to add.", 60000, false, true);
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
images.push(args.join(" "));
} }
let img = args.join(" "); let f;
if (!img.match(/^https:\/\/(?:[\w\-].?)+[\/\w\-%()_]+\.(?:png|jpg|jpeg|gif|webp)$/gm)) {return message.channel.send("I don't think that's an image. Try again?");} images.forEach(img => {if (!img.match(/^https:\/\/(?:[\w\-].?)+[\/\w\-%()_]+\.(?:png|jpg|jpeg|gif|webp)$/gm)) {f = true; return message.channel.send("I don't think that's an image. Try again?");}})
if (!queue) { if (f) {return;}
ch.images.push(img); if (images.length === 1) {
ch.markModified('images'); let img = images[0];
ch.save(); if (!queue) {
ch.images.push(img);
ch.markModified('images');
ch.save();
}
client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('817466729293938698').send({
embeds: [
new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setTitle(`New Image ${queue ? "Submitted" : "Added"}`)
.setDescription(`For **${ch.name}** | \`${ch.id}\` from ${client.misc.cache.animeID.get(ch.anime)}`)
.setThumbnail(ch.thumbnail)
.setImage(img)
.setColor('c375f0')
.setTimestamp()
.setFooter("Natsuki")
], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {})).catch(() => {});
return message.channel.send(`Character image ${queue ? "submitted" : "added"}.`);
} else {
if (!queue) {
images.forEach(img => ch.images.push(img));
ch.markModified('images');
ch.save();
}
client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('817466729293938698').send({
embeds: [
new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setTitle(`New Images ${queue ? "Submitted" : "Added"}`)
.setDescription(`For **${ch.name}** | \`${ch.id}\` from ${client.misc.cache.animeID.get(ch.anime)}`)
.addField("Images", images.map(img => `${img}\n`).join(""))
.setThumbnail(ch.thumbnail)
.setColor('c375f0')
.setTimestamp()
.setFooter("Natsuki")
], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {})).catch(() => {});
return message.channel.send(`Character images ${queue ? "submitted" : "added"}.`);
} }
client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('817466729293938698').send({
embeds: [
new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setTitle(`New Image ${queue ? "Submitted" : "Added"}`)
.setDescription(`For **${ch.name}** | \`${ch.id}\` from ${client.misc.cache.animeID.get(ch.anime)}`)
.setThumbnail(ch.thumbnail)
.setImage(img)
.setColor('c375f0')
.setTimestamp()
.setFooter("Natsuki")
], content: queue ? '<@330547934951112705>' : undefined
}).catch(() => {})).catch(() => {});
return message.channel.send(`Character image ${queue ? "submitted" : "added"}.`);
} }
} }
}; };
Loading…
Cancel
Save