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

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-09-21 13:57:49 +04:30
'use strict';
// Utils
2020-05-13 15:11:43 +02:00
const { html } = require('../../utils/html');
const { isMaster } = require('../../utils/config');
const { link, scheduleDeletion } = require('../../utils/tg');
2020-05-13 15:11:43 +02:00
const { parse, strip } = require('../../utils/cmd');
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 */
2020-05-13 15:11:43 +02:00
const adminHandler = async ({ from, message, replyWithHTML }) => {
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) {
2020-05-13 15:11:43 +02:00
return replyWithHTML(
' <b>Specify one user to promote.</b>',
).then(scheduleDeletion());
}
const userToAdmin = targets.length
? await getUser(strip(targets[0]))
: from;
if (!userToAdmin) {
2020-05-13 15:11:43 +02:00
return replyWithHTML(
'❓ <b>User unknown.</b>\n' +
'Please forward their message, then try again.',
).then(scheduleDeletion());
}
if (userToAdmin.status === 'banned') {
2020-05-13 15:11:43 +02:00
return replyWithHTML(' <b>Can\'t admin banned user.</b>');
}
if (userToAdmin.status === 'admin') {
2020-05-13 15:11:43 +02:00
return replyWithHTML(
html`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`,
);
2017-09-21 13:57:49 +04:30
}
2020-05-13 22:05:22 +02:00
await admin(userToAdmin);
2020-05-13 15:11:43 +02:00
return replyWithHTML(html`⭐️ ${link(userToAdmin)} <b>is now admin.</b>`);
2017-09-21 13:57:49 +04:30
};
module.exports = adminHandler;