fix logs
This commit is contained in:
parent
1350cdc0b1
commit
dd8befa9e0
@ -40,8 +40,8 @@ export function initDiscordBot() {
|
||||
* @param channelId the channel id to log to
|
||||
* @param message the message to log
|
||||
*/
|
||||
export function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) {
|
||||
const channel = DiscordBot.channels.cache.find(c => c.id === channelId);
|
||||
export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) {
|
||||
const channel = await DiscordBot.channels.fetch(channelId);
|
||||
if (channel == undefined) {
|
||||
throw new Error(`Channel "${channelId}" not found`);
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ connectScoreSaberWebSocket({
|
||||
await PlayerService.trackScore(playerScore);
|
||||
await ScoreService.notifyNumberOne(playerScore);
|
||||
},
|
||||
onDisconnect: error => {
|
||||
logToChannel(
|
||||
onDisconnect: async error => {
|
||||
await logToChannel(
|
||||
DiscordChannels.backendLogs,
|
||||
new EmbedBuilder().setDescription(`ScoreSaber websocket disconnected: ${error}`)
|
||||
);
|
||||
|
@ -43,7 +43,7 @@ export class PlayerService {
|
||||
|
||||
// Only notify in production
|
||||
if (isProduction()) {
|
||||
logToChannel(
|
||||
await logToChannel(
|
||||
DiscordChannels.trackedPlayerLogs,
|
||||
new EmbedBuilder()
|
||||
.setTitle("New Player Tracked")
|
||||
|
@ -45,7 +45,7 @@ export class ScoreService {
|
||||
return;
|
||||
}
|
||||
|
||||
logToChannel(
|
||||
await logToChannel(
|
||||
DiscordChannels.numberOneFeed,
|
||||
new EmbedBuilder()
|
||||
.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
|
||||
*/
|
||||
onDisconnect?: (error: WebSocket.ErrorEvent) => void;
|
||||
onDisconnect?: (error?: WebSocket.ErrorEvent) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -48,6 +48,8 @@ export function connectScoreSaberWebSocket({ onMessage, onScore, onDisconnect }:
|
||||
|
||||
websocket.onclose = () => {
|
||||
console.log("Lost connection to the ScoreSaber WebSocket. Attempting to reconnect...");
|
||||
|
||||
onDisconnect && onDisconnect();
|
||||
setTimeout(connectWs, 5000); // Reconnect after 5 seconds
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user