From 972090d00ceb8d33af81faf74e3c41a56b9adee1 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 23 Oct 2023 11:55:49 +0200 Subject: [PATCH] Add optional /report reason and show it to admins (#171) --- README.md | 2 +- handlers/commands/commands.js | 2 +- handlers/commands/report.js | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b5e979bf..9978e870 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Command | Role | Available at | Description `/staff` | _Everyone_ | _Everywhere_ | Shows a list of admins. `/link` | _Everyone_ | _Everywhere_ | Shows the current group's link. `/groups` | _Everyone_ | _Everywhere_ | Shows a list of groups which the bot is admin in. -`/report` | _Everyone_ | _Everywhere_ | Reports the replied-to message to admins. +`/report [reason]` | _Everyone_ | _Everywhere_ | Reports the replied-to message to admins, reason is optional. `/commands` | _Everyone_ | _In-Bot_ | Shows a list of available commands. `/help` \| `/start` | _Everyone_ | _In-Bot_ | How to use the bot. diff --git a/handlers/commands/commands.js b/handlers/commands/commands.js index fece333f..77e86bc5 100644 --- a/handlers/commands/commands.js +++ b/handlers/commands/commands.js @@ -37,7 +37,7 @@ const userCommands = `\ /staff - Shows a list of admins. /link - Show the current group's link. /groups - Show a list of groups which the bot is admin in. -/report - Reports the replied-to message to admins.\n +/report [reason] - Reports the replied-to message to admins, reason is optional.\n `; const role = R.prop('role'); const name = R.prop('name'); diff --git a/handlers/commands/report.js b/handlers/commands/report.js index 35f4a1e5..9b72f541 100644 --- a/handlers/commands/report.js +++ b/handlers/commands/report.js @@ -41,12 +41,21 @@ const reportHandler = async ctx => { }); if (chats.report) { const msg = await ctx.telegram.forwardMessage(chats.report, ctx.chat.id, reply.message_id); + + const parts = ctx.message.text.split(/\s+/) + parts.shift(); + const reportMessage = parts.join(' '); + let reportReason = '' + if (reportMessage.trim() !== '') { + reportReason = TgHtml.tag`\n\n\nReport reason: ${reportMessage}` + } + await ctx.deleteMessage(); await ctx.telegram.sendMessage( chats.report, TgHtml.tag`❗️ ${link(ctx.from)} reported a message from ${link(reply.from)} in ${ctx.chat.title}!`, + )}">a message from ${link(reply.from)} in ${ctx.chat.title}!${reportReason}`, { parse_mode: 'HTML', reply_to_message_id: msg.message_id,