@ -63,11 +63,12 @@ var https = require('https'),
utils = require ( './utils.js' ) ;
utils = require ( './utils.js' ) ;
//-------- Construct ---------
//-------- Construct ---------
function Currency ( irc , db , options ) {
function Currency ( irc , db , commands , options ) {
var __self = this ;
var __self = this ;
__self . irc = irc ;
__self . irc = irc ;
__self . db = db ;
__self . db = db ;
__self . custom_commands = commands ;
// config
// config
__self . config = options || { } ;
__self . config = options || { } ;
@ -136,6 +137,10 @@ function Currency(irc, db, options) {
// high score table
// high score table
__self . score_bet_pool = 0 ;
__self . score_bet_pool = 0 ;
__self . score_bet_single = 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 ---------
//-------- Methods ---------
@ -173,6 +178,20 @@ Currency.prototype.commands = function (data) {
// broadcaster only commands
// broadcaster only commands
if ( broadcaster_bot_initiated || ( __self . config . modpowers && moderator_initiated ) ) {
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
//open / close auction system
if ( data [ 4 ] === 'auction' ) {
if ( data [ 4 ] === 'auction' ) {
switch ( data [ 5 ] ) {
switch ( data [ 5 ] ) {
@ -1551,8 +1570,17 @@ Currency.prototype.bets = function(status, data) {
if ( __self . bets_viewers . length > 0 ) {
if ( __self . bets_viewers . length > 0 ) {
__self . irc . emit ( 'message' , { message : __self . pre_text + 'Betting is now closed' } ) ;
__self . irc . emit ( 'message' , { message : __self . pre_text + 'Betting is now closed' } ) ;
for ( var i = 0 ; i < __self . bets_board . length ; i ++ ) {
for ( var i = 0 ; i < __self . bets_board . length ; i ++ ) {
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 } ) ;
__self . irc . emit ( 'message' , { message : '+ ' + __self . bets_board [ i ] . name + ' with ' + __self . bets_board [ i ] . num + ' bets totaling ' + __self . bets_board [ i ] . total } ) ;
}
}
}
//
} else {
} else {
__self . irc . emit ( 'message' , { message : __self . pre_text + 'Betting closed, no bets were placed' } ) ;
__self . irc . emit ( 'message' , { message : __self . pre_text + 'Betting closed, no bets were placed' } ) ;
}
}
@ -1581,17 +1609,9 @@ Currency.prototype.bets = function(status, data) {
for ( var i = 0 ; i < __self . bets_board . length ; i ++ ) {
for ( var i = 0 ; i < __self . bets_board . length ; i ++ ) {
if ( data == __self . bets_board [ i ] . name ) {
if ( data == __self . bets_board [ i ] . name ) {
__self . bets_award_winner ( __self . bets_board [ i ] ) ;
__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 {
} else {
__self . irc . emit ( 'message' , { message : __self . pre_text + 'Betting has already payed out' } ) ;
__self . irc . emit ( 'message' , { message : __self . pre_text + 'Betting has already payed out' } ) ;
}
}
@ -1646,12 +1666,22 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
for ( var i = 0 ; i < __self . bets_flood . length ; i ++ ) {
for ( var i = 0 ; i < __self . bets_flood . length ; i ++ ) {
bet = __self . bets_viewers [ __self . bets_flood [ i ] ] ;
bet = __self . bets_viewers [ __self . bets_flood [ i ] ] ;
multi_response [ bet . bet ] . push ( bet . viewer + ' (' + bet . amount + ')' ) ;
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 ++ ) {
for ( var i = 0 ; i < __self . bets_board . length ; i ++ ) {
if ( multi_response [ i ] . length > 0 ) {
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 } ) ;
__self . irc . emit ( 'message' , { message : 'New bets for ' + __self . bets_board [ i ] . name + ': ' + multi_response [ i ] . join ( ', ' ) , timer : 1 } ) ;
}
}
}
}
}
}
// clear flood requests
// clear flood requests
@ -1664,15 +1694,6 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
amount = Math . min ( amount , rows [ i ] . points ) ;
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 ) {
if ( __self . bets_viewers . length > 0 ) {
for ( var i = 0 ; i < __self . bets_viewers . length ; i ++ ) {
for ( var i = 0 ; i < __self . bets_viewers . length ; i ++ ) {
if ( __self . bets_viewers [ i ] . viewer === caller ) {
if ( __self . bets_viewers [ i ] . viewer === caller ) {
@ -1779,6 +1800,6 @@ Currency.prototype.bets_award_winner = function (winner) {
__self . bets_total = 0 ;
__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 ) ;
} ;
} ;