Compare commits

...

3 Commits

Author SHA1 Message Date
a455fd8ff7 message -> messageText
All checks were successful
Compile the repository / compile (pull_request) Successful in 16s
Run unit tests / test (pull_request) Successful in 13s
2023-11-18 18:15:27 +01:00
119343c916 fix comment 2023-11-18 18:15:13 +01:00
296a490e93 rename filter function 2023-11-18 18:14:56 +01:00

View File

@ -63,18 +63,20 @@ export default class VoteController {
}
return await message.delete()
}
public isAboveThreshold(vote: Vote): boolean {
const aboveThreshold = (vote.count - 1) >= 1
logger.debug(`${vote.movie} : ${vote.count} -> above: ${aboveThreshold}`)
return aboveThreshold
public hasAtLeastOneVote(vote: Vote): boolean {
// subtracting the bots initial vote
const overOneVote = (vote.count - 1) >= 1
logger.debug(`${vote.movie} : ${vote.count} -> above: ${overOneVote}`)
return overOneVote
}
public async handleReroll(voteMessage: VoteMessage, guildId: string, requestId: string) {
//get movies that already had votes to give them a second chance
// get the movies currently being voted on, their votes, the eventId and its date
const voteInfo: VoteMessageInfo = await this.parseVoteInfoFromVoteMessage(voteMessage, requestId)
let movies: string[] = Array()
if (config.bot.reroll_retains_top_picks) {
const votedOnMovies = voteInfo.votes.filter(this.isAboveThreshold).filter(x => x.emote !== NONE_OF_THAT)
const votedOnMovies = voteInfo.votes.filter(this.hasAtLeastOneVote).filter(x => x.emote !== NONE_OF_THAT)
logger.info(`Found ${votedOnMovies.length} with votes`, { requestId, guildId })
const newMovieCount: number = config.bot.random_movie_count - votedOnMovies.length
logger.info(`Fetching ${newMovieCount} from jellyfin`)
@ -90,7 +92,7 @@ export default class VoteController {
// create new message
logger.info(`Creating new poll message with new movies: ${movies}`, { requestId, guildId })
const message = this.createVoteMessageText(voteInfo.eventId, voteInfo.eventDate, movies, guildId, requestId)
const messageText = this.createVoteMessageText(voteInfo.eventId, voteInfo.eventDate, movies, guildId, requestId)
const announcementChannel = this.client.getAnnouncementChannelForGuild(guildId)
if (!announcementChannel) {
logger.error(`No announcementChannel found for ${guildId}, can't post poll`)
@ -104,7 +106,7 @@ export default class VoteController {
logger.error(`Error during removeMessage: ${err}`)
}
const sentMessage = await this.sendVoteMessage(message, movies.length, announcementChannel)
const sentMessage = await this.sendVoteMessage(messageText, movies.length, announcementChannel)
sentMessage.pin()
logger.info(`Sent and pinned new poll message`, { requestId, guildId })
}