diff --git a/lib/commands.js b/lib/commands.js index bc2eb88..a25fd2e 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -37,8 +37,10 @@ Commands.prototype.start = function() { }; Commands.prototype.commands = function(data) { - var __self = this, - command_check = data[3].slice(1).charAt(0), + var __self = this; + + if (typeof data[3] === 'undefined') return; + var command_check = data[3].slice(1).charAt(0), command = data[3].slice(2); // check if potential command was called and match it with stored commands @@ -67,16 +69,20 @@ Commands.prototype.commands = function(data) { } }); } else if (command_check === '!' && command === __self.config.bot_name.toLowerCase()) { + moderator_initiated = __self.irc.mods.indexOf(__self.irc.caller(data[0])) >= 0; + console.log(__self.irc.mods) var commands = '> Commands: !' + __self.config.currency.toLowerCase() + ', !top, !rank, '; if(Object.keys(__self.config.exchange).length != 0) commands += '!exchange, '; - for (var i = 0; i < __self.command_list.length; i++) { - if (i !== __self.command_list.length - 1) { - commands += '!' + __self.command_list[i] + ', '; - } else { - commands += '!' + __self.command_list[i]; + if(moderator_initiated) { + for (var i = 0; i < __self.command_list.length; i++) { + if (i !== __self.command_list.length - 1) { + commands += '!' + __self.command_list[i] + ', '; + } else { + commands += '!' + __self.command_list[i]; + } } + __self.irc.emit('message',{message:commands, options:null}); } - __self.irc.emit('message',{message:commands, options:null}); } }; diff --git a/lib/currency.js b/lib/currency.js index 5fc10a8..a697ce5 100644 --- a/lib/currency.js +++ b/lib/currency.js @@ -855,32 +855,6 @@ Currency.prototype.handout_coins = function () { // get subscribers function subscribers() { - var time = utils.make_interval(__self.subscriber_check); - if (time === 0) { - // get stream status - http.get(__self.config.subscribers_json, function (response) { - var body = ''; - // put together response - response.on('data', function (chunk) { - body += chunk; - }); - - // start / stop handing out coins based on stream status - response.on('end', function () { - var json = JSON.parse(body); - var entries = json.feed.entry, subs = ''; - __self.subscribers = []; - for (var i = 0; i < entries.length; i++) { - __self.subscribers.push(entries[i].title['$t']); - subs += entries[i].title['$t'] + ' '; - } - __self.irc.emit('data', 'DATA - Subscriber Check - Returned: ' + subs); - setTimeout(subscribers, 1000); - }); - }); - } else { - setTimeout(subscribers, time); - } } // trigger coin handout @@ -2207,39 +2181,42 @@ Currency.prototype.bets_award_winner = function (winner) { // NEW STUFF Currency.prototype.add_quotation = function (data) { var __self = this; + broadcaster_bot_initiated = __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.broadcaster.toLowerCase() || __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.name.toLowerCase(), + moderator_initiated = __self.irc.mods.indexOf(__self.irc.caller(data[0])) >= 0; + if (broadcaster_bot_initiated || moderator_initiated) { - // Chop all the shit out - data.splice(0, 4); - data = data.join(' ') + // Chop all the shit out + data.splice(0, 4); + data = data.join(' ') - sql = 'INSERT INTO quotes (`text`) VALUES (' + __self.db.string_escape(data) + ');'; - __self.db.execute(sql, function() { - __self.irc.emit('message', {message:__self.pre_text + ' New quote added!'}); - }); + sql = 'INSERT INTO quotes (`text`) VALUES (' + __self.db.string_escape(data) + ');'; + __self.db.execute(sql, function(rows, fields) { + __self.irc.emit('message', {message:__self.pre_text + ' New quote added!' + ' ['+rows.insertId+']'}); + }); + } }; Currency.prototype.remove_quotation = function(data) { var __self = this; - - // Chop all the shit out - data.splice(0, 4); - if (data === parseInt(data, 10)) { - __self.db.execute('DELETE FROM quotes WHERE id=\''+parseInt(data, 10)+'\';', function(rows) { - __self.irc.emit('message', {message:__self.pre_text + 'Quote #'+data+' deleted!'}); - }); + broadcaster_bot_initiated = __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.broadcaster.toLowerCase() || __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.name.toLowerCase(), + moderator_initiated = __self.irc.mods.indexOf(__self.irc.caller(data[0])) >= 0; + if (broadcaster_bot_initiated || moderator_initiated) { + + // Chop all the shit out + data.splice(0, 4); + if (data == parseInt(data, 10)) { + __self.db.execute('DELETE FROM quotes WHERE id=\''+parseInt(data, 10)+'\';', function(rows) { + __self.irc.emit('message', {message:__self.pre_text + 'Quote #'+data+' deleted!'}); + }); + } } }; Currency.prototype.get_quotation = function() { var __self = this; - // Let's get the number of quotes in database (should store this on its own later) TODO - __self.db.execute('SELECT COUNT(*) AS quoteCount FROM quotes;', function(rows) { - var quote_count = rows[0].quoteCount; - var selected_quote_id = Math.floor(Math.random() * (quote_count - 0 + 1) + 1); - __self.db.execute('SELECT * FROM quotes WHERE id=\''+selected_quote_id+'\';', function(rows) { - __self.irc.emit('message', {message:__self.pre_text + rows[0].id + ': ' + rows[0].text}); - }); + __self.db.execute('SELECT * FROM quotes ORDER BY RAND() LIMIT 1;', function(rows) { + __self.irc.emit('message', {message:__self.pre_text + rows[0].id + ': ' + rows[0].text}); }); }; diff --git a/lib/irc.js b/lib/irc.js index a4106a0..fdf8425 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -205,6 +205,7 @@ IRC.prototype.connect = function () { __self.raw('NICK ' + __self.config.name); __self.raw('USER ' + __self.config.nick + ' ' + __self.config.nick + '.com ' + __self.config.nick + ' :' + __self.config.name); __self.raw('TWITCHCLIENT 1'); + __self.raw('CAP REQ :twitch.tv/membership'); }); // handle incoming socket data