All of these Nested if Statements can definitely be changed into one level if statements
if (commandList.indexOf('lockChat') !== -1) {
if (lockChat === true) {
bot.lockChat(room)
}
}
if (commandList.indexOf('unlockChat') !== -1) {
if (unlockChat === true) {
bot.unlockChat(room)
}
}
if (commandList.indexOf('setModerated') !== -1) {
if (setModerated === true) {
bot.setModerated(room)
}
}
if (commandList.indexOf('setUnmoderated') !== -1) {
if (setUnmoderated === true) {
bot.setUnmoderated(room)
}
}
so it would look like this when we add the nested if statements to the expression of the first.
if (commandList.indexOf('lockChat') !== -1 && lockChat === true) {
bot.lockChat(room)
}
if (commandList.indexOf('unlockChat') !== -1 && unlockChat === true) {
bot.unlockChat(room)
}
if (commandList.indexOf('setModerated') !== -1 && setModerated === true) {
bot.setModerated(room)
}
if (commandList.indexOf('setUnmoderated') !== -1 && setUnmoderated === true) {
bot.setUnmoderated(room)
}
While we are talking about shortening the if statements or making them cleaner, I assume that
lockChat
unlockChat
setModerated
setUnmoderated
are all boolean values.
If they are you can drop the === true part of those expressions.
I found a little blurb here
if (receivedMessage.indexOf('BET') !== -1 && roomData.turn === player && playerData[player].canBet === true) {
var amount = extractNumbers(receivedMessage)
var localMessages = bet(amount)
for (var i = 0; i < localMessages.length; i++) {
messages.push(localMessages[i])
}
}
that you could eliminate a variable (middle man), amount you only use it once, just use extractNumbers(receivedMessage) inside bet(extractNumbers(receivedMessage)
other than these things, I am not sure that you can clean up those if/else statements, it looks like they are as clean as they can be while still doing what you want them to do.
I am sure that you could smoosh some things into functions
like this
if (receivedMessage.indexOf('CHECK') !== -1 && roomData.turn === player && playerData[player].canCheck === true) { // if both?
var localMessages = check()
for (var i = 0; i < localMessages.length; i++) { // Array holding each to its required values and its outcome? Would solve both problem and allow for similar values
messages.push(localMessages[i])
}
}
if (receivedMessage.indexOf('BET') !== -1 && roomData.turn === player && playerData[player].canBet === true) {
var amount = extractNumbers(receivedMessage)
var localMessages = bet(amount)
for (var i = 0; i < localMessages.length; i++) {
messages.push(localMessages[i])
}
}
These both look like they are doing almost the same thing. once you get the functions running well, post a follow up question and we can take a look at them and see if they are efficient.