From fb0fc005d6dc9deb7f97a8104c0b2c7c22cc730a Mon Sep 17 00:00:00 2001 From: Bast Date: Wed, 15 Jul 2020 22:18:39 +0200 Subject: [PATCH] fixes givebadge command #69 --- ressources/text/commands/giveBadgeCommand.json | 6 ++---- src/commands/admin/GiveBadgeCommand.js | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ressources/text/commands/giveBadgeCommand.json b/ressources/text/commands/giveBadgeCommand.json index cba8f8ba2..d63f69720 100644 --- a/ressources/text/commands/giveBadgeCommand.json +++ b/ressources/text/commands/giveBadgeCommand.json @@ -3,14 +3,12 @@ "fr": { "giveSuccess": "{pseudo}, vous avez donné un badge, j'espère que c'est mérité !", "descGive": "Le badge {badge} a été donné à {player}", - "giveError": "{pseudo}, vous avez fait une erreur !", - "descError": "Vous devez entrer un badge sous la forme :nom_badge: puis tag le pseudo de la personne à qui est donné le badge !" + "descError": "La personne que vous avez saisi n'est pas valide. `gb :badge: @mention`." }, "en": { "giveSuccess": "{pseudo}, you gave a badge, i hope it is well deserved !", "descGive": "The badge {badge} has been given to {player}", - "giveError": "{pseudo}, you made an error !", - "descError": "You must give a badge like :badge_name: and tag the nickname of the receiver !" + "descError": "Please indicate a valid user. `gb :badge: @mention`." } } } \ No newline at end of file diff --git a/src/commands/admin/GiveBadgeCommand.js b/src/commands/admin/GiveBadgeCommand.js index 6406a5a0b..a7e9bab4a 100644 --- a/src/commands/admin/GiveBadgeCommand.js +++ b/src/commands/admin/GiveBadgeCommand.js @@ -4,21 +4,22 @@ * @param {module:"discord.js".Message} message - Message from the discord server * @param {String[]} args=[] - Additional arguments sent with the command */ -const giveBadgeCommand = async function(language, message, args) { +const giveBadgeCommand = 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 + if (message.mentions.users.last() === undefined) { + return sendErrorMessage(message.author, message.channel, language, JsonReader.commands.giveBadgeCommand.getTranslation(language).descError); + } const playerId = message.mentions.users.last().id; [entity] = await Entities.getOrRegister(playerId); - await entity.Player.addBadge(args[0]); await entity.Player.save(); embed.setColor(JsonReader.bot.embed.default) - .setAuthor(format(JsonReader.commands.giveBadgeCommand.getTranslation(language).giveSuccess, {pseudo: message.author.username}), message.author.displayAvatarURL()) - .setDescription(format(JsonReader.commands.giveBadgeCommand.getTranslation(language).descGive, {badge: args[0], player: message.mentions.users.last()})); + .setAuthor(format(JsonReader.commands.giveBadgeCommand.getTranslation(language).giveSuccess, { pseudo: message.author.username }), message.author.displayAvatarURL()) + .setDescription(format(JsonReader.commands.giveBadgeCommand.getTranslation(language).descGive, { badge: args[0], player: message.mentions.users.last() })); return await message.channel.send(embed); };