diff --git a/server/chat-plugins/trivia.ts b/server/chat-plugins/trivia.ts index a47a16a989..7b2c17845a 100644 --- a/server/chat-plugins/trivia.ts +++ b/server/chat-plugins/trivia.ts @@ -117,7 +117,7 @@ interface TriviaData { leaderboard?: TriviaLeaderboard; altLeaderboard?: TriviaLeaderboard; ladder?: TriviaLadder; - history?: TriviaGame[]; + history?: (TriviaGame & {scores?: Map})[]; moveEventQuestions?: boolean; } @@ -851,7 +851,13 @@ export class Trivia extends Rooms.RoomGame { if (!triviaData.history) triviaData.history = []; if (typeof this.game.length === 'number') this.game.length = `${this.game.length} questions`; - triviaData.history.push(this.game); + + const scores = new Map(this.getTopPlayers().map(player => [player.player.id, player.player.points])); + triviaData.history.push({ + ...this.game, + length: typeof this.game.length === 'number' ? `${this.game.length} questions` : this.game.length, + scores, + }); if (triviaData.history.length > 10) triviaData.history.shift(); this.hasModifiedData = true; @@ -2328,6 +2334,18 @@ const triviaCommands: ChatCommands = { }, historyhelp: [`/trivia history - View a list of the 10 most recently played trivia games.`], + lastofficialscore(target, room, user) { + room = this.requireRoom('trivia' as RoomID); + this.runBroadcast(); + + const lastGame = triviaData.history?.[triviaData.history.length - 1]; + if (!lastGame?.scores) throw new Chat.ErrorMessage(`There are no scores recorded for the last Trivia game.`); + + const scores = [...lastGame.scores].map(([userid, score]) => `${userid} (${score})`).join(', '); + this.sendReplyBox(`The scores for the last Trivia game are: ${scores}`); + }, + lastofficialscorehelp: [`/trivia lastofficialscore - View the scores from the last Trivia game. Intended for bots.`], + removepoints: 'addpoints', addpoints(target, room, user, connection, cmd) { room = this.requireRoom('trivia' as RoomID); @@ -2472,6 +2490,7 @@ const triviaCommands: ChatCommands = { `
  • /trivia status [player] - lists the player's standings (your own if no player is specified) and the list of players in the current trivia game.
  • ` + `
  • /trivia rank [username] - View the rank of the specified user. If none is given, view your own.
  • ` + `
  • /trivia history - View a list of the 10 most recently played trivia games.
  • ` + + `
  • /trivia lastofficialscore - View the scores from the last Trivia game. Intended for bots.
  • ` + `` + `
    Leaderboard commands