Trivia: Add /trivia lastofficialscore

Requested by @TheMezStrikes
This commit is contained in:
Annika
2021-02-09 10:41:00 -08:00
parent 53b4263fdc
commit 60e063ff01

View File

@@ -117,7 +117,7 @@ interface TriviaData {
leaderboard?: TriviaLeaderboard;
altLeaderboard?: TriviaLeaderboard;
ladder?: TriviaLadder;
history?: TriviaGame[];
history?: (TriviaGame & {scores?: Map<ID, number>})[];
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 = {
`<li><code>/trivia status [player]</code> - lists the player's standings (your own if no player is specified) and the list of players in the current trivia game.</li>` +
`<li><code>/trivia rank [username]</code> - View the rank of the specified user. If none is given, view your own.</li>` +
`<li><code>/trivia history</code> - View a list of the 10 most recently played trivia games.</li>` +
`<li><code>/trivia lastofficialscore</code> - View the scores from the last Trivia game. Intended for bots.</li>` +
`</ul></details>` +
`<details><summary><strong>Leaderboard commands</strong></summary><ul>` +
`<li><code>/trivia ladder</code> - View information about the top 15 users on the Trivia leaderboard.</li>` +