Prevent users partaking in the lottery if doing so would put their coin total

below the coin redemption amount (coins.py)
This commit is contained in:
jesopo 2019-01-25 16:04:10 +00:00
parent d75e2452ce
commit 45f47bc3fc

View file

@ -469,9 +469,17 @@ class Module(ModuleManager.BaseModule):
user_coins = self._get_user_coins(event["user"]) user_coins = self._get_user_coins(event["user"])
coin_amount = decimal.Decimal(LOTTERY_BUYIN)*amount coin_amount = decimal.Decimal(LOTTERY_BUYIN)*amount
new_user_coins = user_coins-coin_amount
redeem_amount = self._redeem_amount(event["server"])
if coin_amount > user_coins: if coin_amount > user_coins:
raise utils.EventError("%s: You don't have enough coins" % raise utils.EventError("%s: You don't have enough coins" %
event["user"].nickname) event["user"].nickname)
elif new_user_coins < redeem_amount:
raise utils.EventError(
"%s: you can't play the lottery if it puts your total coins "
"below %s" % (event["user"].nickname,
self._coin_str(redeem_amount)))
self._take(event["server"], event["user"], coin_amount) self._take(event["server"], event["user"], coin_amount)