diff --git a/src/Classes/ArtIndexerBot.ts b/src/Classes/ArtIndexerBot.ts index 1ec5992..9b395b5 100644 --- a/src/Classes/ArtIndexerBot.ts +++ b/src/Classes/ArtIndexerBot.ts @@ -653,7 +653,12 @@ export class ArtIndexerBot { const keys = Object.keys(this.flagship) const projectKey = keys[Math.floor(Math.random() * keys.length)] const projBot = this.flagship[projectKey] - if (projBot && projBot.editionSize > 1 && projBot.projectActive) { + if ( + projBot && + projBot.editionSize > 1 && + projBot.projectActive && + !triviaBot.alreadyAsked(projBot) + ) { triviaBot.askTriviaQuestion(projBot) return } diff --git a/src/Classes/SchedulerBot.ts b/src/Classes/SchedulerBot.ts index 7816ae0..7e1486d 100644 --- a/src/Classes/SchedulerBot.ts +++ b/src/Classes/SchedulerBot.ts @@ -42,10 +42,17 @@ export class ScheduleBot { } ) - // TODO: Uncomment when trivia is ready - // Cron('* * * * *', { timezone: 'America/Chicago', name: 'Trivia' }, () => { - // console.log('Trivia Time!') - // artIndexerBot.askRandomTriviaQuestion() - // }) + const triviaCadence = parseInt(process.env.TRIVIA_CADENCE ?? '0') + + if (triviaCadence > 0) { + Cron( + `0 */${triviaCadence} * * *`, + { timezone: 'America/Chicago', name: 'Trivia' }, + () => { + console.log('Trivia Time!') + artIndexerBot.askRandomTriviaQuestion() + } + ) + } } } diff --git a/src/Classes/TriviaBot.ts b/src/Classes/TriviaBot.ts index a1b3c46..7fd10e5 100644 --- a/src/Classes/TriviaBot.ts +++ b/src/Classes/TriviaBot.ts @@ -16,6 +16,7 @@ export class TriviaBot { channel?: TextChannel previousQuestion?: Message + previousAnswers: string[] = [] currentTriviaAnswer: string constructor(bot: Client) { this.bot = bot @@ -44,9 +45,21 @@ export class TriviaBot { isArtistActiveTriviaAnswer(artist: string): boolean { return artist === this.currentTriviaAnswer } + alreadyAsked(projectBot: ProjectBot): boolean { + return ( + this.previousAnswers.includes(projectBot.projectName) || + this.previousAnswers.includes(projectBot.artistName) + ) + } async askTriviaQuestion(project: ProjectBot) { // List of ideas: + + // TODO: build out trivia hour functionality + // TODO: String replace project name in description with "______" + // TODO: "close one! not quite" on typo + // TODO: trivia info call (maybe restates last question too) + // Phase 2: // TODO: Different triggers? Not just time based - number of sales, LJ cursing, thank grant, etc. // TODO: Trait data type questions? (e.g. "Name a project that has a trait of 'blue'"), Which of these is not a Meridian trait? @@ -55,7 +68,9 @@ export class TriviaBot { if (this.currentTriviaAnswer && this.previousQuestion) { this.previousQuestion.reply( - 'No one got this one! The answer was: ' + this.currentTriviaAnswer + `Looks like no one got this one! The answer was: ${this.currentTriviaAnswer}. + +Next question:` ) } @@ -97,6 +112,8 @@ export class TriviaBot { return } + this.previousAnswers.push(this.currentTriviaAnswer) + this.channel = this.bot.channels?.cache?.get( CHANNEL_BLOCK_TALK ) as TextChannel