2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 18:38:05 +00:00

79 lines
2.3 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
// Utils
const Cmd = require('../../utils/cmd');
const { TgHtml } = require('../../utils/html');
const {
link,
msgLink,
scheduleDeletion,
} = require('../../utils/tg');
const { chats = {} } = require('../../utils/config').config;
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>`;
/** @param { import('../../typings/context').ExtendedContext } ctx */
const reportHandler = async ctx => {
if (!ctx.chat.type.endsWith('group')) return null;
// Ignore monospaced reports
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();
return ctx.replyWithHTML(
' <b>Reply to the message you\'d like to report</b>',
).then(scheduleDeletion());
}
const admins = (await ctx.getChatAdministrators())
.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)}`;
const report = await ctx.replyWithHTML(s, {
reply_to_message_id: reply.message_id,
});
if (chats.report) {
const msg = await ctx.telegram.forwardMessage(chats.report, ctx.chat.id, reply.message_id);
const parts = ctx.message.text.split(/\s+/)
parts.shift();
const reportMessage = parts.join(' ');
let reportReason = ''
if (reportMessage.trim() !== '') {
reportReason = TgHtml.tag`\n\n\nReport reason: <i>${reportMessage}</i>`
}
await ctx.deleteMessage();
await ctx.telegram.sendMessage(
chats.report,
TgHtml.tag`❗️ ${link(ctx.from)} reported <a href="${msgLink(
reply,
)}">a message</a> from ${link(reply.from)} in ${ctx.chat.title}!${reportReason}`,
{
parse_mode: 'HTML',
reply_to_message_id: msg.message_id,
reply_markup: { inline_keyboard: [ [ {
text: '✔️ Handled',
callback_data: Cmd.stringify({
command: 'del',
flags: {
chat_id: report.chat.id,
msg_id: report.message_id,
},
reason: 'Report handled',
}),
} ] ] } },
);
}
return null;
};
module.exports = reportHandler;