🥅 Fix some minor errors

This commit is contained in:
Axel Olausson Holtenäs 2022-03-09 21:51:13 +01:00
parent 23fb07647d
commit 1196ae3bcc
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
2 changed files with 33 additions and 52 deletions

View file

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

View file

@ -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 });