🗃️ /credits top is now on mongodb
This commit is contained in:
parent
83e65ce8d6
commit
c0bc0c487d
2 changed files with 10 additions and 21 deletions
|
@ -1,28 +1,17 @@
|
||||||
const db = require('quick.db');
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
const credits = new db.table('credits');
|
const debug = require('../../../handlers/debug');
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
const { client } = interaction;
|
credits.find().then(async (data) => {
|
||||||
const all = credits.all();
|
const topTen = data.slice(0, 10);
|
||||||
const allSorted = all.sort((a, b) => (a.data > b.data ? -1 : 1));
|
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 = {
|
const embed = {
|
||||||
title: 'Balance Top',
|
title: 'Balance Top',
|
||||||
description: `Below are the top ten.\n
|
description: `Below are the top ten.\n${sorted
|
||||||
${topTens
|
|
||||||
.map(
|
.map(
|
||||||
(x) =>
|
(x, index) =>
|
||||||
`**Top ${x.index + 1}** - ${x.user}: ${
|
`**Top ${index + 1}** - <@${x.userId}> ${
|
||||||
x.credits <= 1 ? `${x.credits} credit` : `${x.credits} credits`
|
x.balance <= 1 ? `${x.balance} credit` : `${x.balance} credits`
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
.join('\n')}`,
|
.join('\n')}`,
|
||||||
|
|
|
@ -45,7 +45,7 @@ client.on('interactionCreate', async (interaction) => {
|
||||||
client.on('messageCreate', async (message) => {
|
client.on('messageCreate', async (message) => {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
|
|
||||||
credits
|
await credits
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{ userId: message.author.id },
|
{ userId: message.author.id },
|
||||||
{ $inc: { balance: 1 } },
|
{ $inc: { balance: 1 } },
|
||||||
|
|
Loading…
Add table
Reference in a new issue