Compare commits

...

2 Commits

Author SHA1 Message Date
e66aebc88c 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
2023-10-21 14:56:33 +02:00
599243990e remove console.logs 2023-10-21 14:56:15 +02:00
6 changed files with 29 additions and 18 deletions

View File

@ -1,6 +1,7 @@
import { ApplicationCommandOptionType } from 'discord.js'
import { Command } from '../structures/command'
import { RunOptions } from '../types/commandTypes'
import { logger } from '../logger'
export default new Command({
name: 'echo',
description: 'Echoes a text',
@ -13,7 +14,7 @@ export default new Command({
}
],
run: async (interaction: RunOptions) => {
console.log('echo called')
logger.info('echo called')
interaction.interaction.reply(interaction.toString())
}
})

View File

@ -2,15 +2,16 @@ import { v4 as uuid } from 'uuid'
import { jellyfinHandler } from "../.."
import { Command } from '../structures/command'
import { RunOptions } from '../types/commandTypes'
import { logger } from '../logger'
export default new Command({
name: 'passwort_reset',
description: 'Ich vergebe dir ein neues Passwort und schicke es dir per DM zu. Kostet auch nix! Versprochen! 😉',
options: [],
run: async (interaction: RunOptions) => {
console.log('PasswortReset called')
logger.info('PasswortReset called')
interaction.interaction.followUp('Yo, ich schick dir eins!')
console.log(JSON.stringify(interaction.interaction.member, null, 2))
logger.info(JSON.stringify(interaction.interaction.member, null, 2))
jellyfinHandler.resetUserPasswort(interaction.interaction.member, uuid())
}
})

View File

@ -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"
}
}

View File

@ -1,6 +1,7 @@
import { Message } from "discord.js"
import { logger } from "../logger"
export const name = 'messageCreate'
export function execute(message: Message) {
console.log(`${JSON.stringify(message)} has been created`)
logger.info(`${JSON.stringify(message)} has been created`)
}

View File

@ -1,10 +1,11 @@
import { CustomError, errorCodes } from "../interfaces"
import { logger } from "../logger"
import { ExtendedClient } from "../structures/client"
export async function sendFailureDM(creatorMessage: string, client: ExtendedClient, creatorId?: string): Promise<void> {
if (!creatorId) throw new CustomError('No creator ID present', errorCodes.no_creator_id)
const creator = await client.users.fetch(creatorId)
console.log(`Creator ${JSON.stringify(creator)}`)
logger.info(`Creator ${JSON.stringify(creator)}`)
if (creator)
if (!creator.dmChannel)
await creator.createDM()

View File

@ -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)
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 })
// 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))
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 })