2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 18:38:05 +00:00

44 lines
1007 B
JavaScript
Raw Normal View History

'use strict';
// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
2017-09-23 21:49:23 +03:30
const { logError } = require('../../utils/log');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
2017-09-27 00:11:20 +03:30
const { isAdmin, unadmin } = require('../../stores/user');
const unAdminHandler = async ({ message, reply, state }) => {
const { isMaster } = state;
if (!isMaster) return null;
2017-09-25 12:40:04 +03:30
const userToUnadmin = message.reply_to_message
? message.reply_to_message.from
: message.commandMention
? message.commandMention
: null;
if (!userToUnadmin) {
return reply(' <b>Reply to a message or mention a user.</b>',
replyOptions).then(scheduleDeletion);
}
if (!await isAdmin(userToUnadmin)) {
2017-09-24 14:28:18 +03:30
return reply(` ${link(userToUnadmin)} <b>is not admin.</b>`,
replyOptions);
}
2017-09-23 21:49:23 +03:30
try {
await unadmin(userToUnadmin);
} catch (err) {
logError(err);
2017-09-23 21:49:23 +03:30
}
2017-09-24 14:28:18 +03:30
return reply(`❗️ ${link(userToUnadmin)} <b>is no longer admin.</b>`,
replyOptions);
};
module.exports = unAdminHandler;