From 0eba82789dbcead6b931ba9ae95c7baf590ad793 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:23:04 +1100 Subject: [PATCH] Fix bug with YTModule not sending notification --- src/components/CacheServer.ts | 1 + src/modules/YTModule.ts | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/CacheServer.ts b/src/components/CacheServer.ts index 54bd6ef..93b10d5 100644 --- a/src/components/CacheServer.ts +++ b/src/components/CacheServer.ts @@ -32,6 +32,7 @@ export default class CacheServer { cachedResult = await RedisClient.get(key); if (cachedResult) cachedResult = JSON.parse(cachedResult); } + return cachedResult; } public static async set(key:any, value:any, jsonMode:boolean):Promise { if (jsonMode) return await RedisClient.json.set(key, '.', value); diff --git a/src/modules/YTModule.ts b/src/modules/YTModule.ts index d070773..7d44a8b 100644 --- a/src/modules/YTModule.ts +++ b/src/modules/YTModule.ts @@ -23,7 +23,7 @@ export default async(client:TClient)=>{ try { await Undici.request(`https://youtube.googleapis.com/youtube/v3/activities?part=snippet&channelId=${YTChannelID}&maxResults=2&key=${(await TSClient()).youtube}`, { signal: AbortSignal.timeout(10000), - headers: {'User-Agent':`${client.user.username} - YTModule/undici`}, + headers: {'User-Agent':`${client.user.username} - YTModule/undici`} }).then(async resp=>Data = await resp.body.json()); YTChannelName = Data.items[0].snippet.channelTitle; } catch { @@ -33,13 +33,14 @@ export default async(client:TClient)=>{ const getVideoId = (index:number)=>Data.items[index].snippet.thumbnails.default.url.split('/')[4]; const videoUrl = `https://www.youtube.com/watch?v=${getVideoId(0)}`; - const cacheKey = `YTCache:${YTChannelID}`; + const cacheKey = `YTModule:${YTChannelID}`; const cachedVideoId = await CacheServer.get(cacheKey, false); if (!cachedVideoId) { await CacheServer.set(cacheKey, getVideoId(0), false).then(async()=>await CacheServer.expiry(cacheKey, cacheExpiry)); - return; + continue; } if (getVideoId(1) === cachedVideoId) { + Logger.console('log', 'YTModule:DEBUG', `New video uploaded by ${YTChannelName} and notification sent to Discord`) await CacheServer.delete(cacheKey).then(async()=>await CacheServer.set(cacheKey, getVideoId(0), false).then(async()=>await CacheServer.expiry(cacheKey, cacheExpiry))); (client.channels.resolve(DiscordChannelID) as TextChannel).send({ @@ -47,4 +48,4 @@ export default async(client:TClient)=>{ }); } } -}; +}