From df2731bf6df6ff7cd076e61b5304a5bb74b501af Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Thu, 30 Dec 2021 04:02:02 -0700 Subject: [PATCH] anime alt names --- commands/anime/anime.js | 58 +++++++++++++++++++++++++++++++++++++++++ models/anime.js | 1 + util/cache/anime.js | 1 + 3 files changed, 60 insertions(+) diff --git a/commands/anime/anime.js b/commands/anime/anime.js index 18bb5be..68ea056 100644 --- a/commands/anime/anime.js +++ b/commands/anime/anime.js @@ -285,5 +285,63 @@ module.exports = { af.save(); return message.channel.send(`I've added **${tfc.name}** to your list of finished animes!`); } + + if (['nn', 'nickname', 'altname', 'nick', 'an'].includes(args[0].toLowerCase())) { + args.shift(); + if (!args[0]) { + let tempchar = await ask(message, "What anime would you like to add to add an alternate name to?", 60000, false, true); + if (!tempchar) {return;} + args = tempchar.split(/\s+/g); + } + let asr = await ans(message, client, args.join(" ").trim().toLowerCase(), -700, 0); + let fn; + if (asr === 0) { + return message.channel.send("That search returned no results! Try again?"); + } else if (asr instanceof Pagination) { + await asr.start({user: message.author.id, startPage: 1, endTime: 60000}); + await asr.message.react('✅'); + await message.channel.send("React with :white_check_mark: when you've found the anime you want!"); + let arc; + try {arc = await asr.message.awaitReactions({filter: (r) => ['✅', '⏹'].includes(r.emoji.name), max: 1, errors: ['time']});} + catch {return message.reply("Looks like you didn't find the anime you were looking for.");} + collected = arc.first().emoji.name; + if (collected === '✅') { + fn = client.misc.cache.chars.get(asr.getCurrentPage().title.trim()); + asr.stop(); + } + else {return message.reply("Looks like you didn't find the anime you were looking for.");} + } else {fn = asr.id;} + let tu = await UserData.findOne({uid: message.author.id}); + let queue = false; + if (!tu || !tu.staff) { + message.channel.send("This alternate name will be __submitted__ for reviewal."); + queue = true; + } + let ch = await AniData.findOne({id: fn}); + if (!ch.altNames) {ch.altNames = [];} + let nn = await ask(message, `What nickname would you like to add to ${ch.name}?`, 60000, false, true); + if (!nn) {return;} + if (ch.altNames.map(nickn => nickn.toLowerCase()).includes(nn.toLowerCase())) {return message.channel.send(`Looks like **${ch.name}** already has the nickname "${nn}".`);} + if (!queue) { + ch.altNames.push(nn); + ch.markModified('altNames'); + ch.save(); + client.misc.cache.anime.set(nn, ch.id); + } + client.guilds.fetch('762707532417335296').then(g => g.channels.cache.get('817466729293938698').send({ + embeds: [ + new Discord.MessageEmbed() + .setAuthor({name: message.author.username, iconURL: message.author.avatarURL()}) + .setTitle(`New Anime Alt Name ${queue ? "Submitted" : "Added"}`) + .setDescription(`For **${ch.name}** | \`${ch.id}\``) + .addField("Name", nn) + .setThumbnail(ch.thumbnail) + .setColor('c375f0') + .setTimestamp() + .setFooter({text: "Natsuki"}) + ], content: queue ? '<@330547934951112705>' : undefined + }).catch(() => {})).catch(() => {}); + return message.channel.send(`Anime alt name ${queue ? "submitted" : "added"}.`); + } } }; diff --git a/models/anime.js b/models/anime.js index 631b19a..c2303bd 100644 --- a/models/anime.js +++ b/models/anime.js @@ -15,6 +15,7 @@ const AniSchema = new mongoose.Schema({ genres: [String], tags: {type: [String], default: []}, characters: [String], + altNames: {type: [String], default: []}, streamAt: [String], watchers: {type: Number, default: 0}, listed: {type: Number, default: 0}, diff --git a/util/cache/anime.js b/util/cache/anime.js index 3bc5fe6..2e88d48 100644 --- a/util/cache/anime.js +++ b/util/cache/anime.js @@ -12,6 +12,7 @@ module.exports = async client => { if (ani.queued !== true) { client.misc.cache.anime.set(ani.japname, ani.id); client.misc.cache.anime.set(ani.name, ani.id); + if (ani.altNames) {ani.altNames.forEach(altName => client.misc.cache.anime.set(altName, ani.id));} client.misc.cache.animeID.set(ani.id, ani.name); client.misc.cache.animeLove.set(ani.id, ani.watchers); client.misc.cache.animeNum++;