Skip to content

Commit 197f02a

Browse files
authored
Merge pull request #107 from jodrell2000/stableDev
Stable dev
2 parents 1650163 + cd58de5 commit 197f02a

19 files changed

+1460
-1344
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
DaManagement.sublime-project
33
DaManagement.sublime-workspace
44
.env
5-
.idea
5+
.idea
6+
client_secret.json

DaManagement.js

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ const commandFunctions = commandModule( bot );
3535
const videoFunctions = videoModule( bot );
3636

3737
function 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
177164
bot.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.
350336
bot.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

429421
bot.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.
452444
bot.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
} );

bin/test_allowed_regions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let {
1010
} = videoFunctions(null);
1111

1212
const dummyChat = {
13-
botSpeak: (data, msg) => console.log(msg),
13+
botSpeak: (msg, data) => console.log(msg),
1414
};
1515

1616
console.log("-test 1");

chatBot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
let authModule = require("./authChat.js");
1+
let authModule = require( './auth.js' );
22
let Bot = require("ttapi");
33
let bot = new Bot(authModule.AUTH, authModule.USERID, authModule.ROOMID);
44

55
let botModule = require("./chatbot/botModule.js")
66
const botFunctions = botModule(bot);
77

8-
bot.debug = true;
8+
bot.debug = false;
99

1010
bot.roomRegister(authModule.ROOMID, function() {
1111
bot.setAsBot();
@@ -17,7 +17,7 @@ bot.on("newsong", function () {
1717

1818
bot.on("speak", function (data) {
1919
if (botFunctions.wasThisACommand(data)) {
20-
botFunctions.newParseCommands(data);
20+
botFunctions.parseCommands(data);
2121
}
2222
});
2323

chatbot/botModule.js

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,102 @@
1-
let responseModule = require("../chatbot/responseModule.js");
1+
let responseModule = require( "../chatbot/responseModule.js" );
22

3-
let chatModule = require("../chatbot/chatModule.js");
3+
let chatModule = require( "../chatbot/chatModule.js" );
44

55
const availableCommands = {};
66
const moderatorCommands = {};
77

8-
const botModule = (bot) => {
9-
const responder = chatModule(bot);
8+
const ignoreCommands = [ '/me ' ];
109

11-
availableCommands.hello = (data) => { responder.sayHello(data); }
10+
const botModule = ( bot ) => {
11+
const responder = chatModule( bot );
12+
13+
availableCommands.hello = ( data ) => {
14+
responder.sayHello( data );
15+
}
1216
availableCommands.hello.help = "'/hello': Reply to the sender with a Hello! Likely used to test if the Bot is working";
1317

14-
availableCommands.list = (data) => { responder.saySomething(data, "Available commands are: " + listCommands()); }
18+
availableCommands.list = ( data ) => {
19+
responder.saySomething( data, "Available commands are: " + listCommands() );
20+
}
1521
availableCommands.list.help = "'/list': Lists all available commands";
1622

17-
availableCommands.help = (data, command) => { displayHelp(data, command); }
23+
availableCommands.help = ( data, command ) => {
24+
displayHelp( data, command );
25+
}
1826
availableCommands.help.argumentCount = 1;
1927
availableCommands.help.help = "/help [command] Display how to use an individual command";
2028

21-
moderatorCommands.queue = (data) => { responder.saySomething(data, "This would be a queue in he actual bot", true); }
29+
moderatorCommands.queue = ( data ) => {
30+
responder.saySomething( data, "This would be a queue in he actual bot", true );
31+
}
2232
moderatorCommands.queue.help = "/queue Command that always responds in public";
2333

2434
const allCommands = {
2535
...availableCommands,
2636
...moderatorCommands
2737
}
2838

29-
function displayHelp(data, command) {
30-
if ( command[0] === undefined ) { command = "help" }
31-
if ( allCommands[command] === undefined ) {
32-
responder.saySomething( data, "That command desn't exist. Try /list to find the available commands");
39+
function displayHelp( data, command ) {
40+
if ( command[ 0 ] === undefined ) {
41+
command = "help"
42+
}
43+
if ( allCommands[ command ] === undefined ) {
44+
responder.saySomething( data, "That command desn't exist. Try /list to find the available commands" );
3345
} else {
34-
responder.saySomething(data, allCommands[command].help);
46+
responder.saySomething( data, allCommands[ command ].help );
3547
}
3648
}
3749

3850
function listCommands() {
39-
return Object.keys(allCommands);
51+
return Object.keys( allCommands );
4052
}
4153

4254
return {
4355
tikTok: () => {
44-
switch (responseModule.responseCount % 2) {
56+
switch ( responseModule.responseCount % 2 ) {
4557
case 0:
46-
responder.saySomething("tik");
58+
responder.saySomething( "tik" );
4759
break;
4860
default:
49-
responder.saySomething("tok");
61+
responder.saySomething( "tok" );
5062
}
5163
},
5264

53-
wasThisACommand: function (data) {
65+
wasThisACommand: function( data ) {
5466
let text = data.text;
67+
let commandIdentifier = '!';
68+
69+
// was this on the ignore list
70+
for ( let ignoreLoop = 0; ignoreLoop < ignoreCommands.length; ignoreLoop++ ) {
71+
if ( text.match( ignoreCommands[ ignoreLoop ] ) ) {
72+
return false;
73+
}
74+
}
5575

5676
// check if this was a command
57-
if (text.match(/^\|/)) {
77+
const commandString = "^" + commandIdentifier;
78+
if ( text.match( commandString ) ) {
5879
return true;
5980
}
6081
},
6182

62-
getCommandAndArguments: function(text) {
63-
const [sentCommand, ...args] = text.split(" ");
64-
let theCommand = sentCommand.substring(1, sentCommand.length)
65-
const commandObj = allCommands[theCommand];
66-
if (commandObj) {
67-
return [commandObj, args];
83+
getCommandAndArguments: function( text ) {
84+
const [ sentCommand, ...args ] = text.split( " " );
85+
let theCommand = sentCommand.substring( 1, sentCommand.length )
86+
const commandObj = allCommands[ theCommand ];
87+
if ( commandObj ) {
88+
return [ commandObj, args ];
6889
} else {
69-
return [null, null];
90+
return [ null, null ];
7091
}
7192
},
7293

73-
newParseCommands: function(data, userFunctions) {
74-
const [command, args] = this.getCommandAndArguments(data.text);
75-
if (command) {
76-
command.call(null, data, args);
94+
parseCommands: function( data ) {
95+
const [ command, args ] = this.getCommandAndArguments( data.text );
96+
if ( command ) {
97+
command.call( null, data, args );
7798
} else {
78-
bot.speak(data, "Sorry, that's not a command I recognise. Try /list to find out more.");
99+
bot.speak( data, "Sorry, that's not a command I recognise. Try /list to find out more." );
79100
}
80101
},
81102
};

0 commit comments

Comments
 (0)