Skip to content

Commit 88013d1

Browse files
committed
Merge poll and options
1 parent 9f8f654 commit 88013d1

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

src/commands/extend.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,11 @@ export default class ExtendCommand implements MessageCommand {
9999
return "Bruder das ist keine Umfrage ಠ╭╮ಠ";
100100
}
101101

102-
const { poll, options: oldOptions } = dbPoll;
103-
104-
if (!poll.extendable) {
102+
if (!dbPoll.extendable) {
105103
return "Bruder die Umfrage ist nicht erweiterbar (ง'̀-'́)ง";
106104
}
107105

108-
if (oldOptions.length === pollEmbedService.OPTION_LIMIT) {
106+
if (dbPoll.options.length === pollEmbedService.OPTION_LIMIT) {
109107
return "Bruder die Umfrage ist leider schon voll (⚆ ͜ʖ⚆)";
110108
}
111109

@@ -114,7 +112,7 @@ export default class ExtendCommand implements MessageCommand {
114112
return "Bruder da sind keine Antwortmöglichkeiten :c";
115113
}
116114

117-
if (additionalPollOptions.length + oldOptions.length > pollEmbedService.OPTION_LIMIT) {
115+
if (additionalPollOptions.length + dbPoll.options.length > pollEmbedService.OPTION_LIMIT) {
118116
return `Bruder mit deinen Antwortmöglichkeiten wird das Limit von ${pollEmbedService.OPTION_LIMIT} überschritten!`;
119117
}
120118

@@ -125,28 +123,28 @@ export default class ExtendCommand implements MessageCommand {
125123
}
126124

127125
for (const option of additionalPollOptions) {
128-
await pollService.addPollOption(message.author, poll, option);
126+
await pollService.addPollOption(message.author, dbPoll, option);
129127
}
130128

131-
const newPoll = await pollService.findPoll(poll.id);
129+
const newPoll = await pollService.findPoll(dbPoll.id);
132130
if (newPoll === undefined) {
133131
throw new Error("Could not find poll that should have been there.");
134132
}
135133

136-
const pollAuthor = (await message.guild.members.fetch(newPoll.poll.authorId))?.user ?? {
134+
const pollAuthor = (await message.guild.members.fetch(newPoll.authorId))?.user ?? {
137135
username: "<unbekannt>",
138136
iconURL: undefined,
139137
};
140138

141139
const embed = pollEmbedService.buildPollEmbed(
142140
message.channel,
143141
{
144-
question: newPoll.poll.question,
145-
anonymous: newPoll.poll.anonymous,
146-
extendable: newPoll.poll.extendable,
147-
ended: newPoll.poll.ended,
148-
endsAt: newPoll.poll.endsAt ? new Date(newPoll.poll.endsAt) : null,
149-
multipleChoices: newPoll.poll.multipleChoices,
142+
question: newPoll.question,
143+
anonymous: newPoll.anonymous,
144+
extendable: newPoll.extendable,
145+
ended: newPoll.ended,
146+
endsAt: newPoll.endsAt ? new Date(newPoll.endsAt) : null,
147+
multipleChoices: newPoll.multipleChoices,
150148
author: pollAuthor,
151149
},
152150
newPoll.options.map(o => ({
@@ -164,7 +162,7 @@ export default class ExtendCommand implements MessageCommand {
164162
});
165163

166164
for (const i in additionalPollOptions) {
167-
await msg.react(pollEmbedService.EMOJI[oldOptions.length + Number(i)]);
165+
await msg.react(pollEmbedService.EMOJI[dbPoll.options.length + Number(i)]);
168166
}
169167
await message.delete();
170168
}

src/handler/reaction/pollReactionHandler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ export default {
4242
return;
4343
}
4444

45-
const validVoteReactions = dbPoll.poll.multipleChoices ? POLL_EMOJIS : VOTE_EMOJIS;
45+
const validVoteReactions = dbPoll.multipleChoices ? POLL_EMOJIS : VOTE_EMOJIS;
4646
if (!validVoteReactions.includes(reactionName)) {
4747
return;
4848
}
4949

5050
const invokingMember = await message.guild.members.fetch(invoker.id);
5151

52-
if (dbPoll.poll.endsAt === null) {
53-
await pollService.countVote(dbPoll.poll, message, invokingMember, reactionEvent);
52+
if (dbPoll.endsAt === null) {
53+
await pollService.countVote(dbPoll, message, invokingMember, reactionEvent);
5454
return;
5555
}
5656

57-
if (dbPoll.poll.ended) {
57+
if (dbPoll.ended) {
5858
return;
5959
}
60-
await pollService.countDelayedVote(dbPoll.poll, message, invokingMember, reactionEvent);
60+
await pollService.countDelayedVote(dbPoll, message, invokingMember, reactionEvent);
6161
},
6262
} satisfies ReactionHandler;

src/storage/poll.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ export async function addPollOption(
9393
});
9494
}
9595

96-
export type PollWithOptions = {
97-
poll: Poll;
96+
export type PollWithOptions = Poll & {
9897
options: readonly PollOption[];
9998
};
10099

@@ -120,7 +119,7 @@ export async function findPoll(pollId: PollId, ctx = db()): Promise<PollWithOpti
120119
.execute();
121120

122121
return {
123-
poll,
122+
...poll,
124123
options,
125124
};
126125
});
@@ -176,7 +175,7 @@ export async function findPollForEmbedMessage(
176175
.execute();
177176

178177
return {
179-
poll,
178+
...poll,
180179
options,
181180
};
182181
});

0 commit comments

Comments
 (0)