From 1196ae3bccd369b399136667fe87631579ff4c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Olausson=20Holten=C3=A4s?= Date: Wed, 9 Mar 2022 21:51:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Fix=20some=20minor=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/credits/addons/work.js | 73 +++++++++-------------------- src/commands/profile/addons/view.js | 12 +++++ 2 files changed, 33 insertions(+), 52 deletions(-) diff --git a/src/commands/credits/addons/work.js b/src/commands/credits/addons/work.js index 2d73d89..f9be4ca 100644 --- a/src/commands/credits/addons/work.js +++ b/src/commands/credits/addons/work.js @@ -23,60 +23,29 @@ module.exports = async (interaction) => { if (!isTimeout) { const guild = await guilds.findOne({ guildId: interaction.member.guild.id }); - if (!workedRecently.has(interaction.member.id)) { - const creditsEarned = Math.floor(Math.random() * guild.credits.workRate); - await credits - .findOneAndUpdate( - { - userId: interaction.member.id, - guildId: interaction.member.guild.id, - }, - { $inc: { balance: creditsEarned } }, - { new: true, upsert: true }, - ) - .then(async () => { - logger.debug(`Credits added to user: ${interaction.member.id}`); - const embed = { - title: 'Work', - description: `You earned ${creditNoun(creditsEarned)}`, - color: config.colors.success, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - return interaction.editReply({ embeds: [embed], ephemeral: true }); - }) - .catch(async (err) => { - await logger.error(err); - }); + const creditsEarned = Math.floor(Math.random() * guild.credits.workRate); + await credits + .findOneAndUpdate( + { + userId: interaction.member.id, + guildId: interaction.member.guild.id, + }, + { $inc: { balance: creditsEarned } }, + { new: true, upsert: true }, + ) + .then(async () => { + logger.debug(`Credits added to user: ${interaction.member.id}`); + const embed = { + title: 'Work', + description: `You earned ${creditNoun(creditsEarned)}`, + color: config.colors.success, + timestamp: new Date(), + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; - workedRecently.add(interaction.member.id); - setTimeout(() => { - logger.debug( - `User: ${interaction.member.id} has not worked within last ${ - guild.credits.workTimeout / 1000 - } seconds, work can be runned`, - ); - workedRecently.delete(interaction.member.id); - }, guild.credits.workTimeout); - } else { - logger.debug( - `User: ${interaction.member.id} has already worked within last ${ - guild.credits.workTimeout / 1000 - } seconds, no work is runned`, - ); - const embed = { - title: 'Work', - description: `You can not work now, wait ${ - guild.credits.workTimeout / 1000 - } seconds until timeout is out.`, - color: config.colors.error, - timestamp: new Date(), - footer: { iconURL: config.footer.icon, text: config.footer.text }, - }; - - return interaction.editReply({ embeds: [embed], ephemeral: true }); - } + return interaction.editReply({ embeds: [embed], ephemeral: true }); + }); // Create a timeout for the user diff --git a/src/commands/profile/addons/view.js b/src/commands/profile/addons/view.js index 1beca33..32a4873 100644 --- a/src/commands/profile/addons/view.js +++ b/src/commands/profile/addons/view.js @@ -35,6 +35,18 @@ module.exports = async (interaction) => { }, ); + if (user === null || experience === null || credit === null) { + const embed = { + title: 'Profile', + description: 'You have to write something before viewing your profile!', + timestamp: new Date(), + color: config.colors.error, + footer: { iconURL: config.footer.icon, text: config.footer.text }, + }; + + return await interaction.editReply({ embeds: [embed] }); + } + // Language variables const notAvailableText = i18next.t('general:not_available', { lng: await user.language }); const reputationText = i18next.t('commands:profile:addons:view:embed:reputation', { lng: await user.language });