diff --git a/.eslintrc.json b/.eslintrc.json index 74a4073..b4bfbc9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,7 +21,7 @@ "prettier" ], "rules": { - "@typescript-eslint/ban-ts-ignore": "warn", + "@typescript-eslint/ban-ts-comment": "warn", "@typescript-eslint/camelcase": "off", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-floating-promises": "error", diff --git a/example.config.js b/example.config.js index 61b3b90..4ab47a9 100644 --- a/example.config.js +++ b/example.config.js @@ -42,10 +42,11 @@ 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. + * Chat to send member (un)ban/(un)warn/report notifications and + * relevant messages to. Pass false to disable this feature. */ adminLog: false, @@ -62,6 +63,13 @@ const config = { * Pass false to disable this feature. */ report: false, + + /** + * @type {(true | false)} + * Disable whether clicking on `[Report handled]` deletes the + * report chat message. + */ + noReportChatDeletion: false, }, /** @@ -73,7 +81,7 @@ const config = { deleteCustom: { longerThan: 450, // UTF-16 characters - after: '20 minutes' + after: '20 minutes', }, /** diff --git a/handlers/middlewares/reportHandled.ts b/handlers/middlewares/reportHandled.ts index 61d4f97..4e2d11b 100644 --- a/handlers/middlewares/reportHandled.ts +++ b/handlers/middlewares/reportHandled.ts @@ -1,19 +1,28 @@ -import { CallbackQuery, Update } from "telegraf/types"; +import { CallbackQuery, Message, Update } from "telegraf/types"; +import { config } from "../../utils/config"; import type { ExtendedContext } from "../../typings/context"; -export = (ctx: ExtendedContext>) => { +export = async ( + ctx: ExtendedContext>, +) => { if (ctx.from?.status !== "admin") { return ctx.answerCbQuery("✋ Not permitted!", { cache_time: 600 }); } - const [, chatId, msgId] = ctx.match!; + // @ts-expect-error ctx.match is available but not registered in this callback type + const [, chatId, msgId] = (ctx.match as string[])!; + // delete the report in the actual chat + await ctx.telegram.deleteMessage(+chatId, +msgId); + + if (config.chats?.noReportChatDeletion) return null; return Promise.all([ // delete the report in the report chat ctx.deleteMessage(), // delete the forwarded contextual message in report chat - ctx.deleteMessage(ctx.callbackQuery.message?.reply_to_message?.message_id), - // delete the report in the actual chat - ctx.telegram.deleteMessage(+chatId, +msgId), + ctx.deleteMessage( + (ctx.callbackQuery.message as Message.TextMessage)?.reply_to_message + ?.message_id, + ), ]); }; diff --git a/typings/config.d.ts b/typings/config.d.ts index fed3afc..7373ab2 100644 --- a/typings/config.d.ts +++ b/typings/config.d.ts @@ -38,6 +38,12 @@ export interface Config { * Pass false to disable this feature. */ report?: number | false; + + /** + * Disable whether clicking on `[Report handled]` deletes the + * report chat message. + */ + noReportChatDeletion: boolean; }; /**