Browse Source

Custom commands working. addcmd/removecmd <trigger> <text>

doobs
Brandon Cornejo 11 years ago
parent
commit
ccf9ff5534
  1. 12
      .gitignore
  2. 66
      lib/commands.js
  3. 65
      lib/currency.js
  4. 2
      lib/initialize.js
  5. 4
      lib/mysql.js
  6. 20
      web/public/css/app.css

12
.gitignore

@ -180,4 +180,14 @@ JsonParser.js
KarmaBot.js
Knowledge_Bot.js
WizardBot.js
XBucksBot.js
XBucksBot.js
#me me me
shaneomad.js
pyrionflax.js
testbot.js
*.png
web/public/browserconfig.xml
node_modules/.bin
web/public/favicon.ico
web/public/statistics

66
lib/commands.js

@ -51,14 +51,17 @@ Commands.prototype.commands = function(data) {
for (var i = 0; i < rows.length; i++) {
// match db command with called command
if (rows[i].command = command) {
/*
// display based on viewer auth
if (rows[i].auth === 1) {
__self.irc.emit('message',{message:rows[i].text, options:{caller: __self.irc.caller(data[0]), auth: 1}});
__self.irc.emit('message',{message:'> '+rows[i].text, options:{caller: __self.irc.caller(data[0]), auth: 1}});
break;
} else if (rows[i].auth === 0) {
__self.irc.emit('message',{message:rows[i].text, options:null});
__self.irc.emit('message',{message:'> '+rows[i].text, options:null});
break;
}
*/
__self.irc.emit('message',{message:'> '+rows[i].text, options:null});
}
}
});
@ -71,10 +74,65 @@ Commands.prototype.commands = function(data) {
commands += '!' + __self.command_list[i];
}
}
__self.irc.emit('message',{message:commands, options:{caller: __self.irc.caller(data[0]), auth: 1}});
console.log("!!!!! Right before EMIT");
__self.irc.emit('message',{message:commands, options:null});
}
};
Commands.prototype.add = function(command, text) {
var __self = this;
// escape string for sql sanity
var txt = text.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function(char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
case "'":
case "\\":
case "%":
return "\\"+char;
}
});
var sql = 'INSERT INTO commands (command, text) VALUES (\''+command+'\', \''+txt+'\');';
// add the command to the database
__self.db.execute(sql, function(data) {
var message = '> Add Command: !' + command + ' has been added.';
__self.command_list.push(command);
__self.irc.emit('message',{message:message, options:null});
});
};
Commands.prototype.remove = function(command) {
var __self = this,
index = __self.command_list.indexOf(command);
if( index >= 0) {
var sql = 'DELETE FROM commands WHERE command=\''+command+'\';';
// remove the command from the database
__self.db.execute(sql, function(data) {
var message = '> Delete Command: !' + command + ' has been removed.';
__self.command_list.splice(index, 1);
__self.irc.emit('message',{message:message, options:null});
});
}
};
module.exports = function(irc, db, options) {
return new Commands(irc, db, options);
};
};

65
lib/currency.js

