diff --git a/server/chat-plugins/trivia/trivia.ts b/server/chat-plugins/trivia/trivia.ts index b158344bdf37..5f613c5db3ef 100644 --- a/server/chat-plugins/trivia/trivia.ts +++ b/server/chat-plugins/trivia/trivia.ts @@ -826,6 +826,7 @@ export class Trivia extends Rooms.RoomGame { const prizes = this.getPrizes(); const [p1, p2, p3] = winners; + if (!p1) return `No winners this game!`; let initialPart = this.room.tr`${Utils.escapeHTML(p1.name)} won the game with a final score of ${p1.player.points}`; if (!this.game.givesPoints) { return `${initialPart}.`; @@ -847,18 +848,25 @@ export class Trivia extends Rooms.RoomGame { getStaffEndMessage(winners: TopPlayer[], mapper: (k: TopPlayer) => string) { let message = ""; - const winnerParts: ((k: TopPlayer) => string)[] = [ - winner => this.room.tr`User ${mapper(winner)} won the game of ` + + if (winners.length) { + const winnerParts: ((k: TopPlayer) => string)[] = [ + winner => this.room.tr`User ${mapper(winner)} won the game of ` + + (this.game.givesPoints ? this.room.tr`ranked ` : this.room.tr`unranked `) + + this.room.tr`${this.game.mode} mode trivia under the ${this.game.category} category with ` + + this.room.tr`a cap of ${this.getDisplayableCap()} ` + + this.room.tr`with ${winner.player.points} points and ` + + this.room.tr`${winner.player.correctAnswers} correct answers`, + winner => this.room.tr` Second place: ${mapper(winner)} (${winner.player.points} points)`, + winner => this.room.tr`, third place: ${mapper(winner)} (${winner.player.points} points)`, + ]; + for (const [i, winner] of winners.entries()) { + message += winnerParts[i](winner); + } + } else { + message = `No participants in the game of ` + (this.game.givesPoints ? this.room.tr`ranked ` : this.room.tr`unranked `) + this.room.tr`${this.game.mode} mode trivia under the ${this.game.category} category with ` + - this.room.tr`a cap of ${this.getDisplayableCap()} ` + - this.room.tr`with ${winner.player.points} points and ` + - this.room.tr`${winner.player.correctAnswers} correct answers`, - winner => this.room.tr` Second place: ${mapper(winner)} (${winner.player.points} points)`, - winner => this.room.tr`, third place: ${mapper(winner)} (${winner.player.points} points)`, - ]; - for (let i = 0; i < winners.length; i++) { - message += winnerParts[i](winners[i]); + this.room.tr`a cap of ${this.getDisplayableCap()}`; } return `${message}`; } @@ -1088,11 +1096,9 @@ export class NumberModeTrivia extends Trivia { ); const points = this.calculatePoints(innerBuffer.length); - let winner = false; + const cap = this.getCap(); + let winner = cap.questions && this.questionNumber >= cap.questions; if (points) { - const cap = this.getCap(); - // We add 1 questionNumber because it starts at 0 - winner = !!cap.questions && this.questionNumber >= cap.questions; for (const userid in this.playerTable) { const player = this.playerTable[userid]; if (player.isCorrect) player.incrementPoints(points, this.questionNumber);