Log chat to seperate files, added chat stats to web.
This commit is contained in:
1 parent
708ff96989
commit
b10ba98227
9 files changed
+244
-195
No files matched your search
@@ -59,6 +59,7 @@
|
||||
|
||||
var https = require('https'),
|
||||
http = require('http'),
|
||||
file = require('fs'),
|
||||
utils = require('./utils.js');
|
||||
|
||||
//-------- Construct ---------
|
||||
@@ -236,8 +237,10 @@ Currency.prototype.commands = function (data) {
|
||||
|
||||
// open / close betting system
|
||||
if (data[4] === 'bet') {
|
||||
console.log("bet command found");
|
||||
switch (data[5]) {
|
||||
case 'open':
|
||||
console.log("bet open command found");
|
||||
if (data[6] && data[7]) {
|
||||
__self.bets(true, data);
|
||||
} else {
|
||||
@@ -827,10 +830,42 @@ Currency.prototype.handout_coins = function () {
|
||||
if (viewer != __self.irc.config.name.toLowerCase()) {
|
||||
viewer = viewer.slice(1);
|
||||
}
|
||||
|
||||
// add missing chatters to viewer_list
|
||||
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
|
||||
__self.viewer_list.push(viewer);
|
||||
console.log("[*ADD NAME*] "+viewer+" from CHAT");
|
||||
}
|
||||
|
||||
// log chat if enabled
|
||||
if (__self.irc.store_chat && __self.config.ignorelist.indexOf(viewer) < 0) {
|
||||
file.exists(__self.irc.chat_log, function (exists) {
|
||||
if (exists) {
|
||||
// get a timestamp
|
||||
var date = new Date(),
|
||||
hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
|
||||
min = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
|
||||
sec = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(),
|
||||
streaming_time = '';
|
||||
|
||||
// create start time string
|
||||
streaming_time += hours.toString() + ':' + min.toString();
|
||||
|
||||
// craft message
|
||||
data_split[5] = data_split[5].slice(1);
|
||||
var message = data_split.slice(5).join(' ');
|
||||
|
||||
// put it all together
|
||||
var logline = '[' + streaming_time + '] <' + viewer + '> ' + message + '\r\n';
|
||||
|
||||
file.appendFile(__self.irc.chat_log, logline, 'utf-8', function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+4
-2
@@ -18,7 +18,8 @@ exports.initialize = function(options) {
|
||||
irc = require('./irc.js')({
|
||||
name : config.twitch.bot.name,
|
||||
pass : config.twitch.bot.password,
|
||||
channel : '#' + config.twitch.channel
|
||||
channel : '#' + config.twitch.channel,
|
||||
chatlog : config.web.chatlog
|
||||
});
|
||||
db = require('./mysql.js')({
|
||||
host : config.currency.host,
|
||||
@@ -43,7 +44,8 @@ exports.initialize = function(options) {
|
||||
title : config.twitch.channel,
|
||||
slogan : config.web.slogan,
|
||||
logo : config.web.logo,
|
||||
twitter : config.web.twitter
|
||||
twitter : config.web.twitter,
|
||||
statdir : config.web.statdir
|
||||
});
|
||||
|
||||
//-------- Start -------
|
||||
|
||||
+16
-1
@@ -93,6 +93,13 @@ function IRC(options) {
|
||||
__self.streaming = false;
|
||||
__self.new_file = false;
|
||||
__self.log = '';
|
||||
|
||||
// chat logging
|
||||
__self.first_check = true;
|
||||
__self.store_chat = __self.options.chatlog || false;
|
||||
__self.chat_log = '';
|
||||
|
||||
|
||||
}
|
||||
|
||||
IRC.prototype = new events.EventEmitter();
|
||||
@@ -104,7 +111,9 @@ IRC.prototype.start = function () {
|
||||
// check stream status
|
||||
function stream_status() {
|
||||
var time = utils.make_interval(__self.check_streaming);
|
||||
if (time === 0) {
|
||||
if (time === 0 || __self.first_check) {
|
||||
// Important to log chat right away, so lets skip the first 4 minute wait
|
||||
if (__self.first_check) __self.first_check = false;
|
||||
https.get('https://api.twitch.tv/kraken/streams/' + __self.config.channel.slice(1), function (response) {
|
||||
var body = '';
|
||||
|
||||
@@ -140,6 +149,12 @@ IRC.prototype.start = function () {
|
||||
// create new log file
|
||||
__self.log = './../logs/' + __self.config.channel.slice(1) + '_' + streaming_time.toString() + '.txt';
|
||||
file.open(__self.log, 'w');
|
||||
|
||||
// create chat log
|
||||
if (__self.store_chat) {
|
||||
__self.chat_log = './../logs/chat/' + __self.config.channel.slice(1) + '_' + streaming_time.toString() + '.txt';
|
||||
file.open(__self.chat_log, 'w');
|
||||
}
|
||||
} else if (!__self.streaming) {
|
||||
__self.new_file = false;
|
||||
__self.log = '';
|
||||
|
||||
+2
-2
@@ -52,8 +52,8 @@ DB.prototype.start = function() {
|
||||
scores += '`value` int(11) NOT NULL,';
|
||||
scores += 'PRIMARY KEY (`name`)';
|
||||
scores += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;';
|
||||
scores += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_single\', 0);';
|
||||
scores += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_pool\', 0);';
|
||||
//scores += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_single\', 0);';
|
||||
//scores += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_pool\', 0);';
|
||||
|
||||
// execute sql, create tables if they don't exist
|
||||
__self.execute(commands + '; ' + viewers + '; ' + scores, function(){});
|
||||
|
||||
+11
@@ -12,6 +12,7 @@ function WEB(db, options) {
|
||||
__self.slogan = options.slogan;
|
||||
__self.logo = options.logo;
|
||||
__self.twitter = options.twitter;
|
||||
__self.statdir = options.statdir;
|
||||
}
|
||||
|
||||
// ---- Methods ----
|
||||
@@ -50,6 +51,16 @@ WEB.prototype.start = function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
__self.srv.get('/stats', function(req, res) {
|
||||
//get the whole viewer list
|
||||
res.render('stats', {
|
||||
title: __self.title,
|
||||
slogan: __self.slogan,
|
||||
logo: __self.logo,
|
||||
twitter: __self.twitter,
|
||||
statdir: __self.statdir,
|
||||
});
|
||||
});
|
||||
__self.srv.get('/api/test', function(req, res) {
|
||||
res.send("Hey, its Potatr. This data was pulled from the web.");
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user