|
|
@ -75,6 +75,7 @@ function Currency(irc, db, options) { |
|
|
|
__self.config.website = options.website || ''; |
|
|
|
__self.config.modpowers = options.modpowers || false; |
|
|
|
__self.config.chatterbonus = options.chatterbonus || false; |
|
|
|
__self.config.ignorelist = options.ignorelist || ['jtv']; |
|
|
|
|
|
|
|
// general settings
|
|
|
|
__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) { |
|
|
|
var response = '> Rank (of '+total+'): '; |
|
|
|
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); |
|
|
|
__self.irc.emit('message', {message: response, timer: 1}); |
|
|
@ -691,6 +692,7 @@ Currency.prototype.handout_coins = function () { |
|
|
|
response.on('end', function () { |
|
|
|
var json = JSON.parse(body); |
|
|
|
__self.streaming = json.stream !== null; |
|
|
|
|
|
|
|
if (__self.streaming && __self.give_coins === false) { |
|
|
|
insert_coins(); |
|
|
|
} |
|
|
@ -739,68 +741,21 @@ Currency.prototype.handout_coins = function () { |
|
|
|
if (__self.give_coins) { |
|
|
|
var time = utils.make_interval(__self.give_coins_timer); |
|
|
|
if (time === 0) { |
|
|
|
__self.irc.raw('WHO ' + __self.irc.config.channel); |
|
|
|
setTimeout(insert_coins, 1000); |
|
|
|
} else { |
|
|
|
setTimeout(insert_coins, time); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// monitor viewers in irc
|
|
|
|
__self.irc.on('data', function (data) { |
|
|
|
if (__self.streaming) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 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.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; |
|
|
|
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(clone_active_list.indexOf(clone_viewer_list[i])) currecy_amount++; |
|
|
|
if(active_list.indexOf(__self.viewer_list[i])) currency_amount++; |
|
|
|
} |
|
|
|
if (clone_viewer_list[i] !== '') { |
|
|
|
if (i != clone_viewer_list.length - 1) { |
|
|
|
if (__self.viewer_list[i] !== '') { |
|
|
|
if (i != __self.viewer_list.length - 1) { |
|
|
|
sql += 'INSERT INTO viewers (user, points) '; |
|
|
|
sql += 'VALUES (\'' + clone_viewer_list[i] + '\', ' + currency_amount + ') '; |
|
|
|
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 (\'' + clone_viewer_list[i] + '\', ' + currency_amount + ') '; |
|
|
|
sql += 'VALUES (\'' + __self.viewer_list[i] + '\', ' + currency_amount + ') '; |
|
|
|
sql += 'ON DUPLICATE KEY UPDATE points = points + ' + currency_amount; |
|
|
|
} |
|
|
|
} |
|
|
@ -808,9 +763,66 @@ Currency.prototype.handout_coins = function () { |
|
|
|
|
|
|
|
// execute query
|
|
|
|
__self.db.execute(sql, function () {}); |
|
|
|
setTimeout(insert_coins, 1000); |
|
|
|
} else { |
|
|
|
setTimeout(insert_coins, time); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// monitor viewers in irc
|
|
|
|
__self.irc.on('data', function (data) { |
|
|
|
var data_split = data.split(' '), 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); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// handle JOIN's
|
|
|
|
if (data_split[3] == 'JOIN') { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 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 = []; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|