From 7143e588a6e7da92542e6a3253d29c6e2bc52b75 Mon Sep 17 00:00:00 2001 From: GingerPlusPlus Date: Sun, 28 Jan 2018 17:05:52 +0100 Subject: [PATCH] Rewritten middlewares/kickBanned Closes #52 --- handlers/middlewares/kickBanned.js | 33 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/handlers/middlewares/kickBanned.js b/handlers/middlewares/kickBanned.js index 54c0c49..6daeb0b 100644 --- a/handlers/middlewares/kickBanned.js +++ b/handlers/middlewares/kickBanned.js @@ -1,29 +1,28 @@ 'use strict'; +const dedent = require('dedent-js'); + // Utils const { link } = require('../../utils/tg'); -const { logError } = require('../../utils/log'); -// Bot -const bot = require('../../bot'); const { replyOptions } = require('../../bot/options'); -// DB -const { isBanned } = require('../../stores/user'); +const kickBannedHandler = async (ctx, next) => { + if (ctx.chat.type === 'private') { + return next(); + } + if (ctx.from.status === 'banned') { + ctx.deleteMessage(); + await ctx.kickChatMember(ctx.from.id); + return ctx.replyWithHTML( + dedent(` + 🚫 ${link(ctx.from)} is banned! -const kickbanned = async ({ chat, from, reply }, next) => { - const banned = await isBanned(from); - if (banned) { - return bot.telegram.kickChatMember(chat.id, from.id) - .then(() => reply( - `🚫 ${link(from)} is banned!\n\n` + - `Reason: ${banned}`, - replyOptions - )) - .catch(logError) - .then(next); + Reason: ${ctx.from.ban_reason}`), + replyOptions + ); } return next(); }; -module.exports = kickbanned; +module.exports = kickBannedHandler;