@@ -35,19 +35,20 @@ const commandFunctions = commandModule( bot );
3535const videoFunctions = videoModule ( bot ) ;
3636
3737function logMe ( logLevel , message ) {
38+ let theFile = "Main file" ;
3839 switch ( logLevel ) {
3940 case "error" :
40- console . log ( "!!!!!!!!!!! Main File :" + logLevel + "->" + message + "\n" ) ;
41+ console . log ( "!!!!!!!!!!! " + theFile + " :" + logLevel + "->" + message + "\n" ) ;
4142 break ;
4243 case "warn" :
43- console . log ( "+++++++++++ Main File :" + logLevel + "->" + message + "\n" ) ;
44+ console . log ( "+++++++++++ " + theFile + " :" + logLevel + "->" + message + "\n" ) ;
4445 break ;
4546 case "info" :
46- console . log ( "----------- Main File :" + logLevel + "->" + message + "\n" ) ;
47+ console . log ( "----------- " + theFile + " :" + logLevel + "->" + message + "\n" ) ;
4748 break ;
4849 default :
4950 if ( bot . debug ) {
50- console . log ( "Main File :" + logLevel + "->" + message + "\n" ) ;
51+ console . log ( "" + theFile + " :" + logLevel + "->" + message + "\n" ) ;
5152 }
5253 break ;
5354 }
@@ -126,21 +127,7 @@ bot.on( 'registered', function ( data ) {
126127 if ( bootThisUser ) {
127128 userFunctions . bootThisUser ( theUserID , bootMessage ) ;
128129 } else {
129- //if there are 5 dj's on stage and the queue is turned on when a user enters the room
130- if ( roomDefaults . queueActive === true && userFunctions . howManyDJs ( ) === 5 ) {
131- bot . pm ( 'The queue is currently active. To add yourself to the queue type /addme. To remove yourself from the queue type /removeme.' , userFunctions . getUsername ( theUserID ) ) ;
132- }
133-
134- if ( userFunctions . greetNewuser ( theUserID , username , roomFunctions ) ) {
135- const greetingTimers = roomFunctions . greetingTimer ( ) ;
136-
137- greetingTimers [ theUserID ] = setTimeout ( function ( ) {
138- chatFunctions . userGreeting ( theUserID , username , roomFunctions )
139-
140- // remove timeout function from the list of timeout functions
141- delete greetingTimers [ theUserID ] ;
142- } , 3 * 1000 ) ;
143- }
130+ chatFunctions . userGreeting ( data , theUserID , username , roomFunctions , userFunctions )
144131 }
145132} ) ;
146133
@@ -169,24 +156,23 @@ bot.on( 'roomChanged', function ( data ) {
169156
170157 }
171158 catch ( err ) {
172- logMe ( 'info ' , 'unable to join the room the room due to err: ' + err . toString ( ) ) ;
159+ logMe ( 'error ' , 'unable to join the room the room due to err: ' + err . toString ( ) ) ;
173160 }
174161} ) ;
175162
176163//checks at the beggining of the song
177164bot . on ( 'newsong' , function ( data ) {
178- // bot.speak("entered newsong");
179-
180165 //resets counters and array for vote skipping
181166 songFunctions . resetCheckVotes ( ) ;
182167 songFunctions . resetVoteCountSkip ( ) ;
183168 songFunctions . resetVotesLeft ( roomDefaults . HowManyVotesToSkip ) ;
184- songFunctions . resetWhoSnagged ( ) ;
185169 songFunctions . resetUpVotes ( ) ;
186170 songFunctions . resetDownVotes ( ) ;
171+ songFunctions . resetSnagCount ( ) ;
187172 songFunctions . resetVoteSnagging ( ) ;
188173
189174 //procedure for getting song tags
175+ //console.info( "data.room.metadata.current_song:" + JSON.stringify( data.room.metadata.current_song ) );
190176 songFunctions . getSongTags ( data . room . metadata . current_song )
191177
192178 //set information
@@ -211,7 +197,7 @@ bot.on( 'newsong', function ( data ) {
211197 }
212198
213199 //check to see if conditions are met for bot's autodjing feature
214- botFunctions . checkAutoDJing ( userFunctions , roomFunctions ) ;
200+ botFunctions . checkAutoDJing ( userFunctions ) ;
215201
216202 //if the bot is the only one on stage and they are skipping their songs
217203 //they will stop skipping
@@ -283,9 +269,10 @@ bot.on( 'newsong', function ( data ) {
283269 //of some event not firing, remake currentDj's array
284270 // data.room.metadata.djs.length is index 0 so add 1 to compare
285271 if ( data . room . metadata . djs . length !== userFunctions . howManyDJs ( ) ) {
286- logMe ( 'error' , Date . now ( ) + ' The DJ counts don\'t match...resetting them. Count from data is ' + data . room . metadata . djs . length + ', count from Bot is ' + userFunctions . howManyDJs ( ) ) ;
272+ console . warn ( botFunctions . getFormattedDate ( ) + ' The DJ counts don\'t match...resetting them. Count from data is ' + data . room . metadata . djs . length + ', count from Bot is ' + userFunctions . howManyDJs ( ) ) ;
287273 userFunctions . resetDJs ( data ) ; //reset current djs array
288274 }
275+ console . groupEnd ( ) ;
289276} ) ;
290277
291278//bot gets on stage and starts djing if no song is playing.
@@ -317,9 +304,8 @@ bot.on( 'speak', function ( data ) {
317304 //checks to see if someone is trying to speak to an afk person or not.
318305 const foundUsernames = userFunctions . checkTextForUsernames ( text ) ;
319306
320- let thisAFKUser ;
321- for ( userLoop = 0 ; userLoop < foundUsernames . length ; userLoop ++ ) {
322- thisAFKUserID = userFunctions . getUserIDFromUsername ( foundUsernames [ userLoop ] ) ;
307+ for ( let userLoop = 0 ; userLoop < foundUsernames . length ; userLoop ++ ) {
308+ let thisAFKUserID = userFunctions . getUserIDFromUsername ( foundUsernames [ userLoop ] ) ;
323309 if ( userFunctions . isUserAFK ( thisAFKUserID ) && ! userFunctions . isThisTheBot ( theUserID ) === true ) {
324310 userFunctions . sendUserIsAFKMessage ( data , thisAFKUserID , chatFunctions ) ;
325311 }
@@ -341,14 +327,14 @@ bot.on( 'update_votes', function ( data ) {
341327
342328 //this is for /autosnag, automatically adds songs that get over the awesome threshold
343329 if ( botDefaults . autoSnag === true && songFunctions . snagSong ( ) === false && songFunctions . upVotes ( ) >= botDefaults . howManyVotes && songFunctions . ALLREADYCALLED ( ) === false ) {
344- songFunctions . voteSnagged ( ) ;
330+ songFunctions . songSnagged ( ) ;
345331 botFunctions . checkAndAddToPlaylist ( songFunctions ) ;
346332 }
347333} )
348334
349335//checks who added a song and updates their position on the afk list.
350336bot . on ( 'snagged' , function ( data ) {
351- songFunctions . voteSnagged ( ) ;
337+ songFunctions . incrementSnagCount ( ) ;
352338 userFunctions . updateUserLastSnagged ( data . userid ) ; //update the afk position of people who add a song to their queue
353339} )
354340
@@ -357,21 +343,27 @@ bot.on( 'add_dj', function ( data ) {
357343 let OKToDJ ;
358344 let theMessage ;
359345 const theUserID = data . user [ 0 ] . userid ;
346+ const totalPlayCount = userFunctions . getDJTotalPlayCount ( theUserID ) ;
360347
361348 [ OKToDJ , theMessage ] = userFunctions . checkOKToDJ ( theUserID , roomFunctions ) ;
362349
363350 if ( ! OKToDJ ) {
364351 bot . remDj ( theUserID ) ;
365352 userFunctions . incrementSpamCounter ( theUserID ) ;
366- chatFunctions . botSpeak ( data , theMessage ) ;
353+ chatFunctions . botSpeak ( theMessage , data ) ;
367354 }
368355
369356 //sets dj's current songcount to zero when they enter the stage.
370357 //unless they used the refresh command, in which case its set to
371358 //what it was before they left the room
372359 userFunctions . setDJCurrentPlayCount ( theUserID , userFunctions . getUsersRefreshCurrentPlayCount [ theUserID ] ) ;
373- userFunctions . setDJTotalPlayCount ( theUserID , userFunctions . getUsersRefreshTotalPlayCount [ theUserID ] ) ;
374360
361+ //keep the total playcount as it is, unless they've refreshed
362+ if ( totalPlayCount !== undefined ) {
363+ userFunctions . setDJTotalPlayCount ( theUserID , totalPlayCount ) ;
364+ } else {
365+ userFunctions . setDJTotalPlayCount ( theUserID , userFunctions . getUsersRefreshTotalPlayCount [ theUserID ] ) ;
366+ }
375367 //updates the afk position of the person who joins the stage.
376368 userFunctions . updateUserJoinedStage ( theUserID ) ;
377369
@@ -388,7 +380,7 @@ bot.on( 'add_dj', function ( data ) {
388380 }
389381
390382 //check to see if conditions are met for bot's autodjing feature
391- botFunctions . checkAutoDJing ( userFunctions , roomFunctions ) ;
383+ botFunctions . checkAutoDJing ( userFunctions ) ;
392384} ) ;
393385
394386//checks when a dj leaves the stage
@@ -420,14 +412,14 @@ bot.on( 'rem_dj', function ( data ) {
420412 userFunctions . warnMeCall ( roomFunctions ) ;
421413
422414 //check to see if conditions are met for bot's autodjing feature
423- botFunctions . checkAutoDJing ( userFunctions , roomFunctions ) ;
415+ botFunctions . checkAutoDJing ( userFunctions ) ;
424416
425417 //takes a user off the escort list if they leave the stage.
426418 userFunctions . removeEscortMeFromUser ( theUserID ) ;
427419} ) ;
428420
429421bot . on ( 'update_user' , function ( data ) {
430- userFunctions . updateUser ( data , roomFunctions ) ;
422+ userFunctions . updateUser ( data ) ;
431423} )
432424
433425//updates the moderator list when a moderator is added.
@@ -450,15 +442,16 @@ bot.on( 'deregistered', function ( data ) {
450442
451443//activates at the end of a song.
452444bot . on ( 'endsong' , function ( data ) {
445+ songFunctions . grabSongStats ( ) ;
453446 const djID = data . room . metadata . current_dj ;
454447
448+ //bot says song stats for each song
449+ chatFunctions . readSongStats ( data , songFunctions , botFunctions )
450+
455451 userFunctions . incrementDJPlayCount ( djID ) ;
456452
457453 // check the playlimit and remove the current DJ if they've reached it
458454 userFunctions . removeDJsOverPlaylimit ( data , chatFunctions , djID ) ;
459455
460- //bot says song stats for each song
461- chatFunctions . readSongStats ( data , songFunctions , botFunctions )
462-
463456 roomFunctions . escortDJsDown ( data , djID , botFunctions , userFunctions , chatFunctions ) ;
464457} ) ;
0 commit comments