diff --git a/bot.js b/bot.js index 7dc25ff..2c30ac6 100644 --- a/bot.js +++ b/bot.js @@ -17,6 +17,7 @@ let defaultConfig = { word: "butt", chance: 20, limit: 10, + syllableCount: 2, ignoredUsers: [] }; @@ -93,7 +94,7 @@ function onMessageHandler (channel, userstate, message, self) { break; case "word": config.word = value; - configurations[messageChannel] = config; + configurations[channel] = config; fs.writeFileSync('buttsbot.config', JSON.stringify(configurations)); client.say(channel, "Word set to " + value); break; @@ -104,7 +105,7 @@ function onMessageHandler (channel, userstate, message, self) { if (value < 0) value = 0; config.chance = parseInt(value); - configurations[messageChannel] = config; + configurations[channel] = config; fs.writeFileSync('buttsbot.config', JSON.stringify(configurations)); client.say(channel, "Chance set to " + value + "%"); } else { @@ -118,7 +119,7 @@ function onMessageHandler (channel, userstate, message, self) { if (!config.ignoredUsers.includes(value)) { console.log(`* ignore: value not already ignored`); config.ignoredUsers.push(value); - configurations[messageChannel] = config; + configurations[channel] = config; fs.writeFileSync('buttsbot.config', JSON.stringify(configurations)); } client.say(channel, "User " + value + " will be ignored from now on."); @@ -135,7 +136,7 @@ function onMessageHandler (channel, userstate, message, self) { let index = config.ignoredUsers.indexOf(value); config.ignoredUsers.splice(index, 1); - configurations[messageChannel] = config; + configurations[channel] = config; fs.writeFileSync('buttsbot.config', JSON.stringify(configurations)); } @@ -147,13 +148,22 @@ function onMessageHandler (channel, userstate, message, self) { case "limit": if (isNumeric(value)) { config.limit = parseInt(value); - configurations[messageChannel] = config; + configurations[channel] = config; fs.writeFileSync('buttsbot.config', JSON.stringify(configurations)); client.say(channel, "Set new limit: 1 butt per " + value + " words"); } else { client.say(channel, "Expected a number, got " + value); } break; + case "syllables": + if (isNumeric(value)) { + config.syllableCount = parseInt(value); + configurations[channel] = config; + fs.writeFileSync('buttsbot.config', JSON.stringify(configurations)); + client.say(channel, "Set required syllables to " + value); + } else { + client.say(channel, "Expected a number, got " + value); + } default: client.say(channel, "Action '" + action + "' not recognized."); } @@ -174,6 +184,16 @@ function onMessageHandler (channel, userstate, message, self) { var words = message.split(' '); var syllables = words.map(syllabify); + var syllableCount = 0; + + syllabify.forEach((s) => { + syllableCount += s.length; + }); + + if (syllableCount < config.syllableCount) { + console.log(`* Message had too few syllables`); + return; + } var buttCount = Math.ceil(words.length / config.limit);