From 43cd7ab2859db23a52c7a731d59ca5ca752637ee Mon Sep 17 00:00:00 2001 From: GingerPlusPlus Date: Sat, 23 Sep 2017 14:35:45 +0200 Subject: [PATCH] /unban calls unbanChatMember in each group --- handlers/unban.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/handlers/unban.js b/handlers/unban.js index dd80798..58245da 100644 --- a/handlers/unban.js +++ b/handlers/unban.js @@ -7,10 +7,11 @@ const { link } = require('../utils/tg'); const { replyOptions } = require('../bot/options'); // DB +const { listGroups } = require('../stores/groups'); const { isBanned, unban } = require('../stores/ban'); const admins = require('../stores/admin'); -const unbanHandler = async ({ message, reply }) => { +const unbanHandler = async ({ message, reply, telegram }) => { if (!await admins.isAdmin(message.from)) { return null; } @@ -25,6 +26,13 @@ const unbanHandler = async ({ message, reply }) => { return reply('User is not banned.'); } + const groups = await listGroups(); + + const unbans = groups.map(group => + telegram.unbanChatMember(group.id, userToUnban.id)); + + await Promise.all(unbans); + await unban(userToUnban); return reply(`${link(userToUnban)} has been unbanned.`, replyOptions);