2017-09-21 13:57:49 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2020-05-13 15:11:43 +02:00
|
|
|
|
const { html } = require('../../utils/html');
|
2019-01-28 21:46:29 +01:00
|
|
|
|
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
|
2023-03-08 14:08:57 +01:00
|
|
|
|
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 */
|
2021-05-07 22:46:11 +02:00
|
|
|
|
const adminHandler = async (ctx) => {
|
|
|
|
|
if (!isMaster(ctx.from)) return null;
|
2017-09-25 12:40:04 +03:30
|
|
|
|
|
2021-05-07 22:46:11 +02:00
|
|
|
|
const { targets } = parse(ctx.message);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
if (targets.length > 1) {
|
2023-03-08 14:08:57 +01:00
|
|
|
|
return ctx
|
|
|
|
|
.replyWithHTML('ℹ️ <b>Specify one user to promote.</b>')
|
|
|
|
|
.then(scheduleDeletion());
|
2019-01-28 21:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const userToAdmin = targets.length
|
|
|
|
|
? await getUser(strip(targets[0]))
|
2021-05-07 22:46:11 +02:00
|
|
|
|
: ctx.from;
|
2019-01-28 21:46:29 +01:00
|
|
|
|
|
|
|
|
|
if (!userToAdmin) {
|
2023-03-08 14:08:57 +01:00
|
|
|
|
return ctx
|
|
|
|
|
.replyWithHTML(
|
|
|
|
|
'❓ <b>User unknown.</b>\n' +
|
|
|
|
|
'Please forward their message, then try again.'
|
|
|
|
|
)
|
|
|
|
|
.then(scheduleDeletion());
|
2019-01-28 21:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userToAdmin.status === 'banned') {
|
2023-03-08 14:08:57 +01:00
|
|
|
|
return ctx.replyWithHTML("ℹ️ <b>Can't admin banned user.</b>");
|
2017-09-24 13:10:58 +03:30
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
if (userToAdmin.status === 'admin') {
|
2021-05-07 22:46:11 +02:00
|
|
|
|
return ctx.replyWithHTML(
|
2023-03-08 14:08:57 +01:00
|
|
|
|
html`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`
|
2017-10-31 23:08:22 +01:00
|
|
|
|
);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
}
|
2017-09-22 15:52:27 +03:30
|
|
|
|
|
2020-05-13 22:05:22 +02:00
|
|
|
|
await admin(userToAdmin);
|
2017-09-22 15:52:27 +03:30
|
|
|
|
|
2023-03-08 14:08:57 +01:00
|
|
|
|
return ctx.replyWithHTML(
|
|
|
|
|
html`⭐️ ${link(userToAdmin)} <b>is now admin.</b>`
|
|
|
|
|
);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = adminHandler;
|