-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfadingMessage.ts
More file actions
42 lines (36 loc) · 1.16 KB
/
fadingMessage.ts
File metadata and controls
42 lines (36 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
36
37
38
39
40
41
42
import type { Message } from "discord.js";
import type { FadingMessage } from "./db/model.ts";
import db from "#db";
export function startFadingMessage(
message: Message<true>,
deleteIn: Temporal.Duration,
ctx = db(),
): Promise<FadingMessage> {
const now = Temporal.Now.instant();
// adding milliseconds to a date is a hassle in sqlite, so we're doing it in JS
const endTime = now.add(deleteIn);
return ctx
.insertInto("fadingMessages")
.values({
beginTime: now.toString(),
endTime: endTime.toString(),
guildId: message.guild.id,
channelId: message.channel.id,
messageId: message.id,
})
.returningAll()
.executeTakeFirstOrThrow();
}
export function findPendingForDeletion(
now: Temporal.Instant,
ctx = db(),
): Promise<FadingMessage[]> {
return ctx
.selectFrom("fadingMessages")
.where("endTime", "<=", now.toString())
.selectAll()
.execute();
}
export async function destroyMultiple(ids: FadingMessage["id"][], ctx = db()) {
await ctx.deleteFrom("fadingMessages").where("id", "in", ids).execute();
}