T.tv chat issues fixed 100%, bot working.

This commit is contained in:
binaryatrocity committed 2014-03-23 22:37:19 -05:00
1 parent 6b1a8b893c
commit 708ff96989
7 files changed
+110 -103

No files matched your search

+60 -9
View File
@@ -131,11 +131,30 @@ function Currency(irc, db, options) {
__self.bets_response = null;
__self.bets_response_timer = 3000;
__self.bets_response_reset = true;
// high score table
__self.score_bet_pool = 0;
__self.score_bet_single = 0;
}
//-------- Methods ---------
Currency.prototype.start = function () {
var __self = this;
// populate highscore holders
__self.db.execute('SELECT * FROM highscores', function(rows) {
rows.forEach(function(element, index, array){
switch(element.name) {
case 'bet_pool':
__self.score_bet_pool = element.value;
break;
case 'bet_single':
__self.score_bet_single = element.value;
break;
}
});
});
__self.handout_coins();
};
@@ -243,7 +262,7 @@ Currency.prototype.commands = function (data) {
}
}
/*
// TODO: create a log file that monitors just add/remove/push - greedy mods :D
// add currency
if (data[4] === 'add') {
if(parseInt(data[5], 10) > 0 && data[6]) {
@@ -264,7 +283,6 @@ Currency.prototype.commands = function (data) {
__self.adjust_currency('push', data[5], data[6]);
}
}
*/
}
// moderator commands
@@ -369,9 +387,11 @@ Currency.prototype.commands = function (data) {
}
}
break;
// show top currency earners
case '!top':
__self.get_top(data[4]);
break;
// show a users ranking in the ladder
case '!rank':
__self.get_rank(__self.irc.caller(data[0]).toLowerCase());
break;
@@ -737,7 +757,7 @@ Currency.prototype.handout_coins = function () {
}
// execute query
__self.db.execute(sql, function () { console.log('DATA - Completed adding coins to ' + __self.viewer_list.length + ' viewers'); });
__self.db.execute(sql, function () {});
setTimeout(insert_coins, 1000);
} else {
setTimeout(insert_coins, time);
@@ -749,14 +769,25 @@ Currency.prototype.handout_coins = function () {
__self.irc.on('data', function (data) {
var data_split = data.split(' '), viewer = '';
// Processing /names
// viewers from \who
// TODO: new twitch chat doesn't allow /who, remove this?
if (data_split[3] == '352') {
if (data_split[6] !== undefined) {
viewer = data_split[6].toLowerCase();
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer);
}
}
}
// Processing below replaces the now defunct who-calls above
// handle /names
if (data_split[3] == '353'){
viewers = data_split.splice(7);
viewers.forEach(function(name) {
if(name.charAt(0) === ':') name = name.slice(1);
if (__self.viewer_list.indexOf(name) < 0 && __self.config.ignorelist.indexOf(name) < 0) {
__self.viewer_list.push(name);
console.log("[*ADD NAME*] "+name+" from /names");
}
});
}
@@ -770,7 +801,7 @@ Currency.prototype.handout_coins = function () {
}
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer);
console.log("[*ADD NAME*] "+viewer+" from JOIN");
} else {
}
}
@@ -783,8 +814,9 @@ Currency.prototype.handout_coins = function () {
}
var viewer_idx = __self.viewer_list.indexOf(viewer);
if (viewer_idx >= 0) {
__self.viewer_list.splice(viewer_idx);
console.log("[*DEL NAME*] "+viewer+" from PART");
__self.viewer_list.splice(viewer_idx,1);
} else {
console.log("[*ERROR*] User "+viewer+" PART'ed but was not in viewer_list.");
}
}
@@ -1462,6 +1494,7 @@ Currency.prototype.bets = function(status, data) {
__self.irc.emit('message', {message:__self.pre_text + 'Betting already in progress'});
}
}
// FIXME: messages below should be "cant open a bet until X is over/closed" instead? test it
} else {
// raffle in progress
__self.irc.emit('message', {message:__self.pre_text + 'Betting must be closed before you can open a raffle'});
@@ -1513,7 +1546,15 @@ Currency.prototype.bets = function(status, data) {
for (var i = 0; i < __self.bets_board.length; i++) {
if (data == __self.bets_board[i].name) {
__self.bets_award_winner(__self.bets_board[i]);
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data});
if(__self.bets_board[i].total > __self.score_bet_pool) {
sql = 'UPDATE highscores SET value = ' + __self.bets_board[i].total + ' WHERE name = \'bet_pool\'';
__self.db.execute(sql, function() {
__self.score_bet_pool = __self.bets_board[i].total;
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data + '. New record set!!'});
});
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data});
}
}
}
} else {
@@ -1587,6 +1628,16 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
for (var i = 0; i < rows.length; i++) {
amount = Math.min(amount, rows[i].points);
}
// check for hiscore and set db appropriately
if(amount > __self.score_bet_single) {
sql = 'UPDATE highscores SET value = ' + amount + ' WHERE name = \'bet_single\'';
__self.db.execute(sql, function() {
__self.score_bet_single = amount;
__self.irc.emit('message', {message:__self.pre_text + ' ' + caller + ' set new record bet at ' + amount + '!'});
});
}
if (__self.bets_viewers.length > 0) {
for (var i = 0; i < __self.bets_viewers.length; i++) {
if (__self.bets_viewers[i].viewer === caller) {
+2 -2
View File
@@ -74,7 +74,7 @@ function IRC(options) {
nick : 'irc_bot',
broadcaster : __self.options.channel.slice(1).charAt(0).toUpperCase() + __self.options.channel.slice(2).toLowerCase(),
// twitch server
addr : '199.9.250.229', //__self.options.name.toLowerCase() + '.jtvirc.com',
addr : 'irc.twitch.tv', //__self.options.name.toLowerCase() + '.jtvirc.com',
port : 6667,
channel : __self.options.channel.toLowerCase(),
encoding : 'ascii'
@@ -240,7 +240,7 @@ IRC.prototype.reconnect = function () {
IRC.prototype.join = function (data) {
var __self = this;
if (data[3] === ':>') {
if (data[3] === ':>' || data[3] === ':End') {
__self.raw('JOIN ' + __self.config.channel);
}
};
+13 -4
View File
@@ -28,7 +28,7 @@ function DB(options) {
//-------- Methods ---------
DB.prototype.start = function() {
var __self = this, commands ='', viewers = '';
var __self = this, commands ='', viewers = '', scores = '';
// table structure for table commands
commands += 'CREATE TABLE IF NOT EXISTS `commands` (';
@@ -44,10 +44,19 @@ DB.prototype.start = function() {
viewers += '`user` varchar(64) COLLATE utf8_unicode_ci NOT NULL,';
viewers += '`points` int(11) NOT NULL,';
viewers += 'PRIMARY KEY (`user`)';
viewers += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;';
viewers += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
// table structure for table highscores
scores += 'CREATE TABLE IF NOT EXISTS `highscores` (';
scores += '`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,';
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);';
// execute sql, create tables if they don't exist
__self.execute(commands + '; ' + viewers, function(){});
__self.execute(commands + '; ' + viewers + '; ' + scores, function(){});
};
DB.prototype.execute = function(sql, callback) {
@@ -78,4 +87,4 @@ DB.prototype.execute = function(sql, callback) {
module.exports = function (options) {
return new DB(options);
};
};