From f156b7f5821e153d01157dbd743099a018a53465 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 28 Oct 2024 15:47:41 +0000 Subject: [PATCH] fix previous score --- projects/backend/src/bot/bot.ts | 13 ++++--------- projects/backend/src/service/score.service.ts | 8 ++++++-- projects/backend/tsconfig.json | 3 ++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/projects/backend/src/bot/bot.ts b/projects/backend/src/bot/bot.ts index 7f63a9f..70c5839 100644 --- a/projects/backend/src/bot/bot.ts +++ b/projects/backend/src/bot/bot.ts @@ -56,15 +56,10 @@ export async function initDiscordBot() { export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) { try { const channel = await client.channels.fetch(channelId); - if (channel == undefined) { - throw new Error(`Channel "${channelId}" not found`); + if (channel != undefined && channel.isSendable()) { + channel.send({ embeds: [message] }); } - if (!channel.isSendable()) { - throw new Error(`Channel "${channelId}" is not sendable`); - } - - channel.send({ embeds: [message] }); - } catch (error) { - console.error(error); + } catch { + /* empty */ } } diff --git a/projects/backend/src/service/score.service.ts b/projects/backend/src/service/score.service.ts index 0590441..f8e4938 100644 --- a/projects/backend/src/service/score.service.ts +++ b/projects/backend/src/service/score.service.ts @@ -488,6 +488,8 @@ export class ScoreService { const score = getScoreSaberScoreFromToken(token.score, leaderboard, playerId); if (!score) return undefined; + console.log("boobs"); + // Fetch additional data, previous score, and BeatSaver map concurrently const [additionalData, previousScore, beatSaverMap] = await Promise.all([ this.getAdditionalScoreData( @@ -679,7 +681,9 @@ export class ScoreService { leaderboardId: string, timestamp: Date ): Promise { - const scores = await ScoreSaberScoreModel.find({ playerId: playerId, leaderboardId: leaderboardId }); + const scores = await ScoreSaberScoreModel.find({ playerId: playerId, leaderboardId: leaderboardId }).sort({ + timestamp: -1, + }); if (scores == null || scores.length == 0) { return undefined; } @@ -689,7 +693,7 @@ export class ScoreService { if (scoreIndex == -1 || score == undefined) { return undefined; } - const previousScore = scores[scoreIndex - 1]; + const previousScore = scores[scoreIndex + 1]; if (previousScore == undefined) { return undefined; } diff --git a/projects/backend/tsconfig.json b/projects/backend/tsconfig.json index ab4f221..daec0fe 100644 --- a/projects/backend/tsconfig.json +++ b/projects/backend/tsconfig.json @@ -11,5 +11,6 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "jsx": "react", - }, + "incremental": true + } }