2017-09-23 20:57:32 +02:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2020-05-13 17:22:30 +02:00
|
|
|
|
const Cmd = require('../../utils/cmd');
|
|
|
|
|
const { TgHtml } = require('../../utils/html');
|
2019-04-06 15:39:40 +02:00
|
|
|
|
const {
|
|
|
|
|
link,
|
|
|
|
|
msgLink,
|
|
|
|
|
scheduleDeletion,
|
|
|
|
|
} = require('../../utils/tg');
|
2017-09-23 20:57:32 +02:00
|
|
|
|
|
2020-03-09 23:27:19 +01:00
|
|
|
|
const { chats = {} } = require('../../utils/config').config;
|
2019-01-21 17:22:53 +01:00
|
|
|
|
|
2020-05-13 17:22:30 +02:00
|
|
|
|
const isQualified = member => member.status === 'creator' ||
|
|
|
|
|
member.can_delete_messages &&
|
|
|
|
|
member.can_restrict_members;
|
|
|
|
|
|
|
|
|
|
const adminMention = ({ user }) =>
|
|
|
|
|
TgHtml.tag`<a href="tg://user?id=${user.id}">​</a>`;
|
|
|
|
|
|
2020-03-10 22:10:48 +01:00
|
|
|
|
/** @param { import('../../typings/context').ExtendedContext } ctx */
|
2017-09-23 20:57:32 +02:00
|
|
|
|
const reportHandler = async ctx => {
|
2019-01-24 19:53:10 +01:00
|
|
|
|
if (!ctx.chat.type.endsWith('group')) return null;
|
2021-02-05 12:06:44 +01:00
|
|
|
|
// Ignore monospaced reports
|
2021-02-05 18:17:58 +01:00
|
|
|
|
if (ctx.message.entities?.[0]?.type === 'code' && ctx.message.entities[0].offset === 0)
|
|
|
|
|
return null;
|
2023-09-20 00:36:58 +05:30
|
|
|
|
const reply = ctx.message.reply_to_message;
|
|
|
|
|
if (!reply) {
|
2021-02-05 12:43:56 +01:00
|
|
|
|
await ctx.deleteMessage();
|
2020-05-13 17:22:30 +02:00
|
|
|
|
return ctx.replyWithHTML(
|
2023-09-19 23:59:20 +05:30
|
|
|
|
'ℹ️ <b>Reply to the message you\'d like to report</b>',
|
2018-11-20 11:47:30 +05:30
|
|
|
|
).then(scheduleDeletion());
|
2017-09-23 20:57:32 +02:00
|
|
|
|
}
|
2017-11-11 11:50:37 +01:00
|
|
|
|
const admins = (await ctx.getChatAdministrators())
|
2020-05-13 17:22:30 +02:00
|
|
|
|
.filter(isQualified)
|
|
|
|
|
.map(adminMention);
|
|
|
|
|
// eslint-disable-next-line max-len
|
2023-09-20 00:36:58 +05:30
|
|
|
|
const s = TgHtml.tag`❗️ <b>Message from ${link(reply.from)} was reported to the admins</b>.${TgHtml.join('', admins)}`;
|
2020-02-06 12:35:04 +01:00
|
|
|
|
const report = await ctx.replyWithHTML(s, {
|
2023-09-20 00:36:58 +05:30
|
|
|
|
reply_to_message_id: reply.message_id,
|
2017-09-23 20:57:32 +02:00
|
|
|
|
});
|
2020-02-06 12:35:04 +01:00
|
|
|
|
if (chats.report) {
|
2023-09-20 00:36:58 +05:30
|
|
|
|
const msg = await ctx.telegram.forwardMessage(chats.report, ctx.chat.id, reply.message_id);
|
2020-10-09 10:56:24 +02:00
|
|
|
|
await ctx.deleteMessage();
|
2022-05-31 17:17:45 +02:00
|
|
|
|
await ctx.telegram.sendMessage(
|
2020-02-06 12:35:04 +01:00
|
|
|
|
chats.report,
|
2020-05-13 17:22:30 +02:00
|
|
|
|
TgHtml.tag`❗️ ${link(ctx.from)} reported <a href="${msgLink(
|
2023-09-20 00:36:58 +05:30
|
|
|
|
reply,
|
|
|
|
|
)}">a message</a> from ${link(reply.from)} in ${ctx.chat.title}!`,
|
2020-05-13 17:22:30 +02:00
|
|
|
|
{
|
|
|
|
|
parse_mode: 'HTML',
|
2023-09-20 00:36:58 +05:30
|
|
|
|
reply_to_message_id: msg.message_id,
|
2020-02-06 12:35:04 +01:00
|
|
|
|
reply_markup: { inline_keyboard: [ [ {
|
|
|
|
|
text: '✔️ Handled',
|
2020-05-13 17:22:30 +02:00
|
|
|
|
callback_data: Cmd.stringify({
|
|
|
|
|
command: 'del',
|
|
|
|
|
flags: {
|
|
|
|
|
chat_id: report.chat.id,
|
|
|
|
|
msg_id: report.message_id,
|
|
|
|
|
},
|
|
|
|
|
reason: 'Report handled',
|
|
|
|
|
}),
|
|
|
|
|
} ] ] } },
|
2020-02-06 12:35:04 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2017-09-23 20:57:32 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = reportHandler;
|