Skip to content

Commit efcd382

Browse files
committed
feat: noReportChatDeletion
1 parent 4d8ed6c commit efcd382

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"prettier"
2222
],
2323
"rules": {
24-
"@typescript-eslint/ban-ts-ignore": "warn",
24+
"@typescript-eslint/ban-ts-comment": "warn",
2525
"@typescript-eslint/camelcase": "off",
2626
"@typescript-eslint/explicit-function-return-type": "off",
2727
"@typescript-eslint/no-floating-promises": "error",

example.config.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ const config = {
4242

4343

4444
chats: {
45+
4546
/**
4647
* @type {(number | false)}
47-
* Chat to send member (un)ban/(un)warn/report notifications and relevant messages to.
48-
* Pass false to disable this feature.
48+
* Chat to send member (un)ban/(un)warn/report notifications and
49+
* relevant messages to. Pass false to disable this feature.
4950
*/
5051
adminLog: false,
5152

@@ -62,6 +63,13 @@ const config = {
6263
* Pass false to disable this feature.
6364
*/
6465
report: false,
66+
67+
/**
68+
* @type {(true | false)}
69+
* Disable whether clicking on `[Report handled]` deletes the
70+
* report chat message.
71+
*/
72+
noReportChatDeletion: false,
6573
},
6674

6775
/**
@@ -73,7 +81,7 @@ const config = {
7381

7482
deleteCustom: {
7583
longerThan: 450, // UTF-16 characters
76-
after: '20 minutes'
84+
after: '20 minutes',
7785
},
7886

7987
/**
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
import { CallbackQuery, Update } from "telegraf/types";
1+
import { CallbackQuery, Message, Update } from "telegraf/types";
2+
import { config } from "../../utils/config";
23
import type { ExtendedContext } from "../../typings/context";
34

4-
export = (ctx: ExtendedContext<Update.CallbackQueryUpdate<CallbackQuery.DataQuery>>) => {
5+
export = async (
6+
ctx: ExtendedContext<Update.CallbackQueryUpdate<CallbackQuery.DataQuery>>,
7+
) => {
58
if (ctx.from?.status !== "admin") {
69
return ctx.answerCbQuery("✋ Not permitted!", { cache_time: 600 });
710
}
811

9-
const [, chatId, msgId] = ctx.match!;
12+
// @ts-expect-error ctx.match is available but not registered in this callback type
13+
const [, chatId, msgId] = (ctx.match as string[])!;
1014

15+
// delete the report in the actual chat
16+
await ctx.telegram.deleteMessage(+chatId, +msgId);
17+
18+
if (config.chats?.noReportChatDeletion) return null;
1119
return Promise.all([
1220
// delete the report in the report chat
1321
ctx.deleteMessage(),
1422
// 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
17-
ctx.telegram.deleteMessage(+chatId, +msgId),
23+
ctx.deleteMessage(
24+
(ctx.callbackQuery.message as Message.TextMessage)?.reply_to_message
25+
?.message_id,
26+
),
1827
]);
1928
};

typings/config.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export interface Config {
3838
* Pass false to disable this feature.
3939
*/
4040
report?: number | false;
41+
42+
/**
43+
* Disable whether clicking on `[Report handled]` deletes the
44+
* report chat message.
45+
*/
46+
noReportChatDeletion: boolean;
4147
};
4248

4349
/**

0 commit comments

Comments
 (0)