diff --git a/.gitignore b/.gitignore index eb11e4d..a1baf54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .env twitch.config buttsbot.config - +counter node_modules/ diff --git a/bot.js b/bot.js index e252084..1b989f4 100644 --- a/bot.js +++ b/bot.js @@ -21,7 +21,7 @@ let defaultConfig = { ignoredUsers: [] }; -let messageCounter = []; +let messageCounter = JSON.parse(fs.readFileSync('counter')); // Client client.on('message', onMessageHandler); @@ -194,8 +194,6 @@ function onMessageHandler (channel, userstate, message, self) { // split messages into word array and try to determine syllabes var words = message.split(' '); var syllables = words.map(syllabify); - - console.log(JSON.stringify(syllables)); // calculate syllabe count var syllableCount = 0; @@ -210,23 +208,24 @@ function onMessageHandler (channel, userstate, message, self) { return; } - let counter = []; + var counter = { + total: 0, + converted: 0 + }; if (channel in messageCounter) { + console.log(`* Load counter for ${channel}`); counter = messageCounter[channel]; - } else { - counter['total'] = 0; - counter['converted'] = 0; } - counter['total'] = counter['total']++; + counter.total++; // random chance // TODO: find a better alternative var number = Math.random() * 100; if (number <= config.chance) { - counter['converted'] = counter['converted']++; + counter.converted++; var buttCount = Math.ceil(words.length / config.limit); @@ -261,6 +260,8 @@ function onMessageHandler (channel, userstate, message, self) { client.say(channel, newMessage.trim()); } + console.log(channel + ": " + JSON.stringify(counter)); + messageCounter[channel] = counter; fs.writeFileSync('counter', JSON.stringify(messageCounter));