Added message/converted counter
This commit is contained in:
parent
3870acc7f9
commit
38d6708b06
19
bot.js
19
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user