char love caching and leaderboard

master
Kit Kasune 3 years ago
parent 0b80fa77f5
commit 9ed52301da
  1. 3
      bot.js
  2. 29
      commands/anime/charlb.js
  3. 2
      util/cache/char.js

@ -40,7 +40,8 @@ client.misc = {
anime: new Discord.Collection(), anime: new Discord.Collection(),
charsID: new Discord.Collection(), charsID: new Discord.Collection(),
animeID: new Discord.Collection(), animeID: new Discord.Collection(),
charsNum: 0 charsNum: 0,
charsLove: new Discord.Collection()
}, },
loggers: {}, loggers: {},
rl: readline.createInterface({input: process.stdin, output: process.stdout}), rl: readline.createInterface({input: process.stdin, output: process.stdout}),

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

@ -5,6 +5,7 @@ const CharData = require('../../models/char');
module.exports = async client => { module.exports = async client => {
client.misc.cache.chars = new Discord.Collection(); client.misc.cache.chars = new Discord.Collection();
client.misc.cache.charsID = new Discord.Collection(); client.misc.cache.charsID = new Discord.Collection();
client.misc.cache.charsLove = new Discord.Collection();
client.misc.cache.charsNum = 0; client.misc.cache.charsNum = 0;
for await (const char of CharData.find()) { 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)); char.nicknames.forEach(nn => client.misc.cache.chars.set(nn, char.id));
client.misc.cache.charsID.set(char.id, char.name); client.misc.cache.charsID.set(char.id, char.name);
client.misc.cache.charsNum++; client.misc.cache.charsNum++;
client.misc.cache.charsLove.set(char.id, char.loved);
} }
} }
} }
Loading…
Cancel
Save