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

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