2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-29 13:17:56 +00:00

Rewritten middlewares/kickBanned

Closes #52
This commit is contained in:
GingerPlusPlus 2018-01-28 17:05:52 +01:00
parent ed4473fbab
commit 7143e588a6

View File

@ -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)} <b>is banned</b>!
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)} <b>is banned</b>!\n\n` +
`Reason: ${banned}`,
replyOptions
))
.catch(logError)
.then(next);
Reason: ${ctx.from.ban_reason}`),
replyOptions
);
}
return next();
};
module.exports = kickbanned;
module.exports = kickBannedHandler;