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