Added option to set required syllables

This commit is contained in:
Marco Loewe 2021-09-03 15:58:33 +02:00
parent e6260c08c5
commit 4cdd3af63d

30
bot.js
View File

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