2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-27 20:37:30 +00:00
GingerPlusPlus 48c7733cf1 Report to local admins, instead of bot admins
1. This ensures that bot won't try mentioning admins which are not in
the group (which may fail),
2. This allows also local admins to sort out the situation.
2017-11-11 11:50:37 +01:00

37 lines
1.0 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 { link, scheduleDeletion } = require('../../utils/tg');
// Bot
const { replyOptions } = require('../../bot/options');
const reportHandler = async ctx => {
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);
}
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;