2017-09-21 13:57:49 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2017-09-23 21:40:58 +03:30
|
|
|
|
const { loadJSON } = require('../../utils/json');
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
// Config
|
2017-09-22 15:52:27 +03:30
|
|
|
|
const { masterID } = loadJSON('config.json');
|
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-23 21:40:58 +03:30
|
|
|
|
const { isAdmin, admin } = require('../../stores/admin');
|
2017-09-24 13:10:58 +03:30
|
|
|
|
const { isBanned } = require('../../stores/ban');
|
|
|
|
|
const { getWarns, nowarns } = require('../../stores/warn');
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
|
|
|
|
const adminHandler = async ({ message, reply }) => {
|
2017-09-22 15:52:27 +03:30
|
|
|
|
if (message.from.id !== masterID) {
|
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
|
|
|
|
|
: message.from;
|
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-24 14:28:18 +03:30
|
|
|
|
return reply(`⭐️ ${link(userToAdmin)} <b>is already admin.</b>.`,
|
|
|
|
|
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) {
|
|
|
|
|
logError(process.env.DEBUG)(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-23 21:49:23 +03:30
|
|
|
|
try {
|
|
|
|
|
await admin(userToAdmin);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
logError(process.env.DEBUG)(err);
|
|
|
|
|
}
|
2017-09-22 15:52:27 +03:30
|
|
|
|
|
2017-09-24 14:28:18 +03:30
|
|
|
|
return reply(`⭐️ ${link(userToAdmin)} <b>is now admin.</b>.`, replyOptions);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = adminHandler;
|