Skip to content

Commit

Permalink
Add optional /report reason and show it to admins (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rn3j committed Oct 23, 2023
1 parent 515e6cd commit 972090d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion handlers/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const userCommands = `\
<code>/staff</code> - Shows a list of admins.
<code>/link</code> - Show the current group's link.
<code>/groups</code> - Show a list of groups which the bot is admin in.
<code>/report</code> - Reports the replied-to message to admins.\n
<code>/report [reason]</code> - Reports the replied-to message to admins, reason is optional.\n
`;
const role = R.prop('role');
const name = R.prop('name');
Expand Down
11 changes: 10 additions & 1 deletion handlers/commands/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: <i>${reportMessage}</i>`
}

await ctx.deleteMessage();
await ctx.telegram.sendMessage(
chats.report,
TgHtml.tag`❗️ ${link(ctx.from)} reported <a href="${msgLink(
reply,
)}">a message</a> from ${link(reply.from)} in ${ctx.chat.title}!`,
)}">a message</a> from ${link(reply.from)} in ${ctx.chat.title}!${reportReason}`,
{
parse_mode: 'HTML',
reply_to_message_id: msg.message_id,
Expand Down

0 comments on commit 972090d

Please sign in to comment.