From 26514b0750af72f4496fee34936d51afb18fd9b8 Mon Sep 17 00:00:00 2001 From: GalvinPython Date: Mon, 15 Sep 2025 09:54:38 +0100 Subject: [PATCH] fix: null channels crashing fetchLatestUploads --- src/events/ready.ts | 4 ++++ src/utils/youtube/fetchLatestUploads.ts | 25 ++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/events/ready.ts b/src/events/ready.ts index aed1b9a..1d15cb6 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -18,6 +18,10 @@ client.once(Events.ClientReady, async (bot) => { // await cronUpdateBotInfo(); // }).start(); + console.log( + `Setting intervals: YouTube - ${config.updateIntervalYouTube}ms, Twitch - ${config.updateIntervalTwitch}ms`, + ); + fetchLatestUploads(); setInterval(fetchLatestUploads, config.updateIntervalYouTube as number); diff --git a/src/utils/youtube/fetchLatestUploads.ts b/src/utils/youtube/fetchLatestUploads.ts index 1dd7c62..954ffd9 100644 --- a/src/utils/youtube/fetchLatestUploads.ts +++ b/src/utils/youtube/fetchLatestUploads.ts @@ -79,19 +79,26 @@ export default async function fetchLatestUploads() { const videoId = playlist.snippet.thumbnails.default.url.split("/")[4]; + if (!channelDict[channelId]) { + console.error( + "Channel ID not found in channelDict:", + channelId, + ); + continue; + } + const requiresUpdate = channelDict[channelId].latestAllId !== videoId; - console.log( - "Channel ID:", - channelId, - "Video ID:", - videoId, - "Requires update?", - requiresUpdate, - ); - if (requiresUpdate) { + console.log( + "Channel ID:", + channelId, + "Video ID:", + videoId, + "Requires update?", + requiresUpdate, + ); const [longVideoId, shortVideoId, streamVideoId] = await Promise.all([ getSinglePlaylistAndReturnVideoData(