2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 02:47:48 +00:00

59 lines
1.4 KiB
JavaScript
Raw Permalink 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 { parse, strip, substom } = require('../../utils/cmd');
const { scheduleDeletion } = require('../../utils/tg');
// DB
const { getUser } = require('../../stores/user');
/** @param { import('../../typings/context').ExtendedContext } ctx */
const warnHandler = async (ctx) => {
if (!ctx.message.chat.type.endsWith('group')) {
return ctx.replyWithHTML(
' <b>This command is only available in groups.</b>',
);
}
if (ctx.from.status !== 'admin') return null;
const { flags, reason, targets } = parse(ctx.message);
if (targets.length !== 1) {
return ctx.replyWithHTML(
' <b>Specify one user to warn.</b>',
).then(scheduleDeletion());
}
const userToWarn = await getUser(strip(targets[0]));
if (!userToWarn) {
return ctx.replyWithHTML(
'❓ <b>User unknown.</b>\n' +
'Please forward their message, then try again.',
).then(scheduleDeletion());
}
if (userToWarn.id === ctx.botInfo.id) return null;
if (userToWarn.status === 'admin') {
return ctx.replyWithHTML(' <b>Can\'t warn other admins.</b>');
}
if (reason.length === 0) {
return ctx.replyWithHTML(' <b>Need a reason to warn.</b>')
.then(scheduleDeletion());
}
return ctx.warn({
admin: ctx.from,
amend: flags.has('amend'),
reason: '[' + ctx.chat.title + '] ' + await substom(reason),
userToWarn,
mode: 'manual',
msg: ctx.message.reply_to_message,
});
};
module.exports = warnHandler;