Browse Source

Fixing twitch.tv chat changes, added global ignore list.

master
Brandon Cornejo 11 years ago
parent
commit
f1289e700e
  1. 102
      lib/currency.js
  2. 3
      lib/initialize.js
  3. 3
      lib/irc.js
  4. 6
      web/templates/ladder.jade

102
lib/currency.js

@ -75,6 +75,7 @@ function Currency(irc, db, options) {
__self.config.website = options.website || ''; __self.config.website = options.website || '';
__self.config.modpowers = options.modpowers || false; __self.config.modpowers = options.modpowers || false;
__self.config.chatterbonus = options.chatterbonus || false; __self.config.chatterbonus = options.chatterbonus || false;
__self.config.ignorelist = options.ignorelist || ['jtv'];
// general settings // general settings
__self.pre_text = '> ' + __self.config.currency + ': '; __self.pre_text = '> ' + __self.config.currency + ': ';
@ -492,7 +493,7 @@ Currency.prototype.get_rank = function (data) {
__self.query_rank(__self.rank_flood, function (ranks, total) { __self.query_rank(__self.rank_flood, function (ranks, total) {
var response = '> Rank (of '+total+'): '; var response = '> Rank (of '+total+'): ';
for(var i = 0; i < ranks.length; i++) { for(var i = 0; i < ranks.length; i++) {
response += ranks[i]['user'] + ' ('+ranks[i]['@row_number:=@row_number+1']+'), ';
response += ranks[i]['user'] + ' ('+ranks[i]['@row_number:=@row_number+1']+') ['+ranks[i]['points']+'], ';
} }
response = response.slice(1,-2); response = response.slice(1,-2);
__self.irc.emit('message', {message: response, timer: 1}); __self.irc.emit('message', {message: response, timer: 1});
@ -691,6 +692,7 @@ Currency.prototype.handout_coins = function () {
response.on('end', function () { response.on('end', function () {
var json = JSON.parse(body); var json = JSON.parse(body);
__self.streaming = json.stream !== null; __self.streaming = json.stream !== null;
if (__self.streaming && __self.give_coins === false) { if (__self.streaming && __self.give_coins === false) {
insert_coins(); insert_coins();
} }
@ -739,7 +741,28 @@ Currency.prototype.handout_coins = function () {
if (__self.give_coins) { if (__self.give_coins) {
var time = utils.make_interval(__self.give_coins_timer); var time = utils.make_interval(__self.give_coins_timer);
if (time === 0) { if (time === 0) {
__self.irc.raw('WHO ' + __self.irc.config.channel);
// build sql from the saved viewer list
var sql = '';
for (var i = 0; i < __self.viewer_list.length; i++) {
var currency_amount = __self.subscribers.indexOf(__self.viewer_list[i]) >= 0 ? 2 : 1;
if (__self.config.chatterbonus){
if(active_list.indexOf(__self.viewer_list[i])) currency_amount++;
}
if (__self.viewer_list[i] !== '') {
if (i != __self.viewer_list.length - 1) {
sql += 'INSERT INTO viewers (user, points) ';
sql += 'VALUES (\'' + __self.viewer_list[i] + '\', ' + currency_amount + ') ';
sql += 'ON DUPLICATE KEY UPDATE points = points + ' + currency_amount + '; ';
} else {
sql += 'INSERT INTO viewers (user, points) ';
sql += 'VALUES (\'' + __self.viewer_list[i] + '\', ' + currency_amount + ') ';
sql += 'ON DUPLICATE KEY UPDATE points = points + ' + currency_amount;
}
}
}
// execute query
__self.db.execute(sql, function () {});
setTimeout(insert_coins, 1000); setTimeout(insert_coins, 1000);
} else { } else {
setTimeout(insert_coins, time); setTimeout(insert_coins, time);
@ -749,68 +772,57 @@ Currency.prototype.handout_coins = function () {
// monitor viewers in irc // monitor viewers in irc
__self.irc.on('data', function (data) { __self.irc.on('data', function (data) {
if (__self.streaming) {
var data_split = data.split(' '), viewer = ''; var data_split = data.split(' '), viewer = '';
// viewers from \who
if (data_split[3] == '352') {
if (data_split[6] !== undefined) {
viewer = data_split[6].toLowerCase();
if (__self.viewer_list.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer);
}
// Processing /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);
} }
});
} }
// viewers chatting
if (data_split[3] == 'PRIVMSG') {
// handle JOIN's
if (data_split[3] == 'JOIN') {
var servernick = data_split[2].toLowerCase().split('!'); var servernick = data_split[2].toLowerCase().split('!');
viewer = servernick[0]; viewer = servernick[0];
if (viewer != __self.irc.config.name.toLowerCase()) { if (viewer != __self.irc.config.name.toLowerCase()) {
viewer = viewer.slice(1); viewer = viewer.slice(1);
} }
if (__self.viewer_list.indexOf(viewer) < 0) {
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer); __self.viewer_list.push(viewer);
} }
if (__self.active_list.indexOf(viewer) < 0) {
__self.active_list.push(viewer);
} }
}
// give coins after \who and handout_coins is true
if (__self.give_coins && data_split[3] == '315') {
var clone_viewer_list = __self.viewer_list;
var clone_active_list = __self.active_list;
// clear old list and start recording
__self.viewer_list = [];
__self.active_list = [];
// build sql from the saved viewer list
var sql = '';
for (var i = 0; i < clone_viewer_list.length; i++) {
var currency_amount = __self.subscribers.indexOf(clone_viewer_list[i]) >= 0 ? 2 : 1;
if (__self.config.chatterbonus){
if(clone_active_list.indexOf(clone_viewer_list[i])) currecy_amount++;
}
if (clone_viewer_list[i] !== '') {
if (i != clone_viewer_list.length - 1) {
sql += 'INSERT INTO viewers (user, points) ';
sql += 'VALUES (\'' + clone_viewer_list[i] + '\', ' + currency_amount + ') ';
sql += 'ON DUPLICATE KEY UPDATE points = points + ' + currency_amount + '; ';
} else {
sql += 'INSERT INTO viewers (user, points) ';
sql += 'VALUES (\'' + clone_viewer_list[i] + '\', ' + currency_amount + ') ';
sql += 'ON DUPLICATE KEY UPDATE points = points + ' + currency_amount;
// handle PART's
if (data_split[3] == 'PART') {
var servernick = data_split[2].toLowerCase().split('!');
viewer = servernick[0];
if (viewer != __self.irc.config.name.toLowerCase()) {
viewer = viewer.slice(1);
} }
var viewer_idx = __self.viewer_list.indexOf(viewer);
if (viewer_idx >= 0) {
__self.viewer_list.splice(viewer_idx);
} }
} }
// execute query
__self.db.execute(sql, function () {});
// viewers chatting
if (data_split[3] == 'PRIVMSG') {
var servernick = data_split[2].toLowerCase().split('!');
viewer = servernick[0];
if (viewer != __self.irc.config.name.toLowerCase()) {
viewer = viewer.slice(1);
}
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer);
}
if (__self.active_list.indexOf(viewer) < 0) {
__self.active_list.push(viewer);
} }
} else {
__self.viewer_list = [];
} }
}); });

3
lib/initialize.js

@ -36,7 +36,8 @@ exports.initialize = function(options) {
subscribers : config.twitch.subscribers, subscribers : config.twitch.subscribers,
website : config.currency.website, website : config.currency.website,
modpowers : config.currency.modpowers, modpowers : config.currency.modpowers,
chatterbonus: config.currency.chatterbonus
chatterbonus: config.currency.chatterbonus,
ignorelist : config.ignorelist
}); });
web = require('./web.js')(db, { web = require('./web.js')(db, {
port : config.web.port, port : config.web.port,

3
lib/irc.js

@ -154,6 +154,7 @@ IRC.prototype.start = function () {
stream_status(); stream_status();
__self.connect(); __self.connect();
debugger;
__self.monitor_queue(); __self.monitor_queue();
}; };
@ -239,7 +240,7 @@ IRC.prototype.reconnect = function () {
IRC.prototype.join = function (data) { IRC.prototype.join = function (data) {
var __self = this; var __self = this;
if (data[3] === ':End') {
if (data[3] === ':>') {
__self.raw('JOIN ' + __self.config.channel); __self.raw('JOIN ' + __self.config.channel);
} }
}; };

6
web/templates/ladder.jade

@ -36,6 +36,7 @@ html(lang="en")
caption Potato Farmer Ladder Rankings caption Potato Farmer Ladder Rankings
thead thead
tr tr
th Rank
th Viewer th Viewer
th Potatoes th Potatoes
tbody tbody
@ -62,10 +63,11 @@ html(lang="en")
// slice(a, b): a = (n*(x-1))+1, b = n*x where n = perPage and x=curerntPage (skip +1 at end of a for splice) // slice(a, b): a = (n*(x-1))+1, b = n*x where n = perPage and x=curerntPage (skip +1 at end of a for splice)
var a = (perPage*(z-1)), var a = (perPage*(z-1)),
b = perPage*z;
b = perPage*z,
pstart = z-1;
data.slice(a, b).forEach(function(element, index, array){ data.slice(a, b).forEach(function(element, index, array){
$('table > tbody').append($('<tr></tr>').append('<td>'+element.user+'</td><td>'+element.points+'</td>'));
$('table > tbody').append($('<tr></tr>').append('<td>'+(a+index+1)+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
}); });
}); });

Loading…
Cancel
Save