2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-28 20:57:52 +00:00
2019-04-06 15:39:40 +02:00

54 lines
1.3 KiB
JavaScript
Raw 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 {
escapeHtml,
link,
msgLink,
scheduleDeletion,
} = require('../../utils/tg');
// Bot
const { replyOptions } = require('../../bot/options');
const { chats = {} } = require('../../config');
const reportHandler = async ctx => {
if (!ctx.chat.type.endsWith('group')) return null;
const msg = ctx.message;
if (!msg.reply_to_message) {
return ctx.reply(
' <b>Reply to message you\'d like to report</b>',
replyOptions
).then(scheduleDeletion());
}
if (chats.report) {
ctx.tg.sendMessage(
chats.report,
`❗️ Report in <a href="${msgLink(msg.reply_to_message)}">` +
escapeHtml(msg.chat.title) +
'</a>!',
replyOptions
);
}
const admins = (await ctx.getChatAdministrators())
.filter(member =>
member.status === 'creator' ||
member.can_delete_messages &&
member.can_restrict_members
// eslint-disable-next-line function-paren-newline
).map(member => member.user);
const adminObjects = admins.map(user => ({
first_name: '', // small hack to be able to use link function
id: user.id,
}));
const adminsMention = adminObjects.map(link).join('');
const s = `❗️${link(ctx.from)} <b>reported the message to the admins.</b>` +
`${adminsMention}`;
return ctx.replyWithHTML(s, {
reply_to_message_id: msg.reply_to_message.message_id
});
};
module.exports = reportHandler;