Browse Source

Added a bet cancel command.

master
Uno Polak 11 years ago
parent
commit
bd43392082
  1. 32
      lib/currency.js

32
lib/currency.js

@ -222,6 +222,9 @@ Currency.prototype.commands = function (data) {
case 'winner': case 'winner':
__self.bets('winner', data[6]); __self.bets('winner', data[6]);
break; break;
case 'cancel':
__self.bets('cancel');
break;
} }
} }
@ -1359,6 +1362,35 @@ Currency.prototype.bets = function(status, data) {
__self.irc.emit('message', {message:__self.pre_text + 'Betting must be closed before you can have a winner'}); __self.irc.emit('message', {message:__self.pre_text + 'Betting must be closed before you can have a winner'});
} }
break; break;
case 'cancel':
if (!__self.bets_status) {
// Return all the currency back to original owners
if (__self.bets_payout) {
sql = '';
for (var i = 0; i < __self.bets_viewers.length; i++) {
if (__self.bets_viewers[i].amount > 0) {
if (sql.length > 0) {
sql += '; ';
}
sql += 'UPDATE viewers ';
sql += 'SET points = points + ' + __self.bets_viewers[i].amount + ' ';
sql += 'WHERE user = \'' + __self.bets_viewers[i].viewer + '\'';
}
}
__self.db.execute(sql, function() {
__self.irc.emit('message', {message:__self.pre_text + 'Bet was canceled, all ' + __self.config.currency.toLowerCase() + ' returned.'});
});
__self.bets_payout = false;
// Or just cancel the bets
} else {
__self.irc.emit('message', {message:__self.pre_text + 'No bet to cancel.'});
}
} else {
__self.bets_status = false;
__self.bets_payout = false;
__self.irc.emit('message', {message:__self.pre_text + 'Current bet was canceled.'});
}
break;
} }
}; };

Loading…
Cancel
Save