fix previous score
All checks were successful
Deploy Backend / docker (ubuntu-latest) (push) Successful in 41s

This commit is contained in:
Lee 2024-10-28 15:47:41 +00:00
parent ad568ddf5d
commit f156b7f582
3 changed files with 12 additions and 12 deletions

@ -56,15 +56,10 @@ export async function initDiscordBot() {
export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) { export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) {
try { try {
const channel = await client.channels.fetch(channelId); const channel = await client.channels.fetch(channelId);
if (channel == undefined) { if (channel != undefined && channel.isSendable()) {
throw new Error(`Channel "${channelId}" not found`); channel.send({ embeds: [message] });
} }
if (!channel.isSendable()) { } catch {
throw new Error(`Channel "${channelId}" is not sendable`); /* empty */
}
channel.send({ embeds: [message] });
} catch (error) {
console.error(error);
} }
} }

@ -488,6 +488,8 @@ export class ScoreService {
const score = getScoreSaberScoreFromToken(token.score, leaderboard, playerId); const score = getScoreSaberScoreFromToken(token.score, leaderboard, playerId);
if (!score) return undefined; if (!score) return undefined;
console.log("boobs");
// Fetch additional data, previous score, and BeatSaver map concurrently // Fetch additional data, previous score, and BeatSaver map concurrently
const [additionalData, previousScore, beatSaverMap] = await Promise.all([ const [additionalData, previousScore, beatSaverMap] = await Promise.all([
this.getAdditionalScoreData( this.getAdditionalScoreData(
@ -679,7 +681,9 @@ export class ScoreService {
leaderboardId: string, leaderboardId: string,
timestamp: Date timestamp: Date
): Promise<ScoreSaberPreviousScore | undefined> { ): Promise<ScoreSaberPreviousScore | undefined> {
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) { if (scores == null || scores.length == 0) {
return undefined; return undefined;
} }
@ -689,7 +693,7 @@ export class ScoreService {
if (scoreIndex == -1 || score == undefined) { if (scoreIndex == -1 || score == undefined) {
return undefined; return undefined;
} }
const previousScore = scores[scoreIndex - 1]; const previousScore = scores[scoreIndex + 1];
if (previousScore == undefined) { if (previousScore == undefined) {
return undefined; return undefined;
} }

@ -11,5 +11,6 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"jsx": "react", "jsx": "react",
}, "incremental": true
}
} }