fix logs
All checks were successful
Deploy Backend / deploy (push) Successful in 4m17s
Deploy Website / deploy (push) Successful in 5m36s

This commit is contained in:
Lee 2024-10-17 19:02:32 +01:00
parent 1350cdc0b1
commit dd8befa9e0
5 changed files with 9 additions and 7 deletions

@ -40,8 +40,8 @@ export function initDiscordBot() {
* @param channelId the channel id to log to * @param channelId the channel id to log to
* @param message the message to log * @param message the message to log
*/ */
export function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) { export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) {
const channel = DiscordBot.channels.cache.find(c => c.id === channelId); const channel = await DiscordBot.channels.fetch(channelId);
if (channel == undefined) { if (channel == undefined) {
throw new Error(`Channel "${channelId}" not found`); throw new Error(`Channel "${channelId}" not found`);
} }

@ -42,8 +42,8 @@ connectScoreSaberWebSocket({
await PlayerService.trackScore(playerScore); await PlayerService.trackScore(playerScore);
await ScoreService.notifyNumberOne(playerScore); await ScoreService.notifyNumberOne(playerScore);
}, },
onDisconnect: error => { onDisconnect: async error => {
logToChannel( await logToChannel(
DiscordChannels.backendLogs, DiscordChannels.backendLogs,
new EmbedBuilder().setDescription(`ScoreSaber websocket disconnected: ${error}`) new EmbedBuilder().setDescription(`ScoreSaber websocket disconnected: ${error}`)
); );

@ -43,7 +43,7 @@ export class PlayerService {
// Only notify in production // Only notify in production
if (isProduction()) { if (isProduction()) {
logToChannel( await logToChannel(
DiscordChannels.trackedPlayerLogs, DiscordChannels.trackedPlayerLogs,
new EmbedBuilder() new EmbedBuilder()
.setTitle("New Player Tracked") .setTitle("New Player Tracked")

@ -45,7 +45,7 @@ export class ScoreService {
return; return;
} }
logToChannel( await logToChannel(
DiscordChannels.numberOneFeed, DiscordChannels.numberOneFeed,
new EmbedBuilder() new EmbedBuilder()
.setTitle(`${player.name} set a #1 on ${leaderboard.songName} ${leaderboard.songSubName}`) .setTitle(`${player.name} set a #1 on ${leaderboard.songName} ${leaderboard.songSubName}`)

@ -21,7 +21,7 @@ type ScoresaberSocket = {
* *
* @param error the error that caused the connection to close * @param error the error that caused the connection to close
*/ */
onDisconnect?: (error: WebSocket.ErrorEvent) => void; onDisconnect?: (error?: WebSocket.ErrorEvent) => void;
}; };
/** /**
@ -48,6 +48,8 @@ export function connectScoreSaberWebSocket({ onMessage, onScore, onDisconnect }:
websocket.onclose = () => { websocket.onclose = () => {
console.log("Lost connection to the ScoreSaber WebSocket. Attempting to reconnect..."); console.log("Lost connection to the ScoreSaber WebSocket. Attempting to reconnect...");
onDisconnect && onDisconnect();
setTimeout(connectWs, 5000); // Reconnect after 5 seconds setTimeout(connectWs, 5000); // Reconnect after 5 seconds
}; };