diff --git a/bot/context.js b/bot/context.js index 82876abb..e15b700a 100644 --- a/bot/context.js +++ b/bot/context.js @@ -38,10 +38,10 @@ module.exports = { loggedReply(html, extra) { if (chats.adminLog) { - this.tg + this.telegram .sendMessage( chats.adminLog, - html.toJSON().replace(/\[(\d+)<\/code>\]/g, '[#u$1]'), + html, { parse_mode: 'HTML' }, ) .catch(() => null); diff --git a/example.config.js b/example.config.js index b9000783..61b3b901 100644 --- a/example.config.js +++ b/example.config.js @@ -42,6 +42,12 @@ const config = { chats: { + /** + * @type {(number | false)} + * Chat to send member (un)ban/(un)warn/report notifications and relevant messages to. + * Pass false to disable this feature. + */ + adminLog: false, /** * @type {(number | false)} diff --git a/handlers/commands/ban.js b/handlers/commands/ban.js index fbec2a80..a3bc007a 100644 --- a/handlers/commands/ban.js +++ b/handlers/commands/ban.js @@ -4,6 +4,7 @@ const { displayUser, scheduleDeletion } = require('../../utils/tg'); const { html } = require('../../utils/html'); const { parse, strip, substom } = require('../../utils/cmd'); +const { chats = {} } = require('../../utils/config').config; // Bot @@ -53,6 +54,9 @@ const banHandler = async (ctx) => { } if (ctx.message.reply_to_message) { + if (chats.adminLog) { + await ctx.telegram.forwardMessage(chats.adminLog, ctx.message.chat.id, ctx.message.reply_to_message.message_id) + } ctx.deleteMessage(ctx.message.reply_to_message.message_id) .catch(() => null); } diff --git a/handlers/commands/leave.ts b/handlers/commands/leave.ts index 1ed15acb..7357c62d 100644 --- a/handlers/commands/leave.ts +++ b/handlers/commands/leave.ts @@ -11,7 +11,7 @@ const leaveCommandHandler = async (ctx: ExtendedContext) => { const group = query ? await managesGroup( /^-?\d+/.test(query) ? { id: +query } : { title: query } - ) + ) : ctx.chat; if (!group) { return ctx.replyWithHTML("❓ Unknown group."); diff --git a/handlers/commands/report.js b/handlers/commands/report.js index 157898f2..5caa5692 100644 --- a/handlers/commands/report.js +++ b/handlers/commands/report.js @@ -3,13 +3,13 @@ // Utils const Cmd = require('../../utils/cmd'); const { TgHtml } = require('../../utils/html'); +const { chats = {} } = require('../../utils/config').config; const { link, msgLink, scheduleDeletion, } = require('../../utils/tg'); -const { chats = {} } = require('../../utils/config').config; const isQualified = member => member.status === 'creator' || member.can_delete_messages && @@ -27,7 +27,7 @@ const reportHandler = async ctx => { if (!ctx.message.reply_to_message) { await ctx.deleteMessage(); return ctx.replyWithHTML( - 'ℹ️ Reply to message you\'d like to report', + 'ℹ️ Reply to the message you\'d like to report', ).then(scheduleDeletion()); } const admins = (await ctx.getChatAdministrators()) @@ -60,6 +60,18 @@ const reportHandler = async ctx => { } ] ] } }, ); } + if (chats.adminLog) { + await ctx.telegram.forwardMessage(chats.adminLog, ctx.message.chat.id, ctx.message.reply_to_message.message_id) + await ctx.telegram.sendMessage( + chats.adminLog, + TgHtml.tag`❗️ ${link(ctx.from)} reported a message from ${link(ctx.message.reply_to_message.from)} in ${ctx.chat.title}!`, + { + parse_mode: 'HTML' + }, + ); + } return null; }; diff --git a/handlers/commands/warn.js b/handlers/commands/warn.js index da9a8627..54cbf8a3 100644 --- a/handlers/commands/warn.js +++ b/handlers/commands/warn.js @@ -3,6 +3,7 @@ // Utils const { parse, strip, substom } = require('../../utils/cmd'); const { scheduleDeletion } = require('../../utils/tg'); +const { chats = {} } = require('../../utils/config').config; // DB const { getUser } = require('../../stores/user'); @@ -46,6 +47,9 @@ const warnHandler = async (ctx) => { } if (ctx.message.reply_to_message) { + if (chats.adminLog) { + await ctx.telegram.forwardMessage(chats.adminLog, ctx.message.chat.id, ctx.message.reply_to_message.message_id) + } ctx.deleteMessage(ctx.message.reply_to_message.message_id) .catch(() => null); } diff --git a/handlers/middlewares/commandButtons.js b/handlers/middlewares/commandButtons.js index 84e00abb..d13379ae 100644 --- a/handlers/middlewares/commandButtons.js +++ b/handlers/middlewares/commandButtons.js @@ -20,7 +20,7 @@ module.exports = (ctx, next) => { }; /** @type { import('../../typings/context').ExtendedContext } */ - const cbCtx = new Context(cbUpdate, ctx.tg, ctx.options); + const cbCtx = new Context(cbUpdate, ctx.telegram, ctx.options); Object.assign(cbCtx, contextCustomizations); cbCtx.botInfo = ctx.botInfo; diff --git a/package.json b/package.json index f1452258..86d99288 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "the_guard_bot", - "version": "1.5.0", + "version": "1.5.1", "description": "Telegram guard bot to manage a network of groups.", "main": "index.js", "scripts": { diff --git a/typings/config.d.ts b/typings/config.d.ts index db215f21..e6405b50 100644 --- a/typings/config.d.ts +++ b/typings/config.d.ts @@ -24,8 +24,9 @@ export interface Config { chats?: { /** * Chat to log all admin actions to. + * Pass false to disable this feature. */ - adminLog?: number; + adminLog?: number | false; /** * Chat to send member join/leave notifications to.