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

70 lines
2.0 KiB
JavaScript
Raw Normal View History

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}">&#8203;</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;
const reply = ctx.message.reply_to_message;
if (!reply) {
await ctx.deleteMessage();
2020-05-13 17:22:30 +02:00
return ctx.replyWithHTML(
' <b>Reply to the message you\'d like to report</b>',
).then(scheduleDeletion());
2017-09-23 20:57:32 +02:00
}
const admins = (await ctx.getChatAdministrators())
2020-05-13 17:22:30 +02:00
.filter(isQualified)
.map(adminMention);
// eslint-disable-next-line max-len
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, {
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) {
const msg = await ctx.telegram.forwardMessage(chats.report, ctx.chat.id, reply.message_id);
await ctx.deleteMessage();
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(
reply,
)}">a message</a> from ${link(reply.from)} in ${ctx.chat.title}!`,
2020-05-13 17:22:30 +02:00
{
parse_mode: 'HTML',
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;