2017-09-23 20:57:32 +02:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Utils
|
2019-01-21 17:22:53 +01:00
|
|
|
|
const { escapeHtml, link, 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 => {
|
|
|
|
|
const msg = ctx.message;
|
|
|
|
|
if (!msg.reply_to_message) {
|
2017-10-31 23:08:22 +01:00
|
|
|
|
return ctx.reply(
|
|
|
|
|
'ℹ️ <b>Reply to message you\'d like to report</b>',
|
|
|
|
|
replyOptions
|
2018-11-20 11:47:30 +05:30
|
|
|
|
).then(scheduleDeletion());
|
2017-09-23 20:57:32 +02:00
|
|
|
|
}
|
2019-01-21 17:22:53 +01:00
|
|
|
|
if (chats.report) {
|
|
|
|
|
ctx.tg.sendMessage(
|
|
|
|
|
chats.report,
|
|
|
|
|
`❗️<b>Report in ${escapeHtml(msg.chat.title)}!</b>`,
|
|
|
|
|
replyOptions
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-11-11 11:50:37 +01: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 => ({
|
2017-10-08 11:45:43 +03:30
|
|
|
|
first_name: '', // small hack to be able to use link function
|
2017-09-29 15:53:21 +02:00
|
|
|
|
id: user.id,
|
2017-09-23 20:57:32 +02:00
|
|
|
|
}));
|
2017-10-08 11:45:43 +03:30
|
|
|
|
const adminsMention = adminObjects.map(link).join('');
|
|
|
|
|
const s = `❗️${link(ctx.from)} <b>reported the message to the admins.</b>` +
|
|
|
|
|
`${adminsMention}`;
|
2017-09-23 20:57:32 +02:00
|
|
|
|
return ctx.replyWithHTML(s, {
|
|
|
|
|
reply_to_message_id: msg.reply_to_message.message_id
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = reportHandler;
|