🗃️ /credits top is now on mongodb

This commit is contained in:
Axel Olausson Holtenäs 2022-02-27 23:18:27 +01:00
parent 83e65ce8d6
commit c0bc0c487d
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
2 changed files with 10 additions and 21 deletions

View file

@ -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')}`,

View file

@ -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 } },