2024-10-16 07:31:52 +01:00
|
|
|
import ScoreSaberPlayerScoreToken from "@ssr/common/types/token/scoresaber/score-saber-player-score-token";
|
2024-10-16 07:47:52 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2024-10-16 07:31:52 +01:00
|
|
|
// @ts-ignore
|
|
|
|
import { MessageBuilder, Webhook } from "discord-webhook-node";
|
|
|
|
import { Config } from "../common/config";
|
|
|
|
import { formatPp } from "@ssr/common/utils/number-utils";
|
2024-10-16 08:21:27 +01:00
|
|
|
import { isProduction } from "@ssr/common/utils/utils";
|
2024-10-16 07:31:52 +01:00
|
|
|
|
|
|
|
export class ScoreService {
|
2024-10-17 03:08:27 +01:00
|
|
|
/**
|
|
|
|
* Notifies the number one score in Discord.
|
|
|
|
*
|
|
|
|
* @param playerScore the score to notify
|
|
|
|
*/
|
2024-10-16 07:31:52 +01:00
|
|
|
public static async notifyNumberOne(playerScore: ScoreSaberPlayerScoreToken) {
|
2024-10-16 08:21:27 +01:00
|
|
|
// Only notify in production
|
|
|
|
if (!isProduction()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-10-16 07:31:52 +01:00
|
|
|
const { score, leaderboard } = playerScore;
|
|
|
|
const player = score.leaderboardPlayerInfo;
|
|
|
|
|
|
|
|
// Not ranked
|
|
|
|
if (leaderboard.stars <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Not #1 rank
|
|
|
|
if (score.rank !== 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const hook = new Webhook({
|
|
|
|
url: Config.numberOneWebhook,
|
|
|
|
});
|
|
|
|
hook.setUsername("Number One Feed");
|
|
|
|
const embed = new MessageBuilder();
|
|
|
|
embed.setTitle(`${player.name} set a #${score.rank} on ${leaderboard.songName} ${leaderboard.songSubName}`);
|
|
|
|
embed.setDescription(`
|
|
|
|
**Player:** https://ssr.fascinated.cc/player/${player.id}
|
|
|
|
**Leaderboard:** https://ssr.fascinated.cc/leaderboard/${leaderboard.id}
|
|
|
|
**PP:** ${formatPp(score.pp)}
|
|
|
|
`);
|
|
|
|
embed.setThumbnail(leaderboard.coverImage);
|
|
|
|
embed.setColor("#00ff00");
|
|
|
|
await hook.send(embed);
|
|
|
|
}
|
|
|
|
}
|