Compare commits
No commits in common. "976175242b3b619948c0af720d0e15cdddac8c51" and "ca99987a20baeceda27cb5e206bff42a54f31b04" have entirely different histories.
976175242b
...
ca99987a20
@ -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<true> & { readonly __brand: 'voteend' }
|
export type VoteEndMessage = Message & { readonly __brand: 'vote' }
|
||||||
export type AnnouncementMessage = Message<true> & { readonly __brand: 'announcement' }
|
export type AnnouncementMessage = Message & { readonly __brand: 'announcement' }
|
||||||
export type VoteMessage = Message<true> & { readonly __brand: 'vote' }
|
export type VoteMessage = Message & { readonly __brand: 'voteend' }
|
||||||
|
|
||||||
export type KnownDiscordMessage = VoteMessage | VoteEndMessage | AnnouncementMessage
|
export type DiscordMessage = 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,31 +225,29 @@ export default class VoteController {
|
|||||||
|
|
||||||
const lastMessage: Message<true> = messages[0]
|
const lastMessage: Message<true> = messages[0]
|
||||||
|
|
||||||
if (!isVoteMessage(lastMessage)) {
|
logger.debug(`Found messages: ${JSON.stringify(messages, null, 2)}`, { guildId, requestId })
|
||||||
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(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId })
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId })
|
||||||
|
|
||||||
logger.info("Deleting vote message")
|
|
||||||
lastMessage.unpin()
|
const votes = (await this.getVotesByEmote(lastMessage, guildId, requestId))
|
||||||
await lastMessage.delete()
|
.sort((a, b) => b.count - a.count)
|
||||||
const event = await this.getOpenEvent(guild, guild.id, requestId)
|
|
||||||
if (event && votes?.length > 0) {
|
logger.debug(`votes: ${JSON.stringify(votes, null, 2)}`, { guildId, requestId })
|
||||||
this.updateOpenPollEventWithVoteResults(event, votes, guild, guildId, requestId)
|
|
||||||
this.sendVoteClosedMessage(event, votes[0].movie, guildId, requestId)
|
logger.info("Deleting vote message")
|
||||||
}
|
await lastMessage.delete()
|
||||||
|
const event = await this.getOpenEvent(guild, guild.id, 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: VoteMessage, guildId: string, requestId: string): Promise<Vote[]> {
|
public async getVotesByEmote(message: Message, 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,7 +3,6 @@ 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'
|
||||||
@ -90,10 +89,8 @@ 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