reorder close poll and use message identifier
Compile the repository / compile (pull_request) Successful in 28s Details
Run unit tests / test (pull_request) Successful in 16s Details

This commit is contained in:
kenobi 2023-11-19 18:56:39 +01:00
parent 68546b0b50
commit 976175242b
1 changed files with 20 additions and 18 deletions

View File

@ -225,29 +225,31 @@ export default class VoteController {
const lastMessage: Message<true> = messages[0] const lastMessage: Message<true> = messages[0]
logger.debug(`Found messages: ${JSON.stringify(messages, null, 2)}`, { guildId, requestId }) if (!isVoteMessage(lastMessage)) {
logger.error(`Found message that is not a vote message, can't proceed`, { guildId, requestId })
logger.debug(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId }) logger.debug(`Found messages: ${JSON.stringify(messages, null, 2)}`, { guildId, requestId })
logger.debug(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId })
}
const votes = (await this.getVotesByEmote(lastMessage, guildId, requestId)) else {
.sort((a, b) => b.count - a.count) const votes = (await this.getVotesByEmote(lastMessage, guildId, requestId))
.sort((a, b) => b.count - a.count)
logger.debug(`votes: ${JSON.stringify(votes, null, 2)}`, { guildId, requestId })
logger.debug(`votes: ${JSON.stringify(votes, null, 2)}`, { guildId, requestId })
logger.info("Deleting vote message")
await lastMessage.delete() logger.info("Deleting vote message")
const event = await this.getOpenEvent(guild, guild.id, requestId) lastMessage.unpin()
if (event && votes?.length > 0) { await lastMessage.delete()
this.updateOpenPollEventWithVoteResults(event, votes, guild, guildId, requestId) const event = await this.getOpenEvent(guild, guild.id, requestId)
this.sendVoteClosedMessage(event, votes[0].movie, guildId, requestId) if (event && votes?.length > 0) {
this.updateOpenPollEventWithVoteResults(event, votes, guild, guildId, requestId)
this.sendVoteClosedMessage(event, votes[0].movie, guildId, requestId)
}
} }
lastMessage.unpin()
} }
/** /**
* gets votes for the movies without the NONE_OF_THAT votes * gets votes for the movies without the NONE_OF_THAT votes
*/ */
public async getVotesByEmote(message: Message, guildId: string, requestId: string): Promise<Vote[]> { public async getVotesByEmote(message: VoteMessage, guildId: string, requestId: string): Promise<Vote[]> {
const votes: Vote[] = [] const votes: Vote[] = []
logger.debug(`Number of items in emotes: ${Object.values(Emotes).length}`, { guildId, requestId }) logger.debug(`Number of items in emotes: ${Object.values(Emotes).length}`, { guildId, requestId })
for (let i = 0; i < Object.keys(Emotes).length / 2; i++) { for (let i = 0; i < Object.keys(Emotes).length / 2; i++) {