Skip to content

Commit

Permalink
Merge pull request #632 from ArtBlocks/trivia-tweaking
Browse files Browse the repository at this point in the history
Trivia tweaking
  • Loading branch information
grantoesterling authored Dec 15, 2023
2 parents 963f57d + f1e8918 commit c8ad51c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
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

0 comments on commit c8ad51c

Please sign in to comment.