Replaced timer by a percentage chance / Added option to change the word
This commit is contained in:
parent
b4031b43f9
commit
c566d3e9f3
71
bot.js
71
bot.js
|
|
@ -1,6 +1,5 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const tmi = require('tmi.js');
|
const tmi = require('tmi.js');
|
||||||
const moment = require('moment');
|
|
||||||
|
|
||||||
// Twitch bot options
|
// Twitch bot options
|
||||||
const optsFile = fs.readFileSync('twitch.config');
|
const optsFile = fs.readFileSync('twitch.config');
|
||||||
|
|
@ -16,8 +15,6 @@ let config = JSON.parse(configFile);
|
||||||
|
|
||||||
console.log(`* Startup: Loaded config: ${config}`);
|
console.log(`* Startup: Loaded config: ${config}`);
|
||||||
|
|
||||||
let lastMessageButtified = 0;
|
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
client.on('message', onMessageHandler);
|
client.on('message', onMessageHandler);
|
||||||
client.on('connected', onConnectedHandler);
|
client.on('connected', onConnectedHandler);
|
||||||
|
|
@ -52,13 +49,22 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "config":
|
case "config":
|
||||||
client.say(channel, "Timer: " + config.timer + " - Limit: " + config.limit + " - Ignored Users: " + config.ignoredUsers.join(', '));
|
client.say(channel, "Chance: " + config.chance + "% - Limit: " + config.limit + " - Ignored Users: " + config.ignoredUsers.join(', '));
|
||||||
|
break;
|
||||||
|
case "word":
|
||||||
|
config.word = value;
|
||||||
|
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
||||||
|
client.say(channel, "Word set to " + value);
|
||||||
break;
|
break;
|
||||||
case "timer":
|
case "timer":
|
||||||
if (isNumeric(value)) {
|
if (isNumeric(value)) {
|
||||||
config.timer = parseInt(value)
|
if (value > 100)
|
||||||
|
value = 100;
|
||||||
|
if (value < 0)
|
||||||
|
value = 0;
|
||||||
|
config.chance = parseInt(value);
|
||||||
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
||||||
client.say(channel, "Set new timer to " + value + " seconds.")
|
client.say(channel, "Chance set to " + value + "%");
|
||||||
} else {
|
} else {
|
||||||
client.say(channel, "Expected a number, got " + value);
|
client.say(channel, "Expected a number, got " + value);
|
||||||
}
|
}
|
||||||
|
|
@ -110,55 +116,52 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
console.log(`* buttsbot: User not authorized`);
|
console.log(`* buttsbot: User not authorized`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (trimmedMessage.startsWith("!"))
|
||||||
|
return;
|
||||||
|
|
||||||
if (config.ignoredUsers.includes(userstate['display-name']) || config.ignoredUsers.includes(userstate['username'])) {
|
if (config.ignoredUsers.includes(userstate['display-name']) || config.ignoredUsers.includes(userstate['username'])) {
|
||||||
console.log(`* User ${userstate['username']} is on the ignore list.`);
|
console.log(`* User ${userstate['username']} is on the ignore list.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkDate = moment().subtract(config.timer, 'seconds');
|
var number = Math.random() * 100;
|
||||||
|
if (number <= config.chance) {
|
||||||
if (checkDate < lastMessageButtified)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (trimmedMessage.startsWith("!"))
|
var words = trimmedMessage.split(' ');
|
||||||
return;
|
var syllables = words.map(syllabify);
|
||||||
|
|
||||||
var words = trimmedMessage.split(' ');
|
var buttCount = Math.ceil(words.length / config.limit);
|
||||||
var syllables = words.map(syllabify);
|
|
||||||
|
|
||||||
var buttCount = Math.ceil(words.length / config.limit);
|
var randomNumbersUsed = [];
|
||||||
|
|
||||||
var randomNumbersUsed = [];
|
for (var i = 0; i < buttCount; i++) {
|
||||||
|
|
||||||
for (var i = 0; i < buttCount; i++) {
|
var random = randomIntFromInterval(1, words.length);
|
||||||
|
|
||||||
var random = randomIntFromInterval(1, words.length);
|
while (randomNumbersUsed.includes(random)) random = randomIntFromInterval(1, words.length);
|
||||||
|
|
||||||
while (randomNumbersUsed.includes(random)) random = randomIntFromInterval(1, words.length);
|
randomNumbersUsed.push(random);
|
||||||
|
|
||||||
randomNumbersUsed.push(random);
|
var word = syllables[random - 1];
|
||||||
|
|
||||||
var word = syllables[random - 1];
|
if (word) {
|
||||||
|
var randomSyllable = randomIntFromInterval(1, word.length);
|
||||||
|
|
||||||
if (word) {
|
var firstLetterOfSyllable = word[randomSyllable - 1][0];
|
||||||
var randomSyllable = randomIntFromInterval(1, word.length);
|
|
||||||
|
|
||||||
var firstLetterOfSyllable = word[randomSyllable - 1][0];
|
word[randomSyllable - 1] = firstLetterOfSyllable == firstLetterOfSyllable.toUpperCase() ? config.word.toUpperCase() : config.word;
|
||||||
|
}
|
||||||
word[randomSyllable - 1] = firstLetterOfSyllable == firstLetterOfSyllable.toUpperCase() ? "BUTT" : "butt";
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var newMessage = "";
|
var newMessage = "";
|
||||||
|
|
||||||
syllables.forEach((s) => {
|
syllables.forEach((s) => {
|
||||||
if (s != null)
|
if (s != null)
|
||||||
newMessage += s.join('') + ' ';
|
newMessage += s.join('') + ' ';
|
||||||
});
|
});
|
||||||
|
|
||||||
client.say(channel, newMessage.trim());
|
client.say(channel, newMessage.trim());
|
||||||
|
}
|
||||||
lastMessageButtified = moment();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"timer":120,"limit":10,"ignoredUsers":["StreamElements","Nightbot"]}
|
{"word": "butt","timer":120,"chance":20,"ignoredUsers":["StreamElements","Nightbot"]}
|
||||||
Loading…
Reference in New Issue
Block a user