From 9c9922ca7e22a92d6c541d617f275eaae313d728 Mon Sep 17 00:00:00 2001 From: Tommaso Morganti Date: Sat, 11 Apr 2026 17:40:39 +0200 Subject: [PATCH 1/2] fix: delete mod action logs in chat after 2 mins --- src/modules/tg-logger/index.ts | 3 +++ src/utils/wait.ts | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/modules/tg-logger/index.ts b/src/modules/tg-logger/index.ts index 736e534..45e53b5 100644 --- a/src/modules/tg-logger/index.ts +++ b/src/modules/tg-logger/index.ts @@ -6,6 +6,7 @@ import { logger } from "@/logger" import { groupMessagesByChat, stripChatId } from "@/utils/chat" import { fmt, fmtChat, fmtDate, fmtUser } from "@/utils/format" import type { ModuleShared } from "@/utils/types" +import { after } from "@/utils/wait" import type { ModerationAction, PreDeleteResult } from "../moderation/types" import { type BanAll, banAllMenu, getBanAllText } from "./ban-all" import { grantCreatedMenu, grantMessageMenu } from "./grants" @@ -528,6 +529,8 @@ export class TgLogger extends Module { disable_notification: false, link_preview_options: { is_disabled: true }, }) + .then(after(120_000)) + .then((sent) => this.shared.api.deleteMessage(p.chat.id, sent.message_id)) .catch((error: unknown) => { logger.warn( { error, action: p.action }, diff --git a/src/utils/wait.ts b/src/utils/wait.ts index 172a3de..bd090b3 100644 --- a/src/utils/wait.ts +++ b/src/utils/wait.ts @@ -16,6 +16,31 @@ export function wait(time_ms: number): Promise { }) } +/** + * A utility function that returns a function which, when called with a value, waits for a specified + * amount of time and then resolves with that value. This is useful for chaining in promise-based code + * where you want to introduce a delay before the next step. + * + * @param time_ms The time to wait in milliseconds before resolving with the provided value + * @returns A function that takes a value and returns a promise that resolves with that value after the specified time + * + * @example + * ```ts + * // Usage in a promise chain + * someAsyncFunction() + * .then(after(1000)) // Waits for 1 second before passing the result to the next then + * .then((result) => { + * console.log(result); // This will log the result of someAsyncFunction after a 1 second delay + * }); + * ``` + */ +export function after(time_ms: number): (value: T) => Promise { + return async (value: T): Promise => { + await wait(time_ms) + return value + } +} + /** * A utility class that implements PromiseLike and allows manual resolution of the promise. * This is useful when you need to await a value that will be provided later, outside of the From c52986c348fdeef985dc0a5e1a6df92c83fbaf39 Mon Sep 17 00:00:00 2001 From: Tommaso Morganti Date: Sat, 11 Apr 2026 17:47:19 +0200 Subject: [PATCH 2/2] fix: fire n forget --- src/modules/tg-logger/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/tg-logger/index.ts b/src/modules/tg-logger/index.ts index 45e53b5..c48e2cb 100644 --- a/src/modules/tg-logger/index.ts +++ b/src/modules/tg-logger/index.ts @@ -279,7 +279,7 @@ export class TgLogger extends Module { ? new InlineKeyboard().url("See Deleted Message", props.preDeleteRes.link) : undefined await this.log(isAutoModeration ? this.topics.autoModeration : this.topics.adminActions, mainMsg, { reply_markup }) - if (!isAutoModeration) await this.logModActionInChat(props) + if (!isAutoModeration) void this.logModActionInChat(props) return mainMsg }