aboutsummaryrefslogtreecommitdiff
path: root/modules/coins.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-08-13 16:01:06 +0100
committerGravatar jesopo2018-08-13 16:01:06 +0100
commitb369f5d6e81308d586244603c9a3bf1f765dd340 (patch)
tree7c30ef6bc79b383a895c1d061fee1919708e045c /modules/coins.py
parentRound up when checking zeroness (diff)
signature
Use regex match to avoid coin values less than 0.01
Diffstat (limited to 'modules/coins.py')
-rw-r--r--modules/coins.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/modules/coins.py b/modules/coins.py
index d8aec3f3..e155be91 100644
--- a/modules/coins.py
+++ b/modules/coins.py
@@ -83,13 +83,18 @@ class Module(object):
def flip(self, event):
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(
- coin_bet), 2) <= DECIMAL_ZERO:
+ match = REGEX_FLOAT.match(coin_bet)
+ if not match or round(decimal.Decimal(coin_bet), 2) <= DECIMAL_ZERO:
event["stderr"].write("Please provide a number of coins to bet")
return
- coin_bet = decimal.Decimal(coin_bet)
+ coin_bet = decimal.Decimal(match.group(0))
coin_bet_str = "{0:.2f}".format(coin_bet)
if not side_name in SIDES:
event["stderr"].write("Please provide 'heads' or 'tails'")
@@ -117,12 +122,13 @@ class Module(object):
def send(self, event):
send_amount = event["args_split"][1]
- if not REGEX_FLOAT.match(send_amount) or round(decimal.Decimal(
- send_amount), 2) <= DECIMAL_ZERO:
+ match = REGEX_FLOAT.match(send_amount)
+ if not match or round(decimal.Decimal(send_amount), 2
+ ) <= DECIMAL_ZERO:
event["stderr"].write(
"Please provide a positive number of coins to send")
return
- send_amount = decimal.Decimal(send_amount)
+ send_amount = decimal.Decimal(match.group(0))
user_coins = decimal.Decimal(event["user"].get_setting("coins",
"0.0"))