Compare commits
3 Commits
66507cb08f
...
a455fd8ff7
Author | SHA1 | Date |
---|---|---|
kenobi | a455fd8ff7 | |
kenobi | 119343c916 | |
kenobi | 296a490e93 |
|
@ -63,18 +63,20 @@ export default class VoteController {
|
||||||
}
|
}
|
||||||
return await message.delete()
|
return await message.delete()
|
||||||
}
|
}
|
||||||
public isAboveThreshold(vote: Vote): boolean {
|
|
||||||
const aboveThreshold = (vote.count - 1) >= 1
|
public hasAtLeastOneVote(vote: Vote): boolean {
|
||||||
logger.debug(`${vote.movie} : ${vote.count} -> above: ${aboveThreshold}`)
|
// subtracting the bots initial vote
|
||||||
return aboveThreshold
|
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) {
|
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)
|
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.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 })
|
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`)
|
||||||
|
@ -90,7 +92,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 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)
|
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`)
|
||||||
|
@ -104,7 +106,7 @@ export default class VoteController {
|
||||||
logger.error(`Error during removeMessage: ${err}`)
|
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()
|
sentMessage.pin()
|
||||||
logger.info(`Sent and pinned new poll message`, { requestId, guildId })
|
logger.info(`Sent and pinned new poll message`, { requestId, guildId })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue