Skip to content

Commit

Permalink
Merge pull request #107 from jodrell2000/stableDev
Browse files Browse the repository at this point in the history
Stable dev
  • Loading branch information
jodrell2000 authored Oct 4, 2021
2 parents 1650163 + cd58de5 commit 197f02a
Show file tree
Hide file tree
Showing 19 changed files with 1,460 additions and 1,344 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
DaManagement.sublime-project
DaManagement.sublime-workspace
.env
.idea
.idea
client_secret.json
69 changes: 31 additions & 38 deletions DaManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ const commandFunctions = commandModule( bot );
const videoFunctions = videoModule( bot );

function logMe ( logLevel, message ) {
let theFile = "Main file";
switch ( logLevel ) {
case "error":
console.log( "!!!!!!!!!!! Main File:" + logLevel + "->" + message + "\n" );
console.log( "!!!!!!!!!!! " + theFile + ":" + logLevel + "->" + message + "\n" );
break;
case "warn":
console.log( "+++++++++++ Main File:" + logLevel + "->" + message + "\n" );
console.log( "+++++++++++ " + theFile + ":" + logLevel + "->" + message + "\n" );
break;
case "info":
console.log( "----------- Main File:" + logLevel + "->" + message + "\n" );
console.log( "----------- " + theFile + ":" + logLevel + "->" + message + "\n" );
break;
default:
if ( bot.debug ) {
console.log( "Main File:" + logLevel + "->" + message + "\n" );
console.log( "" + theFile + ":" + logLevel + "->" + message + "\n" );
}
break;
}
Expand Down Expand Up @@ -126,21 +127,7 @@ bot.on( 'registered', function ( data ) {
if ( bootThisUser ) {
userFunctions.bootThisUser( theUserID, bootMessage );
} else {
//if there are 5 dj's on stage and the queue is turned on when a user enters the room
if ( roomDefaults.queueActive === true && userFunctions.howManyDJs() === 5 ) {
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 ) );
}

if ( userFunctions.greetNewuser( theUserID, username, roomFunctions ) ) {
const greetingTimers = roomFunctions.greetingTimer();

greetingTimers[ theUserID ] = setTimeout( function () {
chatFunctions.userGreeting( theUserID, username, roomFunctions )

// remove timeout function from the list of timeout functions
delete greetingTimers[ theUserID ];
}, 3 * 1000 );
}
chatFunctions.userGreeting( data, theUserID, username, roomFunctions, userFunctions )
}
} );

Expand Down Expand Up @@ -169,24 +156,23 @@ bot.on( 'roomChanged', function ( data ) {

}
catch ( err ) {
logMe( 'info', 'unable to join the room the room due to err: ' + err.toString() );
logMe( 'error', 'unable to join the room the room due to err: ' + err.toString() );
}
} );

