@@ -5,7 +5,7 @@ const { Client } = require('tmi.js'),
55 { parse } = require ( 'json2csv' ) ,
66 fs = require ( 'node:fs' ) ,
77 { clientId, identity, channels } = require ( './config.json' ) ,
8- { getCurrentDatetime } = require ( './function.js' ) ;
8+ { getCurrentDatetime, randomColor } = require ( './function.js' ) ;
99
1010const oauth = {
1111 options : {
@@ -82,6 +82,11 @@ class MobBot {
8282 } ;
8383
8484 liveNotif ( message , client , language , gD , axios ) {
85+ if ( gD == undefined || axios == undefined ) {
86+ console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] Error function liveNotif() : GUID = ${ gD } and/or AXIOS = ${ axios } ` ) ;
87+ return ;
88+ } ;
89+
8590 let guidDot = gD ,
8691 channelTwitch = [ 'twitch' , '🎦-fox-stream-🎦' ] ,
8792 guid = '' ,
@@ -111,7 +116,7 @@ class MobBot {
111116 'type' : 'rich' ,
112117 'title' : `Live de ${ axios . data . data [ 0 ] . user_name } ` ,
113118 'description' : `${ language . descLiveSt } ${ axios . data . data [ 0 ] . user_name } ${ language . descLiveNd } ` ,
114- 'color' : 0x4d04bb ,
119+ 'color' : randomColor ( ) ,
115120 'fields' : [ {
116121 'name' : axios . data . data [ 0 ] . game_name ,
117122 'value' : axios . data . data [ 0 ] . title
@@ -137,7 +142,7 @@ class MobBot {
137142 'url' : `https://twitch.tv/${ axios . data . data [ 0 ] . user_login } `
138143 } ]
139144 } )
140- . catch ( err => { console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] Error livenotif ${ err } ` ) ; } ) ;
145+ . catch ( err => { console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] Error message liveNotif() ${ err } ` ) ; } ) ;
141146 } ;
142147
143148 client . user . setPresence ( {
@@ -152,6 +157,62 @@ class MobBot {
152157 console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] ${ channelTwitch } ` ) ;
153158 } ;
154159
160+ async videoNotif ( message , client , language ) {
161+ let fe = await fetch ( `https://www.youtube.com/feeds/videos.xml?channel_id=UCreItrEewfO6IPZYPu4C7pA` )
162+ . catch ( err => { console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] Error GET AXIOS ${ err } ` ) ; } ) ,
163+ fetched = await fe . text ( ) ,
164+ channelYoutube = [ 'youtube' ] ,
165+ video = [ ] ,
166+ urI ,
167+ title ,
168+ thumbnail ,
169+ descp ;
170+
171+ try {
172+ video = fetched . split ( new RegExp ( `(\:[^.]*\<\/)` , 'giu' ) ) ;
173+ urI = video [ 3 ] . split ( new RegExp ( `(\<[^.]*?\>)` , 'giu' ) ) [ 10 ] ;
174+ title = video [ 3 ] . split ( new RegExp ( `(\<[^.]*?\>)` , 'giu' ) ) [ 18 ] . slice ( 0 , - 2 ) ;
175+ thumbnail = video [ 6 ] . split ( new RegExp ( `(\"[^.]*?\")` , 'giu' ) ) [ 8 ] ;
176+ descp = video [ 6 ] . split ( new RegExp ( `(\"[^.]*?\")` , 'giu' ) ) [ 12 ] . split ( new RegExp ( `(\>[^.]*?\:)` , 'giu' ) ) [ 3 ] . slice ( 1 , - 9 ) ;
177+ } catch ( err ) {
178+ console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] Can't get video's information : ` , err ) ;
179+ } ;
180+
181+ for ( let chan in channelYoutube ) {
182+ var channelSend = client . channels . cache . find ( channel => channel . name == channelYoutube [ chan ] ) ;
183+ if ( channelSend . id == undefined ) break ;
184+
185+ client . channels . cache
186+ . get ( channelSend . id )
187+ . send ( {
188+ 'channel_id' : channelSend . id ,
189+ 'content' : '<@&1071049081910210661>' ,
190+ 'tts' : false ,
191+ 'embeds' : [ {
192+ 'type' : 'rich' ,
193+ 'title' : title ,
194+ 'description' : descp ,
195+ 'color' : randomColor ( ) ,
196+ 'image' : {
197+ 'url' : thumbnail ,
198+ 'proxy_url' : `https://www.youtube.com/watch?v=${ urI } `
199+ } ,
200+ 'thumbnail' : {
201+ 'url' : `https://yt3.ggpht.com/SeggshbVSGnz8KFWP-KsS6pQyYpc-BRNc_OxvJH_ilwuLgKEo7bxtxoP1yooIH2ELiq7hTGM=s600-c-k-c0x00ffffff-no-rj-rp-mo` ,
202+ 'proxy_url' : `https://www.youtube.com/watch?v=${ urI } `
203+ } ,
204+ 'author' : {
205+ 'name' : 'Les Lives de daftmob' ,
206+ 'url' : `https://www.youtube.com/watch?v=${ urI } ` ,
207+ 'icon_url' : client . user . avatarURL ( { format : 'png' , dynamic : true , size : 1024 } )
208+ } ,
209+ 'url' : `https://www.youtube.com/watch?v=${ urI } `
210+ } ]
211+ } )
212+ . catch ( err => { console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] Error message videoNotif() ${ err } ` ) ; } ) ;
213+ } ;
214+ } ;
215+
155216 onConnectedHandler ( addr , port ) { console . log ( `* Connected to ${ addr } :${ port } *` ) ; } ;
156217} ;
157218
0 commit comments