2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 10:58:19 +00:00

58 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-09-21 13:57:49 +04:30
'use strict';
// Utils
const { link } = require('../../utils/tg');
2017-09-23 21:49:23 +03:30
const { logError } = require('../../utils/log');
2017-09-21 13:57:49 +04:30
// Bot
const { replyOptions } = require('../../bot/options');
2017-09-21 13:57:49 +04:30
// DB
const {
isAdmin,
admin,
isBanned,
getWarns,
nowarns
} = require('../../stores/user');
2017-09-21 13:57:49 +04:30
const adminHandler = async ({ message, reply, state }) => {
const { isMaster, user } = state;
if (!isMaster) {
2017-09-21 13:57:49 +04:30
return null;
}
2017-09-25 12:40:04 +03:30
2017-09-21 13:57:49 +04:30
const userToAdmin = message.reply_to_message
? message.reply_to_message.from
2017-09-25 12:40:04 +03:30
: message.commandMention
? message.commandMention
: user;
2017-09-21 13:57:49 +04:30
if (await isBanned(userToAdmin)) {
2017-09-24 14:28:18 +03:30
return reply(' <b>Can\'t admin banned user.</b>', replyOptions);
}
if (await isAdmin(userToAdmin)) {
2017-09-27 23:18:11 +03:30
return reply(`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`,
2017-09-24 14:28:18 +03:30
replyOptions);
2017-09-21 13:57:49 +04:30
}
if (await getWarns(userToAdmin)) {
try {
await nowarns(userToAdmin);
} catch (err) {
logError(err);
}
}
2017-09-23 21:49:23 +03:30
try {
await admin(userToAdmin);
} catch (err) {
logError(err);
2017-09-23 21:49:23 +03:30
}
2017-09-29 00:03:55 +03:30
return reply(`⭐️ ${link(userToAdmin)} <b>is now admin.</b>`, replyOptions);
2017-09-21 13:57:49 +04:30
};
module.exports = adminHandler;