Skip to content

Commit e2f99d1

Browse files
committed
Add findExtendablePollsInChannel
1 parent f3150fd commit e2f99d1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/service/poll.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { GuildMember, Message, MessageReaction, User } from "discord.js";
1+
import type { GuildMember, Message, MessageReaction, TextBasedChannel, User } from "discord.js";
22
import type { Temporal } from "@js-temporal/polyfill";
33

44
import * as legacyDelayedPoll from "@/service/delayedPollLegacy.js";
@@ -55,6 +55,10 @@ export async function findPoll(pollId: PollId): Promise<polls.PollWithOptions |
5555
return await polls.findPoll(pollId);
5656
}
5757

58+
export async function findExtendablePollsInChannel(channel: TextBasedChannel): Promise<Poll[]> {
59+
return polls.findExtendablePollsInChannel(channel.id);
60+
}
61+
5862
export async function getExpiredPolls(now: Temporal.Instant): Promise<Poll[]> {
5963
return await polls.getExpiredPolls(now);
6064
}

src/storage/poll.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ export async function findPoll(pollId: PollId, ctx = db()): Promise<PollWithOpti
126126
});
127127
}
128128

129+
export async function findExtendablePollsInChannel(
130+
channelId: Snowflake,
131+
ctx = db(),
132+
): Promise<Poll[]> {
133+
return ctx
134+
.selectFrom("polls")
135+
.where("embedChannelId", "=", channelId)
136+
.where("extendable", "=", true)
137+
.where("ended", "=", false)
138+
.orderBy("createdAt", "desc")
139+
.limit(25)
140+
.selectAll()
141+
.execute();
142+
}
143+
129144
export async function getExpiredPolls(now: Temporal.Instant, ctx = db()): Promise<Poll[]> {
130145
return await ctx
131146
.selectFrom("polls")

0 commit comments

Comments
 (0)