2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-26 20:07:20 +00:00

52 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
// Utils
const { link } = require('../../utils/tg');
2017-09-23 21:49:23 +03:30
const { logError } = require('../../utils/log');
// Bot
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, telegram }) => {
if (!await admins.isAdmin(message.from)) {
return null;
}
if (!message.reply_to_message) {
2017-09-24 14:28:18 +03:30
return reply(' <b>Reply to a message.</b>', replyOptions);
}
const userToUnban = message.reply_to_message.from;
if (!await isBanned(userToUnban)) {
2017-09-24 14:28:18 +03:30
return reply(' <b>User is not banned.</b>', replyOptions);
}
const groups = await listGroups();
const unbans = groups.map(group =>
telegram.unbanChatMember(group.id, userToUnban.id));
2017-09-23 21:49:23 +03:30
try {
await Promise.all(unbans);
} catch (err) {
logError(process.env.DEBUG)(err);
}
2017-09-23 21:49:23 +03:30
try {
await unban(userToUnban);
} catch (err) {
logError(process.env.DEBUG)(err);
}
2017-09-24 14:28:18 +03:30
return reply(`♻️ ${link(userToUnban)} <b>is unbanned.</b>`,
replyOptions);
};
module.exports = unbanHandler;