From 84e178f363b071b4a7cc6d6bf6da16928151d4f5 Mon Sep 17 00:00:00 2001 From: GingerPlusPlus Date: Tue, 31 Oct 2017 19:08:17 +0100 Subject: [PATCH] Always send warn message on /warn even when the last warning gets the target banned. Closes #38 Also, use numberOfWarnsToBan instead of 3. --- handlers/commands/warn.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/handlers/commands/warn.js b/handlers/commands/warn.js index c85b3b3..455473c 100644 --- a/handlers/commands/warn.js +++ b/handlers/commands/warn.js @@ -55,18 +55,25 @@ const warnHandler = async ({ message, chat, reply, me, state }) => { message.reply_to_message.message_id)); } - if (warnCount.length < numberOfWarnsToBan) { - promises.push(reply( - `⚠️ ${link(user)} warned ${link(userToWarn)} ` + - `for:\n\n ${reason} (${warnCount.length}/3)`, - replyOptions)); - } else { + try { + await reply( + `⚠️ ${link(user)} warned ${link(userToWarn)} for:` + + `\n\n${reason} (${warnCount.length}/${numberOfWarnsToBan})`, + replyOptions); + } catch (e) { + // we don't expect an error + // but we do wish to continue if one happens + // to ban people who reach max number of warnings + logError(e); + } + + if (warnCount.length >= numberOfWarnsToBan) { promises.push(bot.telegram.kickChatMember(chat.id, userToWarn.id)); promises.push(ban(userToWarn, 'Reached max number of warnings')); promises.push(reply( `🚫 ${link(user)} banned ${link(userToWarn)} ` + 'for:\n\nReached max number of warnings ' + - `(${warnCount.length}/3)\n\n`, + `(${warnCount.length}/${numberOfWarnsToBan})`, replyOptions)); }