Compare commits
3 Commits
66507cb08f
...
a455fd8ff7
Author | SHA1 | Date | |
---|---|---|---|
a455fd8ff7 | |||
119343c916 | |||
296a490e93 |
@ -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 })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user