mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 04:10:59 -05:00
Fix bug with YTModule not sending notification
This commit is contained in:
parent
e8e1342f21
commit
0eba82789d
@ -32,6 +32,7 @@ export default class CacheServer {
|
|||||||
cachedResult = await RedisClient.get(key);
|
cachedResult = await RedisClient.get(key);
|
||||||
if (cachedResult) cachedResult = JSON.parse(cachedResult);
|
if (cachedResult) cachedResult = JSON.parse(cachedResult);
|
||||||
}
|
}
|
||||||
|
return cachedResult;
|
||||||
}
|
}
|
||||||
public static async set(key:any, value:any, jsonMode:boolean):Promise<any> {
|
public static async set(key:any, value:any, jsonMode:boolean):Promise<any> {
|
||||||
if (jsonMode) return await RedisClient.json.set(key, '.', value);
|
if (jsonMode) return await RedisClient.json.set(key, '.', value);
|
||||||
|
@ -23,7 +23,7 @@ export default async(client:TClient)=>{
|
|||||||
try {
|
try {
|
||||||
await Undici.request(`https://youtube.googleapis.com/youtube/v3/activities?part=snippet&channelId=${YTChannelID}&maxResults=2&key=${(await TSClient()).youtube}`, {
|
await Undici.request(`https://youtube.googleapis.com/youtube/v3/activities?part=snippet&channelId=${YTChannelID}&maxResults=2&key=${(await TSClient()).youtube}`, {
|
||||||
signal: AbortSignal.timeout(10000),
|
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());
|
}).then(async resp=>Data = await resp.body.json());
|
||||||
YTChannelName = Data.items[0].snippet.channelTitle;
|
YTChannelName = Data.items[0].snippet.channelTitle;
|
||||||
} catch {
|
} catch {
|
||||||
@ -33,13 +33,14 @@ export default async(client:TClient)=>{
|
|||||||
|
|
||||||
const getVideoId = (index:number)=>Data.items[index].snippet.thumbnails.default.url.split('/')[4];
|
const getVideoId = (index:number)=>Data.items[index].snippet.thumbnails.default.url.split('/')[4];
|
||||||
const videoUrl = `https://www.youtube.com/watch?v=${getVideoId(0)}`;
|
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);
|
const cachedVideoId = await CacheServer.get(cacheKey, false);
|
||||||
if (!cachedVideoId) {
|
if (!cachedVideoId) {
|
||||||
await CacheServer.set(cacheKey, getVideoId(0), false).then(async()=>await CacheServer.expiry(cacheKey, cacheExpiry));
|
await CacheServer.set(cacheKey, getVideoId(0), false).then(async()=>await CacheServer.expiry(cacheKey, cacheExpiry));
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
if (getVideoId(1) === cachedVideoId) {
|
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)));
|
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({
|
(client.channels.resolve(DiscordChannelID) as TextChannel).send({
|
||||||
@ -47,4 +48,4 @@ export default async(client:TClient)=>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user