Browse Source

Fixing a bug where declaring an invalid bet winner wiped out the bet information.

master
Uno Polak 11 years ago
parent
commit
be552aa011
  1. 24
      lib/currency.js

24
lib/currency.js

@ -1352,10 +1352,6 @@ Currency.prototype.bets = function(status, data) {
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data});
}
}
// Clear the board
__self.bets_board = [];
__self.bets_viewers = [];
__self.bets_total = 0;
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Betting has already payed out'});
}
@ -1458,18 +1454,21 @@ Currency.prototype.bets_deduct_bets = function () {
}
__self.bets_total = 0;
// Remove the points and add them to an escrow
sql = '';
for (var i = 0; i < __self.bets_viewers.length; i++) {
if (__self.bets_viewers[i].amount > 0) {
sql = '';
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.bets_board[__self.bets_viewers[i].bet].num += 1;
__self.bets_board[__self.bets_viewers[i].bet].total += __self.bets_viewers[i].amount;
__self.bets_total += __self.bets_viewers[i].amount;
}
}
__self.db.execute(sql, function() {});
}
};
@ -1480,18 +1479,25 @@ Currency.prototype.bets_award_winner = function (winner) {
// set payout to complete
__self.bets_payout = false;
}
// Remove the points and add them to an escrow
// Payout the points
if (__self.bets_viewers.length > 0) {
sql = '';
for (var i = 0; i < __self.bets_viewers.length; i++) {
if (__self.bets_viewers[i].bet == winner.idx) {
sql = '';
if (sql.length > 0) {
sql += '; ';
}
sql += 'UPDATE viewers ';
sql += 'SET points = points + ' + Math.ceil(__self.bets_total * __self.bets_viewers[i].amount / __self.bets_board[__self.bets_viewers[i].bet].total) + ' ';
sql += 'WHERE user = \'' + __self.bets_viewers[i].viewer + '\'';
__self.db.execute(sql, function() {});
}
}
__self.db.execute(sql, function() {});
}
// Clear the board
__self.bets_board = [];
__self.bets_viewers = [];
__self.bets_total = 0;
};
module.exports = function (irc, db, options) {

Loading…
Cancel
Save