Compare commits
5 Commits
ca99987a20
...
976175242b
Author | SHA1 | Date | |
---|---|---|---|
976175242b | |||
68546b0b50 | |||
1348abbd48 | |||
fce9091114 | |||
081f3c6201 |
@ -2,11 +2,11 @@ import { Message } from "discord.js";
|
|||||||
|
|
||||||
|
|
||||||
// branded types to differentiate objects of identical Type but different contents
|
// branded types to differentiate objects of identical Type but different contents
|
||||||
export type VoteEndMessage = Message & { readonly __brand: 'vote' }
|
export type VoteEndMessage = Message<true> & { readonly __brand: 'voteend' }
|
||||||
export type AnnouncementMessage = Message & { readonly __brand: 'announcement' }
|
export type AnnouncementMessage = Message<true> & { readonly __brand: 'announcement' }
|
||||||
export type VoteMessage = Message & { readonly __brand: 'voteend' }
|
export type VoteMessage = Message<true> & { readonly __brand: 'vote' }
|
||||||
|
|
||||||
export type DiscordMessage = VoteMessage | VoteEndMessage | AnnouncementMessage
|
export type KnownDiscordMessage = VoteMessage | VoteEndMessage | AnnouncementMessage
|
||||||
|
|
||||||
export function isVoteMessage(message: Message): message is VoteMessage {
|
export function isVoteMessage(message: Message): message is VoteMessage {
|
||||||
return message.cleanContent.includes('[Abstimmung]')
|
return message.cleanContent.includes('[Abstimmung]')
|
||||||
|
@ -225,29 +225,31 @@ export default class VoteController {
|
|||||||
|
|
||||||
const lastMessage: Message<true> = messages[0]
|
const lastMessage: Message<true> = messages[0]
|
||||||
|
|
||||||
|
if (!isVoteMessage(lastMessage)) {
|
||||||
|
logger.error(`Found message that is not a vote message, can't proceed`, { guildId, requestId })
|
||||||
logger.debug(`Found messages: ${JSON.stringify(messages, 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 })
|
logger.debug(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId })
|
||||||
|
}
|
||||||
|
else {
|
||||||
const votes = (await this.getVotesByEmote(lastMessage, guildId, requestId))
|
const votes = (await this.getVotesByEmote(lastMessage, guildId, requestId))
|
||||||
.sort((a, b) => b.count - a.count)
|
.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")
|
logger.info("Deleting vote message")
|
||||||
|
lastMessage.unpin()
|
||||||
await lastMessage.delete()
|
await lastMessage.delete()
|
||||||
const event = await this.getOpenEvent(guild, guild.id, requestId)
|
const event = await this.getOpenEvent(guild, guild.id, requestId)
|
||||||
if (event && votes?.length > 0) {
|
if (event && votes?.length > 0) {
|
||||||
this.updateOpenPollEventWithVoteResults(event, votes, guild, guildId, requestId)
|
this.updateOpenPollEventWithVoteResults(event, votes, guild, guildId, requestId)
|
||||||
this.sendVoteClosedMessage(event, votes[0].movie, 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++) {
|
||||||
|
@ -3,6 +3,7 @@ import VoteController from "../../server/helper/vote.controller"
|
|||||||
import { JellyfinHandler } from "../../server/jellyfin/handler"
|
import { JellyfinHandler } from "../../server/jellyfin/handler"
|
||||||
import { ExtendedClient } from "../../server/structures/client"
|
import { ExtendedClient } from "../../server/structures/client"
|
||||||
import { Emoji, NONE_OF_THAT } from "../../server/constants"
|
import { Emoji, NONE_OF_THAT } from "../../server/constants"
|
||||||
|
import { isVoteMessage } from "../../server/helper/messageIdentifiers"
|
||||||
|
|
||||||
describe('vote controller - none_of_that functions', () => {
|
describe('vote controller - none_of_that functions', () => {
|
||||||
const testEventId = '1234321'
|
const testEventId = '1234321'
|
||||||
@ -89,8 +90,10 @@ describe('vote controller - none_of_that functions', () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isVoteMessage(mockMessage)) {
|
||||||
const result = await votes.getVotesByEmote(mockMessage, 'guildId', 'requestId')
|
const result = await votes.getVotesByEmote(mockMessage, 'guildId', 'requestId')
|
||||||
expect(result.length).toEqual(5)
|
expect(result.length).toEqual(5)
|
||||||
expect(result).toEqual(votesList.filter(x => x.movie != NONE_OF_THAT))
|
expect(result).toEqual(votesList.filter(x => x.movie != NONE_OF_THAT))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user