Skip to content

Commit

Permalink
Command resetBadge
Browse files Browse the repository at this point in the history
  • Loading branch information
BastLast committed Jul 14, 2020
1 parent 926123c commit 7642830
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ressources/text/commands/resetBadgeCommand.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"translations": {
"fr": {
"resetSuccess": "{pseudo}, action effectuée !",
"descReset": "Les badges de {player} ont été réinitialisés."
},
"en": {
"giveSuccess": "{pseudo}, finished!",
"descReset": "{player}'s badges are now gone."
}
}
}
28 changes: 28 additions & 0 deletions src/commands/admin/ResetBadgesCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Allow the bot owner or a badgemanager to remove all badges from somebody
* @param {("fr"|"en")} language - Language to use in the response
* @param {module:"discord.js".Message} message - Message from the discord server
* @param {String[]} args=[] - Additional arguments sent with the command
*/
const resetBadgesCommand = async function (language, message, args) {
if ((await canPerformCommand(message, language, PERMISSION.ROLE.BADGEMANAGER)) !== true) {
return;
}
const embed = new discord.MessageEmbed();
// the author of the command is the author of the bot
const playerId = message.mentions.users.last().id;
[entity] = await Entities.getOrRegister(playerId);

entity.Player.badges = null;
await entity.Player.save();

embed.setColor(JsonReader.bot.embed.default)
.setAuthor(format(JsonReader.commands.resetBadgeCommand.getTranslation(language).resetSuccess, { pseudo: message.author.username }), message.author.displayAvatarURL())
.setDescription(format(JsonReader.commands.resetBadgeCommand.getTranslation(language).descReset, { player: message.mentions.users.last() }));
return await message.channel.send(embed);
};

module.exports = {
'rb': resetBadgesCommand,
};

0 comments on commit 7642830

Please sign in to comment.