-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfadingMessage.ts
More file actions
35 lines (27 loc) · 1.16 KB
/
fadingMessage.ts
File metadata and controls
35 lines (27 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { TextChannel } from "discord.js";
import * as sentry from "@sentry/node";
import type { BotContext } from "#/context.ts";
import log from "#log";
import * as fadingMessage from "#/storage/fadingMessage.ts";
export async function handleFadingMessages(context: BotContext) {
const now = Temporal.Now.instant();
const fadingMessages = await fadingMessage.findPendingForDeletion(now);
const toRemove = [];
for (const fadingMessage of fadingMessages) {
toRemove.push(fadingMessage.id);
try {
const guild = await context.client.guilds.fetch(fadingMessage.guildId);
const channel = guild.channels.cache.get(fadingMessage.channelId) as TextChannel;
const message = await channel.messages.fetch(fadingMessage.messageId);
await message.delete();
} catch (error: unknown) {
sentry.captureException(error);
if (error instanceof Error) {
log.warn(
`Failed to handle FadingMessage [${fadingMessage.id}] properly: ${error.stack}`,
);
}
}
}
await fadingMessage.destroyMultiple(toRemove);
}