feat/40-reroll-on-disinterest #54
|
@ -31,6 +31,7 @@ export interface Config {
|
|||
yavin_jellyfin_token: string
|
||||
yavin_jellyfin_collection_user: string
|
||||
random_movie_count: number
|
||||
reroll_retains_top_picks: boolean
|
||||
}
|
||||
}
|
||||
export const config: Config = {
|
||||
|
@ -71,6 +72,7 @@ export const config: Config = {
|
|||
yavin_jellyfin_token: process.env.YAVIN_TOKEN ?? "",
|
||||
yavin_jellyfin_collection_user: process.env.YAVIN_COLLECTION_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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ export default class VoteController {
|
|||
logger.info(`No reroll`, { requestId, guildId })
|
||||
else {
|
||||
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 })
|
||||
}
|
||||
}
|
||||
|
@ -68,20 +68,25 @@ export default class VoteController {
|
|||
logger.debug(`${vote.movie} : ${vote.count} -> above: ${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
|
||||
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
|
||||
|
||||
logger.info(`Creating new poll message with new movies: ${movies}`, { requestId, guildId })
|
||||
|
|
Loading…
Reference in New Issue