Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/modules/tg-logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -278,7 +279,7 @@ export class TgLogger extends Module<ModuleShared> {
? 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
}

Expand Down Expand Up @@ -528,6 +529,8 @@ export class TgLogger extends Module<ModuleShared> {
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 },
Expand Down
25 changes: 25 additions & 0 deletions src/utils/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ export function wait(time_ms: number): Promise<void> {
})
}

/**
* 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): <T>(value: T) => Promise<T> {
return async <T>(value: T): Promise<T> => {
await wait(time_ms)
return value
}
}

/**
* A utility class that implements PromiseLike<T> 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
Expand Down
Loading