diff --git a/src/modules/tg-logger/index.ts b/src/modules/tg-logger/index.ts index 736e534..c48e2cb 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" @@ -278,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 } @@ -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