feat: add trivia category selection and sync trivia fixes

This commit is contained in:
syntaxbullet
2026-01-11 16:08:11 +01:00
parent 7d68652ea5
commit 3a620a84c5
3 changed files with 55 additions and 6 deletions

View File

@@ -66,3 +66,22 @@ export enum LootType {
XP = 'XP',
ITEM = 'ITEM',
}
export enum TriviaCategory {
GENERAL_KNOWLEDGE = 9,
BOOKS = 10,
FILM = 11,
MUSIC = 12,
VIDEO_GAMES = 15,
SCIENCE_NATURE = 17,
COMPUTERS = 18,
MATHEMATICS = 19,
MYTHOLOGY = 20,
SPORTS = 21,
GEOGRAPHY = 22,
HISTORY = 23,
POLITICS = 24,
ART = 25,
ANIMALS = 27,
ANIME_MANGA = 31,
}

View File

@@ -144,7 +144,7 @@ class TriviaService {
/**
* Start a trivia session - deducts entry fee and creates session
*/
async startTrivia(userId: string, username: string): Promise<TriviaSession> {
async startTrivia(userId: string, username: string, categoryId?: number): Promise<TriviaSession> {
// Check cooldown
const cooldownCheck = await this.canPlayTrivia(userId);
if (!cooldownCheck.canPlay) {
@@ -184,9 +184,12 @@ class TriviaService {
});
// Fetch question
const category = config.trivia.categories.length > 0
? config.trivia.categories[Math.floor(Math.random() * config.trivia.categories.length)]
: undefined;
let category = categoryId;
if (!category) {
category = config.trivia.categories.length > 0
? config.trivia.categories[Math.floor(Math.random() * config.trivia.categories.length)]
: undefined;
}
const difficulty = config.trivia.difficulty;
const question = await this.fetchQuestion(category, difficulty);