Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ca5a8a797 | ||
|
|
705c733114 | ||
|
|
1d082c7263 | ||
|
|
8116360d51 |
No files matched your search
+8
-2
@@ -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,8 +69,11 @@ 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, ';
|
||||
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] + ', ';
|
||||
@@ -78,6 +83,7 @@ Commands.prototype.commands = function(data) {
|
||||
}
|
||||
__self.irc.emit('message',{message:commands, options:null});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Commands.prototype.add = function(command, text) {
|
||||
|
||||
+60
-27
@@ -236,7 +236,7 @@ Currency.prototype.commands = function (data) {
|
||||
switch (data[5]) {
|
||||
case 'open':
|
||||
if (data[6] && data[7] && !__self.raffle_status) {
|
||||
if(parseInt(data[6], 10) > 0 && parseInt(data[7], 10) > 0) {
|
||||
if(parseInt(data[6], 10) >= 0 && parseInt(data[7], 10) > 0) {
|
||||
// save default values
|
||||
__self.temp.raffle_ticket_cost = __self.raffle_ticket_cost;
|
||||
__self.temp.raffle_max_tickets = __self.raffle_max_tickets;
|
||||
@@ -352,6 +352,13 @@ Currency.prototype.commands = function (data) {
|
||||
if (broadcaster_bot_initiated || moderator_initiated) {
|
||||
// enable/disable currency requests
|
||||
switch (data[4]) {
|
||||
case 'status':
|
||||
if (__self.streaming) {
|
||||
__self.irc.emit('message', {message:__self.pre_text + "Stream is online, " + __self.config.currency + " are being distributed!"});
|
||||
} else {
|
||||
__self.irc.emit('message', {message:__self.pre_text + "Stream is offline :("});
|
||||
}
|
||||
break;
|
||||
case 'on':
|
||||
if (!__self.auction_status && !__self.raffle_status) {
|
||||
__self.coin_toggle = false;
|
||||
@@ -461,8 +468,18 @@ Currency.prototype.commands = function (data) {
|
||||
case '!exchange':
|
||||
if(Object.keys(__self.config.exchanges).length != 0)
|
||||
__self.currency_exchange(__self.irc.caller(data[0]), parseInt(data[4], 10), data[5]);
|
||||
break;
|
||||
case '!addquote':
|
||||
__self.add_quotation(data);
|
||||
break;
|
||||
case '!delquote':
|
||||
__self.remove_quotation(data);
|
||||
break;
|
||||
case '!quote':
|
||||
__self.get_quotation();
|
||||
}
|
||||
|
||||
|
||||
// place a bet
|
||||
if (__self.bets_status === true) {
|
||||
for (var i = 0; i < __self.bets_board.length; i++) {
|
||||
@@ -838,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
|
||||
@@ -2187,6 +2178,48 @@ Currency.prototype.bets_award_winner = function (winner) {
|
||||
__self.bets_total = 0;
|
||||
};
|
||||
|
||||
// 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(' ')
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
__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});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = function (irc, db, commands, options) {
|
||||
return new Currency(irc, db, commands, options);
|
||||
};
|
||||
+6
-4
@@ -77,7 +77,7 @@ function IRC(options) {
|
||||
addr : 'irc.twitch.tv', //__self.options.name.toLowerCase() + '.jtvirc.com',
|
||||
port : 6667,
|
||||
channel : __self.options.channel.toLowerCase(),
|
||||
encoding : 'ascii'
|
||||
encoding : 'utf-8'
|
||||
};
|
||||
|
||||
__self.mods = [];
|
||||
@@ -204,6 +204,8 @@ IRC.prototype.connect = function () {
|
||||
__self.raw('PASS ' + __self.config.pass, true);
|
||||
__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
|
||||
@@ -273,7 +275,7 @@ IRC.prototype.moderators = function (data) {
|
||||
|
||||
if (data[1] === 'MODE') {
|
||||
if (data[4] !== undefined) {
|
||||
var user = data[4].charAt(0).toUpperCase() + data[4].slice(1);
|
||||
var user = data[4].toLowerCase();
|
||||
switch (data[3]) {
|
||||
case '+o':
|
||||
if (__self.mods.indexOf(user) < 0) {
|
||||
@@ -315,7 +317,7 @@ IRC.prototype.raw = function (data, hide) {
|
||||
IRC.prototype.caller = function (data) {
|
||||
var caller = data.split('!');
|
||||
|
||||
return caller[0].charAt(1).toUpperCase() + caller[0].slice(2);
|
||||
return caller[0].slice(1).toLowerCase();
|
||||
};
|
||||
|
||||
// send message to twitch chat
|
||||
@@ -327,7 +329,7 @@ IRC.prototype.msg = function (msg, options) {
|
||||
__self.raw('PRIVMSG ' + __self.config.channel + ' :' + msg);
|
||||
break;
|
||||
case 1:
|
||||
if (__self.mods.indexOf(opts.caller) >= 0) {
|
||||
if (__self.mods.indexOf(opts.caller.toLowerCase()) >= 0) {
|
||||
__self.raw('PRIVMSG ' + __self.config.channel + ' :' + msg);
|
||||
}
|
||||
break;
|
||||
|
||||
+13
-3
@@ -24,11 +24,14 @@ function DB(options) {
|
||||
__self.user = options.user || '';
|
||||
__self.password = options.password || '';
|
||||
__self.database = options.database || '';
|
||||
|
||||
// Open escape method to other modules
|
||||
__self.string_escape = mysql.escape;
|
||||
}
|
||||
|
||||
//-------- Methods ---------
|
||||
DB.prototype.start = function() {
|
||||
var __self = this, commands ='', viewers = '', scores = '';
|
||||
var __self = this, commands ='', viewers = '', scores = '', quotes = '';
|
||||
|
||||
// table structure for table commands
|
||||
commands += 'CREATE TABLE IF NOT EXISTS `commands` (';
|
||||
@@ -53,10 +56,17 @@ DB.prototype.start = function() {
|
||||
scores += '`value` int(11) NOT NULL,';
|
||||
scores += '`date` timestamp ON UPDATE current_timestamp,';
|
||||
scores += 'PRIMARY KEY (`name`)';
|
||||
scores += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;';
|
||||
scores += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
|
||||
|
||||
// table structure for QUOTES
|
||||
quotes += 'CREATE TABLE IF NOT EXISTS `quotes` (';
|
||||
quotes += '`id` int(11) NOT NULL AUTO_INCREMENT,';
|
||||
quotes += '`text` longtext COLLATE utf8_unicode_ci NOT NULL,';
|
||||
quotes += 'PRIMARY KEY (`id`)';
|
||||
quotes += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;';
|
||||
|
||||
// execute sql, create tables if they don't exist
|
||||
__self.execute(commands + '; ' + viewers + '; ' + scores, function(){});
|
||||
__self.execute(commands + '; ' + viewers + '; ' + scores + '; ' + quotes, function(){});
|
||||
};
|
||||
|
||||
DB.prototype.execute = function(sql, callback) {
|
||||
|
||||
Reference in new issue
Block a user