Only allow !redeemcoins when you have no coins
This commit is contained in:
parent
7c1fce17cd
commit
beb2b4a606
1 changed files with 20 additions and 12 deletions
|
@ -3,6 +3,7 @@ import Utils
|
||||||
|
|
||||||
SIDES = {"heads": 0, "tails": 1}
|
SIDES = {"heads": 0, "tails": 1}
|
||||||
DEFAULT_REDEEM_DELAY = 600 # 600 seconds, 10 minutes
|
DEFAULT_REDEEM_DELAY = 600 # 600 seconds, 10 minutes
|
||||||
|
DEFAULT_REDEEM_AMOUNT = 100
|
||||||
|
|
||||||
class Module(object):
|
class Module(object):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -21,13 +22,17 @@ class Module(object):
|
||||||
"" if coins == 1 else "s"))
|
"" if coins == 1 else "s"))
|
||||||
|
|
||||||
def redeem_coins(self, event):
|
def redeem_coins(self, event):
|
||||||
|
user_coins = event["user"].get_setting("coins", 0)
|
||||||
|
if user_coins == 0:
|
||||||
last_redeem = event["user"].get_setting("last-redeem", None)
|
last_redeem = event["user"].get_setting("last-redeem", None)
|
||||||
redeem_delay = event["server"].get_setting("redeem-delay",
|
redeem_delay = event["server"].get_setting("redeem-delay",
|
||||||
DEFAULT_REDEEM_DELAY)
|
DEFAULT_REDEEM_DELAY)
|
||||||
|
|
||||||
if last_redeem == None or (time.time()-last_redeem) >= redeem_delay:
|
if last_redeem == None or (time.time()-last_redeem
|
||||||
|
) >= redeem_delay:
|
||||||
user_coins = event["user"].get_setting("coins", 0)
|
user_coins = event["user"].get_setting("coins", 0)
|
||||||
redeem_amount = event["server"].get_setting("redeem-amount", 100)
|
redeem_amount = event["server"].get_setting(
|
||||||
|
"redeem-amount", DEFAULT_REDEEM_AMOUNT)
|
||||||
event["user"].set_setting("coins", user_coins+redeem_amount)
|
event["user"].set_setting("coins", user_coins+redeem_amount)
|
||||||
event["stdout"].write("Redeemed %d coins" % redeem_amount)
|
event["stdout"].write("Redeemed %d coins" % redeem_amount)
|
||||||
event["user"].set_setting("last-redeem", time.time())
|
event["user"].set_setting("last-redeem", time.time())
|
||||||
|
@ -35,6 +40,9 @@ class Module(object):
|
||||||
time_left = (last_redeem+redeem_delay)-time.time()
|
time_left = (last_redeem+redeem_delay)-time.time()
|
||||||
event["stdout"].write("Please wait %s before redeeming" %
|
event["stdout"].write("Please wait %s before redeeming" %
|
||||||
Utils.to_pretty_time(time_left))
|
Utils.to_pretty_time(time_left))
|
||||||
|
else:
|
||||||
|
event["stderr"].write(
|
||||||
|
"You can only redeem coins when you have none")
|
||||||
|
|
||||||
def flip(self, event):
|
def flip(self, event):
|
||||||
side_name = event["args_split"][0].lower()
|
side_name = event["args_split"][0].lower()
|
||||||
|
|
Loading…
Reference in a new issue