2017-09-21 13:57:49 +04:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2020-05-23 21:56:04 +02:00
|
|
|
|
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
|
2019-01-28 21:46:29 +01:00
|
|
|
|
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 */
|
2018-02-05 19:17:52 +01:00
|
|
|
|
const warnHandler = async (ctx) => {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
if (!ctx.message.chat.type.endsWith('group')) {
|
|
|
|
|
return ctx.replyWithHTML(
|
2017-11-02 00:18:59 +03:30
|
|
|
|
'ℹ️ <b>This command is only available in groups.</b>',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
if (ctx.from.status !== 'admin') return null;
|
|
|
|
|
|
2020-05-13 15:11:43 +02:00
|
|
|
|
const { flags, reason, targets } = parse(ctx.message);
|
2019-01-28 21:46:29 +01:00
|
|
|
|
|
|
|
|
|
if (targets.length !== 1) {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML(
|
2019-01-28 21:46:29 +01:00
|
|
|
|
'ℹ️ <b>Specify one user to warn.</b>',
|
|
|
|
|
).then(scheduleDeletion());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const userToWarn = await getUser(strip(targets[0]));
|
2017-11-02 00:18:59 +03:30
|
|
|
|
|
2017-09-25 12:40:04 +03:30
|
|
|
|
if (!userToWarn) {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML(
|
2019-01-28 21:46:29 +01:00
|
|
|
|
'❓ <b>User unknown.</b>\n' +
|
|
|
|
|
'Please forward their message, then try again.',
|
2018-11-20 11:47:30 +05:30
|
|
|
|
).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;
|
2017-11-23 18:06:52 +03:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:20:50 +03:30
|
|
|
|
if (reason.length === 0) {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML('ℹ️ <b>Need a reason to warn.</b>')
|
2018-11-20 11:47:30 +05:30
|
|
|
|
.then(scheduleDeletion());
|
2017-10-10 22:20:50 +03:30
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 11:47:30 +05:30
|
|
|
|
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),
|
2018-11-20 11:47:30 +05:30
|
|
|
|
userToWarn,
|
|
|
|
|
mode: 'manual',
|
2023-09-19 23:59:20 +05:30
|
|
|
|
msg: ctx.message.reply_to_message,
|
2018-11-20 11:47:30 +05:30
|
|
|
|
});
|
2017-09-21 13:57:49 +04:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = warnHandler;
|