Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trivia tweaking #632

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Classes/ArtIndexerBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 12 additions & 5 deletions src/Classes/SchedulerBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
)
}
}
}
19 changes: 18 additions & 1 deletion src/Classes/TriviaBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class TriviaBot {
channel?: TextChannel
previousQuestion?: Message

previousAnswers: string[] = []
currentTriviaAnswer: string
constructor(bot: Client) {
this.bot = bot
Expand Down Expand Up @@ -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?
Expand All @@ -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:`
)
}

Expand Down Expand Up @@ -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
Expand Down
Loading