From c0bc0c487d71810bc5163c0c72d5c0152c965eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Olausson=20Holten=C3=A4s?= Date: Sun, 27 Feb 2022 23:18:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20/credits=20top=20is=20n?= =?UTF-8?q?ow=20on=20mongodb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/credits/addons/top.js | 29 +++++++++-------------------- src/index.js | 2 +- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/commands/credits/addons/top.js b/src/commands/credits/addons/top.js index d94430a..a41eb0c 100644 --- a/src/commands/credits/addons/top.js +++ b/src/commands/credits/addons/top.js @@ -1,28 +1,17 @@ -const db = require('quick.db'); -const credits = new db.table('credits'); +const credits = require('../../../helpers/database/models/creditSchema'); +const debug = require('../../../handlers/debug'); module.exports = async (interaction) => { - const { client } = interaction; - const all = credits.all(); - const allSorted = all.sort((a, b) => (a.data > b.data ? -1 : 1)); + credits.find().then(async (data) => { + const topTen = data.slice(0, 10); + const sorted = topTen.sort((a, b) => (a.balance > b.balance ? -1 : 1)); - const topTen = allSorted.slice(0, 10); - - const topTens = []; - - Promise.all( - topTen.map(async (x, i) => { - user = await client.users.fetch(`${x.ID}`, { force: true }); - topTens.push({ index: i, user: user, credits: x.data }); - }) - ).then(async () => { const embed = { title: 'Balance Top', - description: `Below are the top ten.\n - ${topTens + description: `Below are the top ten.\n${sorted .map( - (x) => - `**Top ${x.index + 1}** - ${x.user}: ${ - x.credits <= 1 ? `${x.credits} credit` : `${x.credits} credits` + (x, index) => + `**Top ${index + 1}** - <@${x.userId}> ${ + x.balance <= 1 ? `${x.balance} credit` : `${x.balance} credits` }` ) .join('\n')}`, diff --git a/src/index.js b/src/index.js index 0d1be35..ff6c307 100644 --- a/src/index.js +++ b/src/index.js @@ -45,7 +45,7 @@ client.on('interactionCreate', async (interaction) => { client.on('messageCreate', async (message) => { if (message.author.bot) return; - credits + await credits .findOneAndUpdate( { userId: message.author.id }, { $inc: { balance: 1 } },