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
|
.env
|
||||||
twitch.config
|
twitch.config
|
||||||
buttsbot.config
|
buttsbot.config
|
||||||
|
counter
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
|
||||||
19
bot.js
19
bot.js
|
|
@ -21,7 +21,7 @@ let defaultConfig = {
|
||||||
ignoredUsers: []
|
ignoredUsers: []
|
||||||
};
|
};
|
||||||
|
|
||||||
let messageCounter = [];
|
let messageCounter = JSON.parse(fs.readFileSync('counter'));
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
client.on('message', onMessageHandler);
|
client.on('message', onMessageHandler);
|
||||||
|
|
@ -194,8 +194,6 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
// split messages into word array and try to determine syllabes
|
// split messages into word array and try to determine syllabes
|
||||||
var words = message.split(' ');
|
var words = message.split(' ');
|
||||||
var syllables = words.map(syllabify);
|
var syllables = words.map(syllabify);
|
||||||
|
|
||||||
console.log(JSON.stringify(syllables));
|
|
||||||
|
|
||||||
// calculate syllabe count
|
// calculate syllabe count
|
||||||
var syllableCount = 0;
|
var syllableCount = 0;
|
||||||
|
|
@ -210,23 +208,24 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let counter = [];
|
var counter = {
|
||||||
|
total: 0,
|
||||||
|
converted: 0
|
||||||
|
};
|
||||||
|
|
||||||
if (channel in messageCounter) {
|
if (channel in messageCounter) {
|
||||||
|
console.log(`* Load counter for ${channel}`);
|
||||||
counter = messageCounter[channel];
|
counter = messageCounter[channel];
|
||||||
} else {
|
|
||||||
counter['total'] = 0;
|
|
||||||
counter['converted'] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
counter['total'] = 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']++;
|
counter.converted++;
|
||||||
|
|
||||||
var buttCount = Math.ceil(words.length / config.limit);
|
var buttCount = Math.ceil(words.length / config.limit);
|
||||||
|
|
||||||
|
|
@ -261,6 +260,8 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
client.say(channel, newMessage.trim());
|
client.say(channel, newMessage.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(channel + ": " + JSON.stringify(counter));
|
||||||
|
|
||||||
messageCounter[channel] = counter;
|
messageCounter[channel] = counter;
|
||||||
|
|
||||||
fs.writeFileSync('counter', JSON.stringify(messageCounter));
|
fs.writeFileSync('counter', JSON.stringify(messageCounter));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user