From cf18c23ef5540fc8b3e013b66d1e3366bb23361a Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Thu, 30 Dec 2021 03:44:06 -0700 Subject: [PATCH] anime watch leaderboard --- commands/anime/listanime.js | 1 - commands/anime/watchedlb.js | 29 +++++++++++++++++++++++++++++ util/cache.js | 2 +- util/cache/anime.js | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 commands/anime/watchedlb.js diff --git a/commands/anime/listanime.js b/commands/anime/listanime.js index ed0acfa..4c48260 100644 --- a/commands/anime/listanime.js +++ b/commands/anime/listanime.js @@ -22,7 +22,6 @@ module.exports = { if (args.length) { anime = fz.go(args.join(" "), Array.from(client.misc.cache.animeID.values()), {limit: 200}).sort((a,b)=>a.score-b.score).map(k => client.misc.cache.anime.get(k.target)); - console.log(anime); if (!anime.length) {return message.channel.send("That query returned no results!");} matches = `matches`; } else {anime = Array.from(client.misc.cache.animeID.keys());} diff --git a/commands/anime/watchedlb.js b/commands/anime/watchedlb.js new file mode 100644 index 0000000..4f483f2 --- /dev/null +++ b/commands/anime/watchedlb.js @@ -0,0 +1,29 @@ +const Discord = require('discord.js'); + +module.exports = { + name: "watchedlb", + aliases: ['wlb', 'watchleaderboard', 'watchedlb', 'finishedleaderboard', 'flb', 'finishlb', 'finishleaderboard'], + meta: { + category: 'Anime', + description: "Find out the most watched anime across Natsuki's users!", + syntax: '`watchedlb`', + extra: null + }, + help: "This command has no special syntax!", + async execute(message, msg, args, cmd, prefix, mention, client) { + return message.channel.send({embeds: [ + new Discord.MessageEmbed() + .setTitle("Anime Watch Count Leaderboard") + .setDescription( + Array.from(client.misc.cache.animeLove.keys()) + .sort((a, b) => client.misc.cache.animeLove.get(a) - client.misc.cache.animeLove.get(b)) + .reverse() + .slice(0, 10) + .map((c, i) => `${i+1}. **${client.misc.cache.animeLove.get(c)} watcher${client.misc.cache.animeLove.get(c) === 1 ? '' : 's'}** -> ${client.misc.cache.animeID.get(c)}`) + .join('\n') + ).setColor('c375f0') + .setFooter({text: "Natsuki", iconURL: client.user.avatarURL()}) + .setTimestamp() + ]}); + } +}; \ No newline at end of file diff --git a/util/cache.js b/util/cache.js index df04b91..7ab7e47 100644 --- a/util/cache.js +++ b/util/cache.js @@ -32,7 +32,7 @@ module.exports = async (client) => { let ora_anCache = ora("Caching Animes...").start(); await require('./cache/anime')(client); ora_anCache.stop(); ora_anCache.clear(); - console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.anime.size / 2}`)} ${chalk.blueBright(`animes into lookup registry.`)}`); + console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.animeNum}`)} ${chalk.blueBright(`animes into lookup registry.`)}`); let ora_chCache = ora("Caching Characters...").start(); await require('./cache/char')(client); diff --git a/util/cache/anime.js b/util/cache/anime.js index ce28164..3bc5fe6 100644 --- a/util/cache/anime.js +++ b/util/cache/anime.js @@ -5,12 +5,16 @@ const AniData = require('../../models/anime'); module.exports = async client => { client.misc.cache.anime = new Discord.Collection(); client.misc.cache.animeID = new Discord.Collection(); + client.misc.cache.animeLove = new Discord.Collection(); + client.misc.cache.animeNum = 0; for await (const ani of AniData.find()) { if (ani.queued !== true) { client.misc.cache.anime.set(ani.japname, ani.id); client.misc.cache.anime.set(ani.name, ani.id); client.misc.cache.animeID.set(ani.id, ani.name); + client.misc.cache.animeLove.set(ani.id, ani.watchers); + client.misc.cache.animeNum++; } } } \ No newline at end of file