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

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-09-23 20:57:32 +02:00
'use strict';
// Utils
2019-04-06 15:39:40 +02:00
const {
escapeHtml,
link,
msgLink,
scheduleDeletion,
} = require('../../utils/tg');
2017-09-23 20:57:32 +02:00
2017-09-24 14:32:27 +03:30
// Bot
const { replyOptions } = require('../../bot/options');
2019-01-21 17:22:53 +01:00
const { chats = {} } = require('../../config');
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;
2017-09-23 20:57:32 +02:00
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());
2017-09-23 20:57:32 +02:00
}
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);
2017-09-23 20:57:32 +02:00
const adminObjects = admins.map(user => ({
first_name: '', // small hack to be able to use link function
id: user.id,
2017-09-23 20:57:32 +02:00
}));
const adminsMention = adminObjects.map(link).join('');
const s = `❗️${link(ctx.from)} <b>reported the message to the admins.</b>` +
`${adminsMention}`;
2020-02-06 12:35:04 +01:00
const report = await ctx.replyWithHTML(s, {
2017-09-23 20:57:32 +02:00
reply_to_message_id: msg.reply_to_message.message_id
});
2020-02-06 12:35:04 +01:00
if (chats.report) {
await ctx.tg.sendMessage(
chats.report,
`❗️ Report in <a href="${msgLink(msg.reply_to_message)}">` +
escapeHtml(msg.chat.title) +
'</a>!',
{ ...replyOptions,
reply_markup: { inline_keyboard: [ [ {
text: '✔️ Handled',
// eslint-disable-next-line max-len
callback_data: `/del -chat_id=${report.chat.id} -msg_id=${report.message_id} Report handled`
} ] ] } }
);
}
return null;
2017-09-23 20:57:32 +02:00
};
module.exports = reportHandler;