anime watch leaderboard

master
Kit Kasune 3 years ago
parent 79aa23f675
commit cf18c23ef5
  1. 1
      commands/anime/listanime.js
  2. 29
      commands/anime/watchedlb.js
  3. 2
      util/cache.js
  4. 4
      util/cache/anime.js

@ -22,7 +22,6 @@ module.exports = {
if (args.length) { 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)); 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!");} if (!anime.length) {return message.channel.send("That query returned no results!");}
matches = `matches`; matches = `matches`;
} else {anime = Array.from(client.misc.cache.animeID.keys());} } else {anime = Array.from(client.misc.cache.animeID.keys());}

@ -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()
]});
}
};

@ -32,7 +32,7 @@ module.exports = async (client) => {
let ora_anCache = ora("Caching Animes...").start(); let ora_anCache = ora("Caching Animes...").start();
await require('./cache/anime')(client); await require('./cache/anime')(client);
ora_anCache.stop(); ora_anCache.clear(); 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(); let ora_chCache = ora("Caching Characters...").start();
await require('./cache/char')(client); await require('./cache/char')(client);

@ -5,12 +5,16 @@ const AniData = require('../../models/anime');
module.exports = async client => { module.exports = async client => {
client.misc.cache.anime = new Discord.Collection(); client.misc.cache.anime = new Discord.Collection();
client.misc.cache.animeID = 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()) { for await (const ani of AniData.find()) {
if (ani.queued !== true) { if (ani.queued !== true) {
client.misc.cache.anime.set(ani.japname, ani.id); client.misc.cache.anime.set(ani.japname, ani.id);
client.misc.cache.anime.set(ani.name, ani.id); client.misc.cache.anime.set(ani.name, ani.id);
client.misc.cache.animeID.set(ani.id, ani.name); client.misc.cache.animeID.set(ani.id, ani.name);
client.misc.cache.animeLove.set(ani.id, ani.watchers);
client.misc.cache.animeNum++;
} }
} }
} }
Loading…
Cancel
Save