Use regex match to avoid coin values less than 0.01
This commit is contained in:
parent
d89fcbfe46
commit
b369f5d6e8
1 changed files with 13 additions and 7 deletions
|
@ -83,13 +83,18 @@ class Module(object):
|
||||||
|
|
||||||
def flip(self, event):
|
def flip(self, event):
|
||||||
side_name = event["args_split"][0].lower()
|
side_name = event["args_split"][0].lower()
|
||||||
coin_bet = event["args_split"][1]
|
coin_bet = event["args_split"][1].lower()
|
||||||
|
if coin_bet == "all":
|
||||||
|
coin_bet = event["user"].get_setting("coins", "0.0")
|
||||||
|
if decimal.Decimal(coin_bet) <= DECIMAL_ZERO:
|
||||||
|
event["stderr"].write("You have no coins to bet")
|
||||||
|
return
|
||||||
|
|
||||||
if not REGEX_FLOAT.match(coin_bet) or round(decimal.Decimal(
|
match = REGEX_FLOAT.match(coin_bet)
|
||||||
coin_bet), 2) <= DECIMAL_ZERO:
|
if not match or round(decimal.Decimal(coin_bet), 2) <= DECIMAL_ZERO:
|
||||||
event["stderr"].write("Please provide a number of coins to bet")
|
event["stderr"].write("Please provide a number of coins to bet")
|
||||||
return
|
return
|
||||||
coin_bet = decimal.Decimal(coin_bet)
|
coin_bet = decimal.Decimal(match.group(0))
|
||||||
coin_bet_str = "{0:.2f}".format(coin_bet)
|
coin_bet_str = "{0:.2f}".format(coin_bet)
|
||||||
if not side_name in SIDES:
|
if not side_name in SIDES:
|
||||||
event["stderr"].write("Please provide 'heads' or 'tails'")
|
event["stderr"].write("Please provide 'heads' or 'tails'")
|
||||||
|
@ -117,12 +122,13 @@ class Module(object):
|
||||||
|
|
||||||
def send(self, event):
|
def send(self, event):
|
||||||
send_amount = event["args_split"][1]
|
send_amount = event["args_split"][1]
|
||||||
if not REGEX_FLOAT.match(send_amount) or round(decimal.Decimal(
|
match = REGEX_FLOAT.match(send_amount)
|
||||||
send_amount), 2) <= DECIMAL_ZERO:
|
if not match or round(decimal.Decimal(send_amount), 2
|
||||||
|
) <= DECIMAL_ZERO:
|
||||||
event["stderr"].write(
|
event["stderr"].write(
|
||||||
"Please provide a positive number of coins to send")
|
"Please provide a positive number of coins to send")
|
||||||
return
|
return
|
||||||
send_amount = decimal.Decimal(send_amount)
|
send_amount = decimal.Decimal(match.group(0))
|
||||||
|
|
||||||
user_coins = decimal.Decimal(event["user"].get_setting("coins",
|
user_coins = decimal.Decimal(event["user"].get_setting("coins",
|
||||||
"0.0"))
|
"0.0"))
|
||||||
|
|
Loading…
Reference in a new issue