multiple images in one upload

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

@ -301,6 +301,11 @@ module.exports = {
if (['i', 'im', 'img', 'image'].includes(args[0].toLowerCase())) {
args.shift();
let list = false;
if (args[0] && ['l', 'list'].includes(args[0].toLowerCase())) {
list = true;
args.shift();
}
if (!args[0]) {
let tempchar = await ask(message, "What character would you like to add to add an image to?", 60000, false, true);
if (!tempchar) {return;}
@ -331,7 +336,25 @@ module.exports = {
queue = true;
}
let ch = await Char.findOne({id: fn});
if (list) {
let pages = ch.images.map(im => new Discord.MessageEmbed()
.setTitle(ch.name)
.setDescription(`**Name:** ${ch.name}`)
.addField('Other', `**Anime**: ${client.misc.cache.animeID.get(ch.anime)}\n\n**Gender**: ${ch.gender}\n`)
.setColor("c375f0")
.setImage(im)
);
if (pages.length > 1) {
let pag = new Pagination(message.channel, pages, message, client, true);
return await pag.start({user: message.author.id, time: 60000});
} else {return message.channel.send(pages[0].setTimestamp());}
} 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
@ -339,8 +362,13 @@ module.exports = {
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
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?");}
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');
@ -360,6 +388,28 @@ module.exports = {
], 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"}.`);
}
}
}
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();
if (!args[0]) {
let tempchar = await ask(message, "What character would you like to add to add a nickname to?", 60000, false, true);

@ -72,6 +72,10 @@ module.exports = {
} else {return message.channel.send(pages[0].setTimestamp());}
} 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
@ -79,8 +83,13 @@ module.exports = {
if (!tempchar) {return;}
args = tempchar.split(/\s+/g);
}
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?");}
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');
@ -100,6 +109,27 @@ module.exports = {
], 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"}.`);
}
}
}
};
Loading…
Cancel
Save