|
@ -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 = []; |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|