Skip to content

Commit 5bedd0d

Browse files
committed
feat: forward reported msg to report chat
1 parent 610fd60 commit 5bedd0d

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

handlers/commands/report.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const reportHandler = async ctx => {
2424
// Ignore monospaced reports
2525
if (ctx.message.entities?.[0]?.type === 'code' && ctx.message.entities[0].offset === 0)
2626
return null;
27-
if (!ctx.message.reply_to_message) {
27+
const reply = ctx.message.reply_to_message;
28+
if (!reply) {
2829
await ctx.deleteMessage();
2930
return ctx.replyWithHTML(
3031
'ℹ️ <b>Reply to the message you\'d like to report</b>',
@@ -34,19 +35,21 @@ const reportHandler = async ctx => {
3435
.filter(isQualified)
3536
.map(adminMention);
3637
// eslint-disable-next-line max-len
37-
const s = TgHtml.tag`❗️ <b>Message from ${link(ctx.message.reply_to_message.from)} was reported to the admins</b>.${TgHtml.join('', admins)}`;
38+
const s = TgHtml.tag`❗️ <b>Message from ${link(reply.from)} was reported to the admins</b>.${TgHtml.join('', admins)}`;
3839
const report = await ctx.replyWithHTML(s, {
39-
reply_to_message_id: ctx.message.reply_to_message.message_id,
40+
reply_to_message_id: reply.message_id,
4041
});
4142
if (chats.report) {
43+
const msg = await ctx.telegram.forwardMessage(chats.report, ctx.chat.id, reply.message_id);
4244
await ctx.deleteMessage();
4345
await ctx.telegram.sendMessage(
4446
chats.report,
4547
TgHtml.tag`❗️ ${link(ctx.from)} reported <a href="${msgLink(
46-
ctx.message.reply_to_message,
47-
)}">a message</a> from ${link(ctx.message.reply_to_message.from)} in ${ctx.chat.title}!`,
48+
reply,
49+
)}">a message</a> from ${link(reply.from)} in ${ctx.chat.title}!`,
4850
{
4951
parse_mode: 'HTML',
52+
reply_to_message_id: msg.message_id,
5053
reply_markup: { inline_keyboard: [ [ {
5154
text: '✔️ Handled',
5255
callback_data: Cmd.stringify({
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
import { CallbackQuery, Update } from "telegraf/types";
12
import type { ExtendedContext } from "../../typings/context";
23

3-
export = (ctx: ExtendedContext) => {
4+
export = (ctx: ExtendedContext<Update.CallbackQueryUpdate<CallbackQuery.DataQuery>>) => {
45
if (ctx.from?.status !== "admin") {
5-
return ctx.answerCbQuery("✋ Not permitted!", false, { cache_time: 600 });
6+
return ctx.answerCbQuery("✋ Not permitted!", { cache_time: 600 });
67
}
78

89
const [, chatId, msgId] = ctx.match!;
910

1011
return Promise.all([
12+
// delete the report in the report chat
1113
ctx.deleteMessage(),
14+
// delete the forwarded contextual message in report chat
15+
ctx.deleteMessage(ctx.callbackQuery.message?.reply_to_message?.message_id),
16+
// delete the report in the actual chat
1217
ctx.telegram.deleteMessage(+chatId, +msgId),
1318
]);
1419
};

typings/context.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Convenience, Message, MessageId, User } from "telegraf/types";
1+
import type { Convenience, Message, Update, User } from "telegraf/types";
22
import type { Context } from "telegraf";
33
import type { TgHtml } from "../utils/html";
44

@@ -46,7 +46,7 @@ export interface ContextExtensions {
4646
): Promise<Message>;
4747
}
4848

49-
export type ExtendedContext = ContextExtensions &
50-
Context & {
49+
export type ExtendedContext<U extends Update = Update> = ContextExtensions &
50+
Context<U> & {
5151
from?: DbUser;
5252
};

0 commit comments

Comments
 (0)