Added message/converted counter

This commit is contained in:
Marco Loewe 2021-09-03 18:13:52 +02:00
parent 3870acc7f9
commit 38d6708b06

19
bot.js
View File

@ -21,6 +21,8 @@ let defaultConfig = {
ignoredUsers: [] ignoredUsers: []
}; };
let messageCounter = [];
// Client // Client
client.on('message', onMessageHandler); client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler); client.on('connected', onConnectedHandler);
@ -207,12 +209,25 @@ function onMessageHandler (channel, userstate, message, self) {
console.log(`* Message had too few syllables`); console.log(`* Message had too few syllables`);
return; return;
} }
let counter = [];
if (channel in messageCounter) {
counter = messageCounter[channel];
} else {
counter['total'] = 0;
counter['converted'] = 0;
}
counter['total'] = counter['total']++;
// random chance // random chance
// TODO: find a better alternative // TODO: find a better alternative
var number = Math.random() * 100; var number = Math.random() * 100;
if (number <= config.chance) { if (number <= config.chance) {
counter['converted'] = counter['converted']++;
var buttCount = Math.ceil(words.length / config.limit); var buttCount = Math.ceil(words.length / config.limit);
var randomNumbersUsed = []; var randomNumbersUsed = [];
@ -245,6 +260,10 @@ function onMessageHandler (channel, userstate, message, self) {
client.say(channel, newMessage.trim()); client.say(channel, newMessage.trim());
} }
messageCounter[channel] = counter;
fs.writeFileSync('counter', JSON.stringify(messageCounter));
} }
} }
} }