From 38d6708b0625719342f73289ccbdb23d966646cd Mon Sep 17 00:00:00 2001 From: Marco Loewe Date: Fri, 3 Sep 2021 18:13:52 +0200 Subject: [PATCH] Added message/converted counter --- bot.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bot.js b/bot.js index afa08f9..e252084 100644 --- a/bot.js +++ b/bot.js @@ -21,6 +21,8 @@ let defaultConfig = { ignoredUsers: [] }; +let messageCounter = []; + // Client client.on('message', onMessageHandler); client.on('connected', onConnectedHandler); @@ -207,12 +209,25 @@ function onMessageHandler (channel, userstate, message, self) { console.log(`* Message had too few syllables`); return; } + + let counter = []; + + if (channel in messageCounter) { + counter = messageCounter[channel]; + } else { + counter['total'] = 0; + counter['converted'] = 0; + } + + counter['total'] = counter['total']++; // random chance // TODO: find a better alternative var number = Math.random() * 100; if (number <= config.chance) { + counter['converted'] = counter['converted']++; + var buttCount = Math.ceil(words.length / config.limit); var randomNumbersUsed = []; @@ -245,6 +260,10 @@ function onMessageHandler (channel, userstate, message, self) { client.say(channel, newMessage.trim()); } + + messageCounter[channel] = counter; + + fs.writeFileSync('counter', JSON.stringify(messageCounter)); } } }