Skip to content

Commit d719ad7

Browse files
committed
Address some review comments
1 parent 70a401f commit d719ad7

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

docs/concepts/events.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,6 @@ The `Vote` object contains the following properties:
485485
`~Vote.message`
486486
: The poll message that was voted on.
487487

488-
Note that for multiple choice polls, each option selection creates a separate
489-
`Vote` object, even if the same user selects multiple options.
490-
491488
> [!TIP]
492489
> You can check if a poll allows multiple selections by accessing the
493490
> `vote.poll.multiple` property:

examples/otp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ app.post("/authenticate", async (c) => {
203203
const form = await c.req.formData();
204204
const messageId = form.get("messageId")?.toString();
205205
if (messageId == null) return c.notFound();
206-
const key = await kv.get<string>(["emojis", messageId]);
206+
const key = await kv.get<string[]>(["emojis", messageId]);
207207
if (key?.value == null) return c.notFound();
208208
const emojis = new Set(key.value);
209209
const answer = new Set<string>();

src/bot-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
746746
await this.onVote(session, vote);
747747
const update = new Update({
748748
id: new URL(
749-
`#update-votes/${Date.now()}`,
749+
`#update-votes/${crypto.randomUUID()}`,
750750
updatedQuestion.id ?? ctx.origin,
751751
),
752752
actor: ctx.getActorUri(this.identifier),

src/session-impl.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ export class SessionImpl<TContextData> implements Session<TContextData> {
265265
let voters: number | null = null;
266266
let endTime: Temporal.Instant | null = null;
267267
if ("class" in options && options.class === Question && "poll" in options) {
268+
if (options.poll.options.length < 2) {
269+
throw new TypeError("At least two options are required in a poll.");
270+
} else if (
271+
new Set(options.poll.options).size != options.poll.options.length
272+
) {
273+
throw new TypeError("Duplicate options are not allowed in a poll.");
274+
} else if (options.poll.options.some((o) => o.trim() === "")) {
275+
throw new TypeError("Poll options cannot be empty.");
276+
}
268277
const pollOptions = options.poll.options.map((option) =>
269278
new Note({
270279
name: option,

0 commit comments

Comments
 (0)