2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-22 09:57:50 +00:00
Thomas Rory Gummerson 37974a3d92 Updates
2023-03-08 14:08:57 +01:00

55 lines
1.3 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 { html } = require('../../utils/html');
const { isMaster } = require('../../utils/config');
const { link, scheduleDeletion } = require('../../utils/tg');
const { parse, strip } = require('../../utils/cmd');
// DB
const { admin, getUser } = require('../../stores/user');
/** @param { import('../../typings/context').ExtendedContext } ctx */
const adminHandler = async (ctx) => {
if (!isMaster(ctx.from)) return null;
const { targets } = parse(ctx.message);
if (targets.length > 1) {
return ctx
.replyWithHTML(' <b>Specify one user to promote.</b>')
.then(scheduleDeletion());
}
const userToAdmin = targets.length
? await getUser(strip(targets[0]))
: ctx.from;
if (!userToAdmin) {
return ctx
.replyWithHTML(
'❓ <b>User unknown.</b>\n' +
'Please forward their message, then try again.'
)
.then(scheduleDeletion());
}
if (userToAdmin.status === 'banned') {
return ctx.replyWithHTML(" <b>Can't admin banned user.</b>");
}
if (userToAdmin.status === 'admin') {
return ctx.replyWithHTML(
html`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`
);
}
await admin(userToAdmin);
return ctx.replyWithHTML(
html`⭐️ ${link(userToAdmin)} <b>is now admin.</b>`
);
};
module.exports = adminHandler;