Counter now supports multiple channel and creates a log
This commit is contained in:
parent
38d6708b06
commit
26128ab966
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
|||
.env
|
||||
twitch.config
|
||||
buttsbot.config
|
||||
|
||||
counter
|
||||
node_modules/
|
||||
|
|
|
|||
19
bot.js
19
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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user