2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-26 03:47:11 +00:00
2017-09-24 14:28:31 +03:30

54 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
// Utils
const { loadJSON } = require('../../utils/json');
const { link } = require('../../utils/tg');
const { logError } = require('../../utils/log');
// Config
const { masterID } = loadJSON('config.json');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
const { isAdmin, admin } = require('../../stores/admin');
const { isBanned } = require('../../stores/ban');
const { getWarns, nowarns } = require('../../stores/warn');
const adminHandler = async ({ message, reply }) => {
if (message.from.id !== masterID) {
return null;
}
const userToAdmin = message.reply_to_message
? message.reply_to_message.from
: message.from;
if (await isBanned(userToAdmin)) {
return reply(' <b>Can\'t admin banned user.</b>', replyOptions);
}
if (await isAdmin(userToAdmin)) {
return reply(`⭐️ ${link(userToAdmin)} <b>is already admin.</b>.`,
replyOptions);
}
if (await getWarns(userToAdmin)) {
try {
await nowarns(userToAdmin);
} catch (err) {
logError(process.env.DEBUG)(err);
}
}
try {
await admin(userToAdmin);
} catch (err) {
logError(process.env.DEBUG)(err);
}
return reply(`⭐️ ${link(userToAdmin)} <b>is now admin.</b>.`, replyOptions);
};
module.exports = adminHandler;