diff --git a/bot.js b/bot.js index 0641227..27936f0 100644 --- a/bot.js +++ b/bot.js @@ -40,7 +40,8 @@ client.misc = { anime: new Discord.Collection(), charsID: new Discord.Collection(), animeID: new Discord.Collection(), - charsNum: 0 + charsNum: 0, + charsLove: new Discord.Collection() }, loggers: {}, rl: readline.createInterface({input: process.stdin, output: process.stdout}), diff --git a/commands/anime/charlb.js b/commands/anime/charlb.js new file mode 100644 index 0000000..d33d080 --- /dev/null +++ b/commands/anime/charlb.js @@ -0,0 +1,29 @@ +const Discord = require('discord.js'); + +module.exports = { + name: "charlb", + aliases: ['chlb', 'charleaderboard', 'characterlb', 'characterleaderboard'], + meta: { + category: 'Anime', + description: "Find out the most loved characters across Natsuki's users!", + syntax: '`charlb`', + 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("Character Love Leaderboard") + .setDescription( + Array.from(client.misc.cache.charsLove.keys()) + .sort((a, b) => client.misc.cache.charsLove.get(a) - client.misc.cache.charsLove.get(b)) + .reverse() + .slice(0, 10) + .map((c, i) => `${i+1}. **${client.misc.cache.charsLove.get(c)} vote${client.misc.cache.charsLove.get(c) === 1 ? '' : 's'}** -> ${client.misc.cache.charsID.get(c)}`) + .join('\n') + ).setColor('c375f0') + .setFooter("Natsuki", client.user.avatarURL()) + .setTimestamp() + ]}); + } +}; \ No newline at end of file diff --git a/util/cache/char.js b/util/cache/char.js index 6968f2a..cb4aa88 100644 --- a/util/cache/char.js +++ b/util/cache/char.js @@ -5,6 +5,7 @@ const CharData = require('../../models/char'); module.exports = async client => { client.misc.cache.chars = new Discord.Collection(); client.misc.cache.charsID = new Discord.Collection(); + client.misc.cache.charsLove = new Discord.Collection(); client.misc.cache.charsNum = 0; for await (const char of CharData.find()) { @@ -13,6 +14,7 @@ module.exports = async client => { char.nicknames.forEach(nn => client.misc.cache.chars.set(nn, char.id)); client.misc.cache.charsID.set(char.id, char.name); client.misc.cache.charsNum++; + client.misc.cache.charsLove.set(char.id, char.loved); } } } \ No newline at end of file