2017-09-22 15:52:27 +03:30
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const { displayUser, scheduleDeletion } = require('../../utils/tg');
|
2020-05-13 15:11:43 +02:00
|
|
|
|
const { html } = require('../../utils/html');
|
2020-05-23 21:56:04 +02:00
|
|
|
|
const { parse, strip, substom } = require('../../utils/cmd');
|
2017-09-22 15:52:27 +03:30
|
|
|
|
|
|
|
|
|
// Bot
|
|
|
|
|
|
|
|
|
|
// DB
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const { getUser } = require('../../stores/user');
|
2018-02-05 19:17:52 +01:00
|
|
|
|
|
2020-03-10 22:10:48 +01:00
|
|
|
|
/** @param { import('../../typings/context').ExtendedContext } ctx */
|
2018-02-05 19:17:52 +01:00
|
|
|
|
const banHandler = async (ctx) => {
|
2020-07-15 18:47:44 +04:30
|
|
|
|
if (ctx.chat.type === 'private') {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML(
|
2019-01-28 21:46:29 +01:00
|
|
|
|
'ℹ️ <b>This command is only available in groups.</b>',
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-09-22 15:52:27 +03:30
|
|
|
|
|
2018-02-05 19:17:52 +01:00
|
|
|
|
if (ctx.from.status !== 'admin') return null;
|
2017-11-02 00:18:59 +03:30
|
|
|
|
|
2020-05-13 15:11:43 +02:00
|
|
|
|
const { flags, targets, reason } = parse(ctx.message);
|
2019-01-28 21:46:29 +01:00
|
|
|
|
|
2019-01-31 20:19:39 +01:00
|
|
|
|
if (targets.length === 0) {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML(
|
2019-01-31 20:19:39 +01:00
|
|
|
|
'ℹ️ <b>Specify at least one user to ban.</b>',
|
2019-01-28 21:46:29 +01:00
|
|
|
|
).then(scheduleDeletion());
|
2017-11-02 00:18:59 +03:30
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 20:19:39 +01:00
|
|
|
|
if (reason.length === 0) {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML('ℹ️ <b>Need a reason to ban.</b>')
|
2019-01-31 20:19:39 +01:00
|
|
|
|
.then(scheduleDeletion());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (targets.length > 1) {
|
|
|
|
|
return ctx.batchBan({ admin: ctx.from, reason, targets });
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
const userToBan = await getUser(strip(targets[0])) || targets[0];
|
|
|
|
|
|
|
|
|
|
if (!userToBan.id) {
|
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-25 12:40:04 +03:30
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
if (userToBan.id === ctx.botInfo.id) return null;
|
2017-11-23 18:06:52 +03:30
|
|
|
|
|
2019-01-28 21:46:29 +01:00
|
|
|
|
if (userToBan.status === 'admin') {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML('ℹ️ <b>Can\'t ban other admins.</b>');
|
2017-10-10 22:20:50 +03:30
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 17:25:59 +02:00
|
|
|
|
if (!flags.has('amend') && userToBan.status === 'banned') {
|
2020-05-13 15:11:43 +02:00
|
|
|
|
return ctx.replyWithHTML(
|
|
|
|
|
html`🚫 ${displayUser(userToBan)} <b>is already banned.</b>`,
|
2017-10-31 23:08:22 +01:00
|
|
|
|
);
|
2017-09-22 15:52:27 +03:30
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 21:56:04 +02:00
|
|
|
|
return ctx.ban({
|
|
|
|
|
admin: ctx.from,
|
2022-03-29 13:38:22 +02:00
|
|
|
|
reason: '[' + ctx.chat.title + '] ' + await substom(reason),
|
2020-05-23 21:56:04 +02:00
|
|
|
|
userToBan,
|
2023-09-19 23:59:20 +05:30
|
|
|
|
msg: ctx.message.reply_to_message
|
2020-05-23 21:56:04 +02:00
|
|
|
|
});
|
2017-09-22 15:52:27 +03:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = banHandler;
|