@ -63,11 +63,12 @@ var https = require('https'),
utils = require('./utils.js');
//-------- Construct ---------
function Currency(irc, db, options) {
function Currency(irc, db, commands, options) {
var __self = this;
__self.irc = irc;
__self.db = db;
__self.custom_commands = commands;
// config
__self.config = options || {};
@ -136,6 +137,10 @@ function Currency(irc, db, options) {
// high score table
__self.score_bet_pool = 0;
__self.score_bet_single = 0;
// commands add/rem settings
__self.command_add_string = options.add_command || 'addcmd';
__self.command_remove_string = options.remove_command || 'removecmd';
}
//-------- Methods ---------
@ -173,6 +178,20 @@ Currency.prototype.commands = function (data) {
// broadcaster only commands
if (broadcaster_bot_initiated || (__self.config.modpowers && moderator_initiated)) {
//add / remove custom commands
if (data[4] === __self.command_add_string && data[5] !== undefined && data[6] !== undefined) {
var command = data[5];
var text = data.slice(6);
text = text.join(' ');
__self.custom_commands.add(command, text);
}
if (data[4] === __self.command_remove_string && data[5] !== undefined) {
var command = data[5];
__self.custom_commands.remove(command);
}
//open / close auction system
if (data[4] === 'auction') {
switch (data[5]) {
@ -1551,8 +1570,17 @@ Currency.prototype.bets = function(status, data) {
if (__self.bets_viewers.length > 0) {
__self.irc.emit('message', {message:__self.pre_text + 'Betting is now closed'});
for (var i = 0; i < __self.bets_board.length; i++) {
__self.irc.emit('message', {message:'+ ' + __self.bets_board[i].name + ' with ' + __self.bets_board[i].num + ' bets totaling ' + __self.bets_board[i].total});
if(parseInt(__self.bets_board[i].total,10) > parseInt(__self.score_bet_pool, 10)) {
__self.score_bet_pool = __self.bets_board[i].total;
sql = 'INSERT INTO highscores (`value`, `name`) VALUES (\'' + __self.bets_board[i].total + '\', \'bet_pool\') ON DUPLICATE KEY UPDATE value=values(value);';
__self.db.execute(sql, function() {});
__self.irc.emit('message', {message:'+ ' + __self.bets_board[i].name + ' with ' + __self.bets_board[i].num + ' bets totaling ' + __self.bets_board[i].total + '. New record set!!'});
} else {
__self.irc.emit('message', {message:'+ ' + __self.bets_board[i].name + ' with ' + __self.bets_board[i].num + ' bets totaling ' + __self.bets_board[i].total});
}
}
//
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Betting closed, no bets were placed'});
}
@ -1581,15 +1609,7 @@ Currency.prototype.bets = function(status, data) {
for (var i = 0; i < __self.bets_board.length; i++) {
if (data == __self.bets_board[i].name) {
__self.bets_award_winner(__self.bets_board[i]);
if(__self.bets_board[i].total > __self.score_bet_pool) {
sql = 'UPDATE highscores SET value = ' + __self.bets_board[i].total + ' WHERE name = \'bet_pool\'';
__self.db.execute(sql, function() {
__self.score_bet_pool = __self.bets_board[i].total;
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data + '. New record set!!'});
});
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data});
}
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data});
}
}
} else {
@ -1646,12 +1666,22 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
for (var i = 0; i < __self.bets_flood.length; i++) {
bet = __self.bets_viewers[__self.bets_flood[i]];
multi_response[bet.bet].push(bet.viewer + ' (' + bet.amount + ')');
// check for hiscore and set db appropriately
if ( parseInt(bet.amount, 10) > parseInt(__self.score_bet_single, 10) ) {
sql = 'INSERT INTO highscores (`value`, `user`, `name`) VALUES (\'' + amount + '\', \'' + caller + '\', \'bet_single\') ON DUPLICATE KEY UPDATE user=values(user), value=values(value);';
__self.db.execute(sql, function() {
__self.score_bet_single = amount;
__self.irc.emit('message', {message:__self.pre_text + ' ' + caller + ' set new record bet at ' + amount + '!'});
});
}
}
for (var i = 0; i < __self.bets_board.length; i++) {
if (multi_response[i].length > 0) {
__self.irc.emit('message', {message:'New bets for ' + __self.bets_board[i].name + ': ' + multi_response[i].join(', '), timer: 1});
}
}
}
// clear flood requests
@ -1664,15 +1694,6 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
amount = Math.min(amount, rows[i].points);
}
// check for hiscore and set db appropriately
if(amount > __self.score_bet_single) {
sql = 'UPDATE highscores SET value = ' + amount + ' WHERE name = \'bet_single\'';
__self.db.execute(sql, function() {
__self.score_bet_single = amount;
__self.irc.emit('message', {message:__self.pre_text + ' ' + caller + ' set new record bet at ' + amount + '!'});
});
}
if (__self.bets_viewers.length > 0) {
for (var i = 0; i < __self.bets_viewers.length; i++) {
if (__self.bets_viewers[i].viewer === caller) {
@ -1779,6 +1800,6 @@ Currency.prototype.bets_award_winner = function (winner) {
__self.bets_total = 0;
};
module.exports = function (irc, db, options) {
return new Currency(irc, db, options);
module.exports = function (irc, db, commands, options) {
return new Currency(irc, db, commands, options);
};

2
lib/initialize.js

@ -31,7 +31,7 @@ exports.initialize = function(options) {
bot_name : config.twitch.bot.name,
currency : config.currency.name
});
currency = require('./currency.js')(irc, db, {
currency = require('./currency.js')(irc, db, commands, {
currency : config.currency.name,
payrate : config.currency.payrate,
subscribers : config.twitch.subscribers,

4
lib/mysql.js

@ -49,11 +49,11 @@ DB.prototype.start = function() {
// table structure for table highscores
scores += 'CREATE TABLE IF NOT EXISTS `highscores` (';
scores += '`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,';
scores += '`user` varchar(64) COLLATE utf8_unicode_ci,';
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 += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_single\', 0);';
//scores += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_pool\', 0);';
// execute sql, create tables if they don't exist
__self.execute(commands + '; ' + viewers + '; ' + scores, function(){});

20
web/public/css/app.css

@ -0,0 +1,20 @@
.uk-navbar-nav > li {
display: inline-block;
float: none;
}
.uk-navbar-nav > li > a > img {
width: 20px;
}
.flip {
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
.uk-search-field, .uk-search-field::-moz-placeholder {
color: #FFFFFF;
}
Loading…
Cancel
Save