From 89a8b5875f643bdaa6aa60eae26b0d1a892ccc73 Mon Sep 17 00:00:00 2001 From: Pouria Ezzati Date: Wed, 11 Oct 2017 00:16:34 +0330 Subject: [PATCH] fixed channel forwarding warn count bug --- handlers/messages/removeLinks.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/handlers/messages/removeLinks.js b/handlers/messages/removeLinks.js index 88e8f48..a411090 100644 --- a/handlers/messages/removeLinks.js +++ b/handlers/messages/removeLinks.js @@ -16,7 +16,7 @@ const bot = require('../../bot'); const { replyOptions } = require('../../bot/options'); // DB -const { ban, warn } = require('../../stores/user'); +const { ban, warn, getWarns } = require('../../stores/user'); const { listGroups } = require('../../stores/group'); const removeLinks = async ({ message, chat, reply, state }, next) => { @@ -48,13 +48,14 @@ const removeLinks = async ({ message, chat, reply, state }, next) => { return next(); } const reason = 'Channel forward/link'; - const warnCount = await warn(user, reason); + await warn(user, reason); + const warnCount = await getWarns(user); const promises = [ bot.telegram.deleteMessage(chat.id, message.message_id) ]; - if (warnCount < numberOfWarnsToBan) { + if (warnCount.length < numberOfWarnsToBan) { promises.push(reply( - `⚠️ ${link(user)} got warned! (${warnCount}/3)` + + `⚠️ ${link(user)} got warned! (${warnCount.length}/3)` + `\n\nReason: ${reason}`, replyOptions)); } else { @@ -62,7 +63,7 @@ const removeLinks = async ({ message, chat, reply, state }, next) => { promises.push(ban(user, 'Reached max number of warnings')); promises.push(reply( - `🚫 ${link(user)} got banned! (${warnCount}/3)` + + `🚫 ${link(user)} got banned! (${warnCount.length}/3)` + '\n\nReason: Reached max number of warnings', replyOptions)); }