From 764283071dbe65782c8aabc5d316921d44661ba5 Mon Sep 17 00:00:00 2001 From: Bast Date: Tue, 14 Jul 2020 23:41:07 +0200 Subject: [PATCH] Command resetBadge --- .../text/commands/resetBadgeCommand.json | 12 ++++++++ src/commands/admin/ResetBadgesCommand.js | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 ressources/text/commands/resetBadgeCommand.json create mode 100644 src/commands/admin/ResetBadgesCommand.js diff --git a/ressources/text/commands/resetBadgeCommand.json b/ressources/text/commands/resetBadgeCommand.json new file mode 100644 index 000000000..19bc2ba18 --- /dev/null +++ b/ressources/text/commands/resetBadgeCommand.json @@ -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." + } + } +} \ No newline at end of file diff --git a/src/commands/admin/ResetBadgesCommand.js b/src/commands/admin/ResetBadgesCommand.js new file mode 100644 index 000000000..8dae6a818 --- /dev/null +++ b/src/commands/admin/ResetBadgesCommand.js @@ -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, +}; +