make top pick retain optional during reroll via env var
Some checks failed
Compile the repository / compile (pull_request) Successful in 32s
Run unit tests / test (pull_request) Failing after 40s

This commit is contained in:
kenobi 2023-10-21 14:56:33 +02:00
parent 599243990e
commit e66aebc88c
2 changed files with 20 additions and 13 deletions

View File

@ -31,6 +31,7 @@ export interface Config {
yavin_jellyfin_token: string yavin_jellyfin_token: string
yavin_jellyfin_collection_user: string yavin_jellyfin_collection_user: string
random_movie_count: number random_movie_count: number
reroll_retains_top_picks: boolean
} }
} }
export const config: Config = { export const config: Config = {
@ -71,6 +72,7 @@ export const config: Config = {
yavin_jellyfin_token: process.env.YAVIN_TOKEN ?? "", yavin_jellyfin_token: process.env.YAVIN_TOKEN ?? "",
yavin_jellyfin_collection_user: process.env.YAVIN_COLLECTION_USER ?? "", yavin_jellyfin_collection_user: process.env.YAVIN_COLLECTION_USER ?? "",
jf_user: process.env.JELLYFIN_USER ?? "", jf_user: process.env.JELLYFIN_USER ?? "",
random_movie_count: parseInt(process.env.RANDOM_MOVIE_COUNT ?? "5") ?? 5 random_movie_count: parseInt(process.env.RANDOM_MOVIE_COUNT ?? "5") ?? 5,
reroll_retains_top_picks: process.env.REROLL_RETAIN === "true"
} }
} }

View File

@ -52,7 +52,7 @@ export default class VoteController {
logger.info(`No reroll`, { requestId, guildId }) logger.info(`No reroll`, { requestId, guildId })
else { else {
logger.info('Starting poll reroll', { requestId, guildId }) logger.info('Starting poll reroll', { requestId, guildId })
await this.handleReroll(reactedUponMessage, guild, guild.id, requestId) await this.handleReroll(reactedUponMessage, guild.id, requestId)
logger.info(`Finished handling NONE_OF_THAT vote`, { requestId, guildId }) logger.info(`Finished handling NONE_OF_THAT vote`, { requestId, guildId })
} }
} }
@ -68,20 +68,25 @@ export default class VoteController {
logger.debug(`${vote.movie} : ${vote.count} -> above: ${aboveThreshold}`) logger.debug(`${vote.movie} : ${vote.count} -> above: ${aboveThreshold}`)
return aboveThreshold return aboveThreshold
} }
public async handleReroll(voteMessage: VoteMessage, guild: Guild, 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 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)
const votedOnMovies = voteInfo.votes.filter(this.isAboveThreshold).filter(x => x.emote !== NONE_OF_THAT)
logger.info(`Found ${votedOnMovies.length} with votes`, { requestId, guildId })
// get movies from jellyfin to fill the remaining slots
const newMovieCount: number = config.bot.random_movie_count - votedOnMovies.length
logger.info(`Fetching ${newMovieCount} from jellyfin`)
const newMovies: string[] = await this.yavinJellyfinHandler.getRandomMovieNames(newMovieCount, guildId, requestId)
// merge
const movies: string[] = newMovies.concat(votedOnMovies.map(x => x.movie))
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)
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`)
const newMovies: string[] = await this.yavinJellyfinHandler.getRandomMovieNames(newMovieCount, guildId, requestId)
// merge
movies = newMovies.concat(votedOnMovies.map(x => x.movie))
} else {
// get movies from jellyfin to fill the remaining slots
const newMovieCount: number = config.bot.random_movie_count
logger.info(`Fetching ${newMovieCount} from jellyfin`)
movies = await this.yavinJellyfinHandler.getRandomMovieNames(newMovieCount, guildId, requestId)
}
// 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 })