Compare commits

..

No commits in common. "a455fd8ff7e6b8ffb032fb4aed9389da68ee513b" and "66507cb08fa50ba3a7be28388c55b21227fb2261" have entirely different histories.

View File

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