2017-09-21 13:57:49 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const { isMaster } = require('../../utils/config');
|
|
|
|
|
const { link, scheduleDeletion } = require('../../utils/tg');
|
2017-09-23 21:49:23 +03:30
|
|
|
|
const { logError } = require('../../utils/log');
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const { parse, strip } = require('../../utils/parse');
|
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-27 12:34:26 +03:30
|
|
|
|
const {
|
|
|
|
|
admin,
|
2019-01-28 21:46:29 +01:00
|
|
|
|
getUser,
|
2017-09-27 12:34:26 +03:30
|
|
|
|
} = 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 */
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const adminHandler = async ({ from, message, reply }) => {
|
|
|
|
|
if (!isMaster(from)) return null;
|
2017-09-25 12:40:04 +03:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const { targets } = parse(message);
|
2017-09-21 13:57:49 +04:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
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);
|
2017-09-24 13:10:58 +03:30
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
if (userToAdmin.status === 'admin') {
|
2017-10-31 23:08:22 +01:00
|
|
|
|
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-23 21:49:23 +03:30
|
|
|
|
try {
|
|
|
|
|
await admin(userToAdmin);
|
|
|
|
|
} catch (err) {
|
2017-09-27 23:12:12 +03:30
|
|
|
|
logError(err);
|
2017-09-23 21:49:23 +03:30
|
|
|
|
}
|
2017-09-22 15:52:27 +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;
|