2017-09-21 13:57:49 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2017-09-23 21:40:58 +03:30
|
|
|
|
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
|
2017-09-23 21:40:58 +03:30
|
|
|
|
const { replyOptions } = require('../../bot/options');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
|
|
|
|
// DB
|
2017-09-27 12:34:26 +03:30
|
|
|
|
const {
|
|
|
|
|
isAdmin,
|
|
|
|
|
admin,
|
|
|
|
|
isBanned,
|
|
|
|
|
getWarns,
|
|
|
|
|
nowarns
|
|
|
|
|
} = require('../../stores/user');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2017-10-06 16:34:23 +03: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
|
2017-10-06 16:34:23 +03:30
|
|
|
|
: user;
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2017-09-24 13:10:58 +03:30
|
|
|
|
if (await isBanned(userToAdmin)) {
|
2017-09-24 14:28:18 +03:30
|
|
|
|
return reply('ℹ️ <b>Can\'t admin banned user.</b>', replyOptions);
|
2017-09-24 13:10:58 +03:30
|
|
|
|
}
|
|
|
|
|
|
2017-09-22 15:52:27 +03:30
|
|
|
|
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
|
|
|
|
}
|
2017-09-22 15:52:27 +03:30
|
|
|
|
|
2017-09-24 13:10:58 +03:30
|
|
|
|
if (await getWarns(userToAdmin)) {
|
|
|
|
|
try {
|
|
|
|
|
await nowarns(userToAdmin);
|
|
|
|
|
} catch (err) {
|
2017-09-27 23:12:12 +03:30
|
|
|
|
logError(err);
|
2017-09-24 13:10:58 +03:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-23 21:49:23 +03:30
|
|
|
|
try {
|
|
|
|
|
await admin(userToAdmin);
|
|
|
|
|
} catch (err) {
|
2017-09-27 23:12:12 +03:30
|
|
|
|
logError(err);
|
2017-09-23 21:49:23 +03:30
|
|
|
|
}
|
2017-09-22 15:52:27 +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;
|