//checks at the beggining of the song
bot.on( 'newsong', function ( data ) {
// bot.speak("entered newsong");

//resets counters and array for vote skipping
songFunctions.resetCheckVotes();
songFunctions.resetVoteCountSkip();
songFunctions.resetVotesLeft( roomDefaults.HowManyVotesToSkip );
songFunctions.resetWhoSnagged();
songFunctions.resetUpVotes();
songFunctions.resetDownVotes();
songFunctions.resetSnagCount();
songFunctions.resetVoteSnagging();

//procedure for getting song tags
//console.info( "data.room.metadata.current_song:" + JSON.stringify( data.room.metadata.current_song ) );
songFunctions.getSongTags( data.room.metadata.current_song )

//set information
Expand All @@ -211,7 +197,7 @@ bot.on( 'newsong', function ( data ) {
}

//check to see if conditions are met for bot's autodjing feature
botFunctions.checkAutoDJing( userFunctions, roomFunctions );
botFunctions.checkAutoDJing( userFunctions );

//if the bot is the only one on stage and they are skipping their songs
//they will stop skipping
Expand Down Expand Up @@ -283,9 +269,10 @@ bot.on( 'newsong', function ( data ) {
//of some event not firing, remake currentDj's array
// data.room.metadata.djs.length is index 0 so add 1 to compare
if ( data.room.metadata.djs.length !== userFunctions.howManyDJs() ) {
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() );
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() );
userFunctions.resetDJs( data ); //reset current djs array
}
console.groupEnd();
} );

//bot gets on stage and starts djing if no song is playing.
Expand Down Expand Up @@ -317,9 +304,8 @@ bot.on( 'speak', function ( data ) {
//checks to see if someone is trying to speak to an afk person or not.
const foundUsernames = userFunctions.checkTextForUsernames( text );

let thisAFKUser;
for ( userLoop = 0; userLoop < foundUsernames.length; userLoop++ ) {
thisAFKUserID = userFunctions.getUserIDFromUsername( foundUsernames[ userLoop ] );
for ( let userLoop = 0; userLoop < foundUsernames.length; userLoop++ ) {
let thisAFKUserID = userFunctions.getUserIDFromUsername( foundUsernames[ userLoop ] );
if ( userFunctions.isUserAFK( thisAFKUserID ) && !userFunctions.isThisTheBot( theUserID ) === true ) {
userFunctions.sendUserIsAFKMessage( data, thisAFKUserID, chatFunctions );
}
Expand All @@ -341,14 +327,14 @@ bot.on( 'update_votes', function ( data ) {

//this is for /autosnag, automatically adds songs that get over the awesome threshold
if ( botDefaults.autoSnag === true && songFunctions.snagSong() === false && songFunctions.upVotes() >= botDefaults.howManyVotes && songFunctions.ALLREADYCALLED() === false ) {
songFunctions.voteSnagged();
songFunctions.songSnagged();
botFunctions.checkAndAddToPlaylist( songFunctions );
}
} )

//checks who added a song and updates their position on the afk list.
bot.on( 'snagged', function ( data ) {
songFunctions.voteSnagged();
songFunctions.incrementSnagCount();
userFunctions.updateUserLastSnagged( data.userid ); //update the afk position of people who add a song to their queue
} )

Expand All @@ -357,21 +343,27 @@ bot.on( 'add_dj', function ( data ) {
let OKToDJ;
let theMessage;
const theUserID = data.user[ 0 ].userid;
const totalPlayCount = userFunctions.getDJTotalPlayCount( theUserID );

[ OKToDJ, theMessage ] = userFunctions.checkOKToDJ( theUserID, roomFunctions );

if ( !OKToDJ ) {
bot.remDj( theUserID );
userFunctions.incrementSpamCounter( theUserID );
chatFunctions.botSpeak( data, theMessage );
chatFunctions.botSpeak( theMessage, data );
}

//sets dj's current songcount to zero when they enter the stage.
//unless they used the refresh command, in which case its set to
//what it was before they left the room
userFunctions.setDJCurrentPlayCount( theUserID, userFunctions.getUsersRefreshCurrentPlayCount[ theUserID ] );
userFunctions.setDJTotalPlayCount( theUserID, userFunctions.getUsersRefreshTotalPlayCount[ theUserID ] );

//keep the total playcount as it is, unless they've refreshed
if ( totalPlayCount !== undefined ) {
userFunctions.setDJTotalPlayCount( theUserID, totalPlayCount );
} else {
userFunctions.setDJTotalPlayCount( theUserID, userFunctions.getUsersRefreshTotalPlayCount[ theUserID ] );
}
//updates the afk position of the person who joins the stage.
userFunctions.updateUserJoinedStage( theUserID );

Expand All @@ -388,7 +380,7 @@ bot.on( 'add_dj', function ( data ) {
}

//check to see if conditions are met for bot's autodjing feature
botFunctions.checkAutoDJing( userFunctions, roomFunctions );
botFunctions.checkAutoDJing( userFunctions );
} );

//checks when a dj leaves the stage
Expand Down Expand Up @@ -420,14 +412,14 @@ bot.on( 'rem_dj', function ( data ) {
userFunctions.warnMeCall( roomFunctions );

//check to see if conditions are met for bot's autodjing feature
botFunctions.checkAutoDJing( userFunctions, roomFunctions );
botFunctions.checkAutoDJing( userFunctions );

//takes a user off the escort list if they leave the stage.
userFunctions.removeEscortMeFromUser( theUserID );
} );

bot.on( 'update_user', function ( data ) {
userFunctions.updateUser( data, roomFunctions );
userFunctions.updateUser( data );
} )

//updates the moderator list when a moderator is added.
Expand All @@ -450,15 +442,16 @@ bot.on( 'deregistered', function ( data ) {

//activates at the end of a song.
bot.on( 'endsong', function ( data ) {
songFunctions.grabSongStats();
const djID = data.room.metadata.current_dj;

//bot says song stats for each song
chatFunctions.readSongStats( data, songFunctions, botFunctions )

userFunctions.incrementDJPlayCount( djID );

// check the playlimit and remove the current DJ if they've reached it
userFunctions.removeDJsOverPlaylimit( data, chatFunctions, djID );

//bot says song stats for each song
chatFunctions.readSongStats( data, songFunctions, botFunctions )

roomFunctions.escortDJsDown( data, djID, botFunctions, userFunctions, chatFunctions );
} );
2 changes: 1 addition & 1 deletion bin/test_allowed_regions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let {
} = videoFunctions(null);

const dummyChat = {
botSpeak: (data, msg) => console.log(msg),
botSpeak: (msg, data) => console.log(msg),
};

console.log("-test 1");
Expand Down
6 changes: 3 additions & 3 deletions chatBot.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let authModule = require("./authChat.js");
let authModule = require( './auth.js' );
let Bot = require("ttapi");
let bot = new Bot(authModule.AUTH, authModule.USERID, authModule.ROOMID);

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

bot.debug = true;
bot.debug = false;

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

bot.on("speak", function (data) {
if (botFunctions.wasThisACommand(data)) {
botFunctions.newParseCommands(data);
botFunctions.parseCommands(data);
}
});

Expand Down
83 changes: 52 additions & 31 deletions chatbot/botModule.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,102 @@
let responseModule = require("../chatbot/responseModule.js");
let responseModule = require( "../chatbot/responseModule.js" );

let chatModule = require("../chatbot/chatModule.js");
let chatModule = require( "../chatbot/chatModule.js" );

const availableCommands = {};
const moderatorCommands = {};

const botModule = (bot) => {
const responder = chatModule(bot);
const ignoreCommands = [ '/me ' ];

availableCommands.hello = (data) => { responder.sayHello(data); }
const botModule = ( bot ) => {
const responder = chatModule( bot );

availableCommands.hello = ( data ) => {
responder.sayHello( data );
}
availableCommands.hello.help = "'/hello': Reply to the sender with a Hello! Likely used to test if the Bot is working";

availableCommands.list = (data) => { responder.saySomething(data, "Available commands are: " + listCommands()); }
availableCommands.list = ( data ) => {
responder.saySomething( data, "Available commands are: " + listCommands() );
}
availableCommands.list.help = "'/list': Lists all available commands";

availableCommands.help = (data, command) => { displayHelp(data, command); }
availableCommands.help = ( data, command ) => {
displayHelp( data, command );
}
availableCommands.help.argumentCount = 1;
availableCommands.help.help = "/help [command] Display how to use an individual command";

moderatorCommands.queue = (data) => { responder.saySomething(data, "This would be a queue in he actual bot", true); }
moderatorCommands.queue = ( data ) => {
responder.saySomething( data, "This would be a queue in he actual bot", true );
}
moderatorCommands.queue.help = "/queue Command that always responds in public";

const allCommands = {
...availableCommands,
...moderatorCommands
}

function displayHelp(data, command) {
if ( command[0] === undefined ) { command = "help" }
if ( allCommands[command] === undefined ) {
responder.saySomething( data, "That command desn't exist. Try /list to find the available commands");
function displayHelp( data, command ) {
if ( command[ 0 ] === undefined ) {
command = "help"
}
if ( allCommands[ command ] === undefined ) {
responder.saySomething( data, "That command desn't exist. Try /list to find the available commands" );
} else {
responder.saySomething(data, allCommands[command].help);
responder.saySomething( data, allCommands[ command ].help );
}
}

function listCommands() {
return Object.keys(allCommands);
return Object.keys( allCommands );
}

return {
tikTok: () => {
switch (responseModule.responseCount % 2) {
switch ( responseModule.responseCount % 2 ) {
case 0:
responder.saySomething("tik");
responder.saySomething( "tik" );
break;
default:
responder.saySomething("tok");
responder.saySomething( "tok" );
}
},

wasThisACommand: function (data) {
wasThisACommand: function( data ) {
let text = data.text;
let commandIdentifier = '!';

// was this on the ignore list
for ( let ignoreLoop = 0; ignoreLoop < ignoreCommands.length; ignoreLoop++ ) {
if ( text.match( ignoreCommands[ ignoreLoop ] ) ) {
return false;
}
}

// check if this was a command
if (text.match(/^\|/)) {
const commandString = "^" + commandIdentifier;
if ( text.match( commandString ) ) {
return true;
}
},

getCommandAndArguments: function(text) {
const [sentCommand, ...args] = text.split(" ");
let theCommand = sentCommand.substring(1, sentCommand.length)
const commandObj = allCommands[theCommand];
if (commandObj) {
return [commandObj, args];
getCommandAndArguments: function( text ) {
const [ sentCommand, ...args ] = text.split( " " );
let theCommand = sentCommand.substring( 1, sentCommand.length )
const commandObj = allCommands[ theCommand ];
if ( commandObj ) {
return [ commandObj, args ];
} else {
return [null, null];
return [ null, null ];
}
},

newParseCommands: function(data, userFunctions) {
const [command, args] = this.getCommandAndArguments(data.text);
if (command) {
command.call(null, data, args);
parseCommands: function( data ) {
const [ command, args ] = this.getCommandAndArguments( data.text );
if ( command ) {
command.call( null, data, args );
} else {
bot.speak(data, "Sorry, that's not a command I recognise. Try /list to find out more.");
bot.speak( data, "Sorry, that's not a command I recognise. Try /list to find out more." );
}
},
};
Expand Down
Loading

0 comments on commit 197f02a

Please sign in to comment.