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

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-09-21 13:57:49 +04:30
'use strict';
// Utils
const { isMaster } = require('../../utils/config');
const { link, scheduleDeletion } = require('../../utils/tg');
2017-09-23 21:49:23 +03:30
const { logError } = require('../../utils/log');
const { parse, strip } = require('../../utils/parse');
2017-09-21 13:57:49 +04:30
// Bot
const { replyOptions } = require('../../bot/options');
2017-09-21 13:57:49 +04:30
// DB
const {
admin,
getUser,
} = require('../../stores/user');
2017-09-21 13:57:49 +04:30
2020-03-10 22:10:48 +01:00
/** @param { import('../../typings/context').ExtendedContext } ctx */
const adminHandler = async ({ from, message, reply }) => {
if (!isMaster(from)) return null;
2017-09-25 12:40:04 +03:30
const { targets } = parse(message);
2017-09-21 13:57:49 +04:30
if (targets.length > 1) {
return reply(
' <b>Specify one user to promote.</b>',
replyOptions
).then(scheduleDeletion());
}
const userToAdmin = targets.length
? await getUser(strip(targets[0]))
: from;
if (!userToAdmin) {
return reply(
'❓ <b>User unknown.</b>\n' +
'Please forward their message, then try again.',
replyOptions
).then(scheduleDeletion());
}
if (userToAdmin.status === 'banned') {
2017-09-24 14:28:18 +03:30
return reply(' <b>Can\'t admin banned user.</b>', replyOptions);
}
if (userToAdmin.status === 'admin') {
return reply(
`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`,
replyOptions
);
2017-09-21 13:57:49 +04:30
}
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;