1+ const { Discord, Client, Collection, Message, MessageEmbed} = require ( "discord.js" ) ;
2+ const dClient = new Client ( { intents : 32767 } ) ;
3+ dClient . db = require ( "quick.db" ) ;
4+ dClient . request = new ( require ( "rss-parser" ) ) ( ) ;
5+ dClient . config = require ( "./config.js" ) ;
6+
7+ dClient . on ( "ready" , ( ) => {
8+ console . log ( `Started following Youtube [ID] ${ dClient . config . channel_id } ` ) ;
9+ console . log ( `For Support please join https://discord.gg/PrGCCWpDbP` )
10+ handleUploads ( ) ;
11+ } ) ;
12+
13+ function handleUploads ( ) {
14+ if ( dClient . db . fetch ( `postedVideos` ) === null ) dClient . db . set ( `postedVideos` , [ ] ) ;
15+ setInterval ( ( ) => {
16+ dClient . request . parseURL ( `https://www.youtube.com/feeds/videos.xml?channel_id=${ dClient . config . channel_id } ` )
17+ . then ( data => {
18+ if ( dClient . db . fetch ( `postedVideos` ) . includes ( data . items [ 0 ] . link ) ) return ;
19+ else {
20+ dClient . db . set ( `videoData` , data . items [ 0 ] ) ;
21+ dClient . db . push ( "postedVideos" , data . items [ 0 ] . link ) ;
22+ const parsed = dClient . db . fetch ( `videoData` ) ;
23+ const channel = dClient . channels . cache . get ( dClient . config . discord_channel ) ;
24+ if ( ! channel ) return ;
25+ const message = dClient . config . messageText
26+ . replace ( / { a u t h o r } / g, parsed . author )
27+ . replace ( / { u r l } / g, parsed . link ) ;
28+ channel . send ( message ) ;
29+ console . log ( `[YOUTUBE] Sent Video Update to ${ dClient . config . discord_channel } ` )
30+ }
31+ } ) ;
32+ } , dClient . config . refreshInterval ) ;
33+ }
34+
35+ dClient . login ( dClient . config . discordBotToken ) ;
0 commit comments