From 91b25452e83724c84fd0cb19afacb0dbe9923765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Olausson=20Holten=C3=A4s?= Date: Thu, 3 Mar 2022 21:31:18 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20=F0=9F=8E=A8=20made=20creditNoun?= =?UTF-8?q?=20syncronous=20due=20/credits=20top?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/credits/addons/balance.js | 2 +- src/commands/credits/addons/gift.js | 4 ++-- src/commands/credits/addons/give.js | 2 +- src/commands/credits/addons/redeem.js | 2 +- src/commands/credits/addons/take.js | 2 +- src/commands/credits/addons/top.js | 11 ++++++----- src/commands/credits/index.js | 15 +++++---------- src/helpers/creditNoun.js | 2 +- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/commands/credits/addons/balance.js b/src/commands/credits/addons/balance.js index 6176314..398a51e 100644 --- a/src/commands/credits/addons/balance.js +++ b/src/commands/credits/addons/balance.js @@ -24,7 +24,7 @@ module.exports = async (interaction) => { const embed = { title: 'Balance', - description: `${user ? `${user} has` : 'You have'} ${await creditNoun(balance)}.`, + description: `${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`, color: process.env.SUCCESS_COLOR, timestamp: new Date(), footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, diff --git a/src/commands/credits/addons/gift.js b/src/commands/credits/addons/gift.js index 62431cc..a9427a4 100644 --- a/src/commands/credits/addons/gift.js +++ b/src/commands/credits/addons/gift.js @@ -48,9 +48,9 @@ module.exports = async (interaction) => { const embed = { title: 'Gift', - description: `You sent ${await creditNoun( + description: `You sent ${creditNoun( amount - )} to ${user}. Your new balance is ${await creditNoun(fromUser.balance)}.`, + )} to ${user}. Your new balance is ${creditNoun(fromUser.balance)}.`, color: 0x22bb33, timestamp: new Date(), footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, diff --git a/src/commands/credits/addons/give.js b/src/commands/credits/addons/give.js index 2b1cd74..8ebb9ef 100644 --- a/src/commands/credits/addons/give.js +++ b/src/commands/credits/addons/give.js @@ -31,7 +31,7 @@ module.exports = async (interaction) => { await toUser.save(); const embed = { title: 'Give', - description: `Gave ${await creditNoun(amount)} to ${user}.`, + description: `Gave ${creditNoun(amount)} to ${user}.`, color: 0x22bb33, timestamp: new Date(), footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, diff --git a/src/commands/credits/addons/redeem.js b/src/commands/credits/addons/redeem.js index 3e16048..9291ca7 100644 --- a/src/commands/credits/addons/redeem.js +++ b/src/commands/credits/addons/redeem.js @@ -78,7 +78,7 @@ module.exports = async (interaction) => { await user.save(); - await logger.debug(`User: ${user.username} redeemed: ${await creditNoun(amount)}`); + await logger.debug(`User: ${user.username} redeemed: ${creditNoun(amount)}`); await interaction.editReply({ embeds: [embed], ephemeral: true }); }) .catch(async (err) => { diff --git a/src/commands/credits/addons/take.js b/src/commands/credits/addons/take.js index fafc99e..db8d037 100644 --- a/src/commands/credits/addons/take.js +++ b/src/commands/credits/addons/take.js @@ -34,7 +34,7 @@ module.exports = async (interaction) => { const embed = { title: 'Take', - description: `You took ${await creditNoun(amount)} to ${user}.`, + description: `You took ${creditNoun(amount)} to ${user}.`, color: 0x22bb33, timestamp: new Date(), footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, diff --git a/src/commands/credits/addons/top.js b/src/commands/credits/addons/top.js index 0ae4e99..012508d 100644 --- a/src/commands/credits/addons/top.js +++ b/src/commands/credits/addons/top.js @@ -4,14 +4,15 @@ const creditNoun = require('../../../helpers/creditNoun'); module.exports = async (interaction) => { await credits.find().then(async (data) => { - const sorted = data.sort((a, b) => (a.balance > b.balance ? -1 : 1)); - const topTen = sorted.slice(0, 10); + const topTen = data.sort((a, b) => (a.balance > b.balance ? -1 : 1)).slice(0, 10); + + const item = (x, index) => { + return `**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`; + }; const embed = { title: 'Balance Top', - description: `Below are the top ten.\n${topTen - .map((x, index) => `**Top ${index + 1}** - <@${x.userId}> ${await creditNoun(x.balance)}`) - .join('\n')}`, + description: `Below are the top ten.\n${topTen.map((x, index) => item(x, index)).join('\n')}`, color: 0x22bb33, timestamp: new Date(), footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, diff --git a/src/commands/credits/index.js b/src/commands/credits/index.js index 0fa9b20..6baac7b 100644 --- a/src/commands/credits/index.js +++ b/src/commands/credits/index.js @@ -79,20 +79,15 @@ module.exports = { async execute(interaction) { if (interaction.options.getSubcommand() === 'balance') { await balance(interaction); - } - else if (interaction.options.getSubcommand() === 'gift') { + } else if (interaction.options.getSubcommand() === 'gift') { await gift(interaction); - } - else if (interaction.options.getSubcommand() === 'give') { + } else if (interaction.options.getSubcommand() === 'give') { await give(interaction); - } - else if (interaction.options.getSubcommand() === 'redeem') { + } else if (interaction.options.getSubcommand() === 'redeem') { await redeem(interaction); - } - else if (interaction.options.getSubcommand() === 'take') { + } else if (interaction.options.getSubcommand() === 'take') { await take(interaction); - } - else if (interaction.options.getSubcommand() === 'top') { + } else if (interaction.options.getSubcommand() === 'top') { await top(interaction); } }, diff --git a/src/helpers/creditNoun.js b/src/helpers/creditNoun.js index 374cfb1..9b58d78 100644 --- a/src/helpers/creditNoun.js +++ b/src/helpers/creditNoun.js @@ -1,3 +1,3 @@ -module.exports = async (amount) => { +module.exports = (amount) => { return `${amount <= 1 ? `${amount} credit` : `${amount} credits`}`; };