2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-24 19:07:17 +00:00

59 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2017-09-21 13:57:49 +04:30
'use strict';
// Utils
const { parse, strip, substom } = require('../../utils/cmd');
2018-05-04 14:21:51 +02:00
const { scheduleDeletion } = require('../../utils/tg');
2017-09-21 23:47:26 +04:30
2017-09-21 13:57:49 +04:30
// DB
const { getUser } = 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 */
const warnHandler = async (ctx) => {
2020-05-13 15:11:43 +02:00
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;
2020-05-13 15:11:43 +02:00
const { flags, reason, targets } = parse(ctx.message);
if (targets.length !== 1) {
2020-05-13 15:11:43 +02:00
return ctx.replyWithHTML(
' <b>Specify one user to warn.</b>',
).then(scheduleDeletion());
}
const userToWarn = await getUser(strip(targets[0]));
2017-09-25 12:40:04 +03:30
if (!userToWarn) {
2020-05-13 15:11:43 +02:00
return ctx.replyWithHTML(
'❓ <b>User unknown.</b>\n' +
'Please forward their message, then try again.',
).then(scheduleDeletion());
2017-09-21 13:57:49 +04:30
}
2019-01-31 20:54:45 +01:00
if (userToWarn.id === ctx.botInfo.id) return null;
if (userToWarn.status === 'admin') {
2020-05-13 15:11:43 +02:00
return ctx.replyWithHTML(' <b>Can\'t warn other admins.</b>');
2017-09-21 13:57:49 +04:30
}
if (reason.length === 0) {
2020-05-13 15:11:43 +02:00
return ctx.replyWithHTML(' <b>Need a reason to warn.</b>')
.then(scheduleDeletion());
}
return ctx.warn({
admin: ctx.from,
2019-05-31 17:02:00 +02:00
amend: flags.has('amend'),
2022-03-29 13:38:22 +02:00
reason: '[' + ctx.chat.title + '] ' + await substom(reason),
userToWarn,
mode: 'manual',
msg: ctx.message.reply_to_message,
});
2017-09-21 13:57:49 +04:30
};
module.exports = warnHandler;