2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-28 04:37:52 +00:00
Thomas Rory Gummerson 758b924436
Type ctx
2020-03-13 22:00:30 +01:00

64 lines
1.4 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 { isMaster } = require('../../utils/config');
const { link, scheduleDeletion } = require('../../utils/tg');
const { logError } = require('../../utils/log');
const { parse, strip } = require('../../utils/parse');
// Bot
const { replyOptions } = require('../../bot/options');
// DB
const {
admin,
getUser,
} = require('../../stores/user');
/** @param { import('../../typings/context').ExtendedContext } ctx */
const adminHandler = async ({ from, message, reply }) => {
if (!isMaster(from)) return null;
const { targets } = parse(message);
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') {
return reply(' <b>Can\'t admin banned user.</b>', replyOptions);
}
if (userToAdmin.status === 'admin') {
return reply(
`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`,
replyOptions
);
}
try {
await admin(userToAdmin);
} catch (err) {
logError(err);
}
return reply(`⭐️ ${link(userToAdmin)} <b>is now admin.</b>`, replyOptions);
};
module.exports = adminHandler;