2018-10-10 11:02:41 +00:00
|
|
|
import datetime, decimal, math, re, secrets, time
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import utils
|
2018-08-09 11:24:09 +00:00
|
|
|
|
|
|
|
SIDES = {"heads": 0, "tails": 1}
|
|
|
|
DEFAULT_REDEEM_DELAY = 600 # 600 seconds, 10 minutes
|
2018-08-10 11:22:41 +00:00
|
|
|
DEFAULT_REDEEM_AMOUNT = "100.0"
|
|
|
|
DEFAULT_INTEREST_RATE = "0.01"
|
2018-08-10 09:27:34 +00:00
|
|
|
INTEREST_INTERVAL = 60*60 # 1 hour
|
2018-08-10 11:22:41 +00:00
|
|
|
DECIMAL_ZERO = decimal.Decimal("0")
|
2018-10-10 11:10:53 +00:00
|
|
|
REGEX_FLOAT = re.compile("(?:\d+(?:\.\d{1,2}|$)|\.\d{1,2})")
|
2018-08-09 11:24:09 +00:00
|
|
|
|
2018-08-15 16:55:05 +00:00
|
|
|
RED = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]
|
|
|
|
BLACK = [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35]
|
|
|
|
|
2018-08-15 17:33:14 +00:00
|
|
|
SMALL = range(1, 19)
|
|
|
|
BIG = range(19, 37)
|
|
|
|
|
2018-08-15 16:55:05 +00:00
|
|
|
FIRST_DOZEN = list(range(1, 13))
|
|
|
|
SECOND_DOZEN = list(range(13, 25))
|
|
|
|
THIRD_DOZEN = list(range(25, 37))
|
|
|
|
|
|
|
|
FIRST_COLUMN = list(range(1, 37))[0::3]
|
|
|
|
SECOND_COLUMN = list(range(1, 37))[1::3]
|
|
|
|
THIRD_COLUMN = list(range(1, 37))[2::3]
|
|
|
|
|
2018-08-18 17:26:47 +00:00
|
|
|
REGEX_STREET = re.compile("street([1-9]|1[0-2])$")
|
2018-08-15 16:55:05 +00:00
|
|
|
|
2018-08-09 11:24:09 +00:00
|
|
|
class Module(object):
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-08-09 13:22:25 +00:00
|
|
|
self.bot = bot
|
2018-09-05 12:51:42 +00:00
|
|
|
|
2018-08-09 13:22:25 +00:00
|
|
|
now = datetime.datetime.now()
|
|
|
|
until_next_hour = 60-now.second
|
|
|
|
until_next_hour += ((60-(now.minute+1))*60)
|
|
|
|
|
2018-09-28 15:51:36 +00:00
|
|
|
bot.timers.add("coin-interest", INTEREST_INTERVAL,
|
|
|
|
time.time()+until_next_hour)
|
2018-08-09 13:22:25 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.coins")
|
2018-08-09 11:24:09 +00:00
|
|
|
def coins(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Show how many coins you have
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-08-09 15:37:55 +00:00
|
|
|
if event["args_split"]:
|
|
|
|
target = event["server"].get_user(event["args_split"][0])
|
|
|
|
else:
|
|
|
|
target = event["user"]
|
2018-08-10 11:22:41 +00:00
|
|
|
coins = decimal.Decimal(target.get_setting("coins", "0.0"))
|
|
|
|
event["stdout"].write("%s has %s coin%s" % (target.nickname,
|
|
|
|
"{0:.2f}".format(coins), "" if coins == 1 else "s"))
|
2018-08-09 11:24:09 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.resetcoins", min_args=1)
|
2018-08-28 11:39:16 +00:00
|
|
|
def reset_coins(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Reset a user's coins to 0
|
|
|
|
:usage: <target>
|
|
|
|
:permission: resetcoins
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-08-28 11:39:16 +00:00
|
|
|
target = event["server"].get_user(event["args_split"][0])
|
|
|
|
coins = decimal.Decimal(target.get_setting("coins", "0.0"))
|
|
|
|
if coins == DECIMAL_ZERO:
|
|
|
|
event["stderr"].write("%s already has %s coins" % (
|
|
|
|
target.nickname, str(DECIMAL_ZERO)))
|
|
|
|
else:
|
|
|
|
target.del_setting("coins")
|
|
|
|
event["stdout"].write("Reset coins for %s" % target.nickname)
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.givecoins", min_args=1)
|
2018-09-05 12:51:42 +00:00
|
|
|
def give_coins(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Give coins to a user
|
|
|
|
:usage: <nickname> <coins>
|
|
|
|
:permission: givecoins
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-05 12:51:42 +00:00
|
|
|
target = event["server"].get_user(event["args_split"][0])
|
|
|
|
coins = event["args_split"][1]
|
|
|
|
match = REGEX_FLOAT.match(coins)
|
|
|
|
if not match or round(decimal.Decimal(coins), 2) <= DECIMAL_ZERO:
|
|
|
|
event["stderr"].write(
|
|
|
|
"Please provide a positive number of coins to send")
|
|
|
|
return
|
|
|
|
coins = decimal.Decimal(match.group(0))
|
|
|
|
target_coins = decimal.Decimal(target.get_setting("coins", "0.0"))
|
|
|
|
target.set_setting("coins", str(target_coins+coins))
|
|
|
|
event["stdout"].write("Gave '%s' %s coins" % (target.nickname,
|
|
|
|
str(coins)))
|
2018-08-28 11:39:16 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.richest")
|
2018-08-09 12:49:44 +00:00
|
|
|
def richest(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Show the top 10 richest users
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-08-09 12:49:44 +00:00
|
|
|
all_coins = event["server"].get_all_user_settings("coins", [])
|
2018-08-10 11:59:06 +00:00
|
|
|
all_coins = list(filter(lambda coin: decimal.Decimal(coin[1]),
|
|
|
|
all_coins))
|
2018-08-10 11:54:19 +00:00
|
|
|
items = [(coin[0], decimal.Decimal(coin[1])) for coin in all_coins]
|
2018-08-09 12:49:44 +00:00
|
|
|
all_coins = dict(items)
|
|
|
|
|
2018-10-04 04:33:15 +00:00
|
|
|
top_10 = utils.top_10(all_coins,
|
|
|
|
convert_key=lambda nickname: utils.prevent_highlight(
|
|
|
|
event["server"].get_user(nickname).nickname),
|
|
|
|
value_format=lambda value: "{0:.2f}".format(value))
|
|
|
|
event["stdout"].write("Richest users: %s" % ", ".join(top_10))
|
2018-08-09 12:49:44 +00:00
|
|
|
|
2018-09-29 11:53:39 +00:00
|
|
|
def _redeem_cache(self, server, user):
|
|
|
|
return "redeem|%s|%s@%s" % (server.id, user.username, user.hostname)
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.redeemcoins")
|
2018-08-09 11:24:09 +00:00
|
|
|
def redeem_coins(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Redeem your free coins
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-08-10 11:22:41 +00:00
|
|
|
user_coins = decimal.Decimal(event["user"].get_setting(
|
|
|
|
"coins", "0.0"))
|
|
|
|
if user_coins == DECIMAL_ZERO:
|
2018-09-29 11:53:39 +00:00
|
|
|
cache = self._redeem_cache(event["server"], event["user"])
|
|
|
|
if not self.bot.cache.has_item(cache):
|
2018-08-10 11:22:41 +00:00
|
|
|
redeem_amount = decimal.Decimal(event["server"
|
|
|
|
].get_setting("redeem-amount", DEFAULT_REDEEM_AMOUNT))
|
|
|
|
event["user"].set_setting("coins", str(
|
|
|
|
user_coins+redeem_amount))
|
|
|
|
event["stdout"].write("Redeemed %s coins" % "{0:.2f}".format(
|
|
|
|
redeem_amount))
|
2018-09-29 11:53:39 +00:00
|
|
|
|
|
|
|
redeem_delay = event["server"].get_setting("redeem-delay",
|
|
|
|
DEFAULT_REDEEM_DELAY)
|
|
|
|
self.bot.cache.temporary_cache(cache, redeem_delay)
|
2018-08-09 11:34:12 +00:00
|
|
|
else:
|
2018-09-29 11:53:39 +00:00
|
|
|
time_left = self.bot.cache.until_expiration(cache)
|
2018-08-09 17:02:29 +00:00
|
|
|
event["stderr"].write("Please wait %s before redeeming" %
|
2018-10-03 12:22:37 +00:00
|
|
|
utils.to_pretty_time(math.ceil(time_left)))
|
2018-08-09 11:24:09 +00:00
|
|
|
else:
|
2018-08-09 11:34:12 +00:00
|
|
|
event["stderr"].write(
|
|
|
|
"You can only redeem coins when you have none")
|
2018-08-09 11:24:09 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.flip", min_args=2, authenticated=True)
|
2018-08-09 11:24:09 +00:00
|
|
|
def flip(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Bet on a coin flip
|
|
|
|
:usage: heads|tails <coin amount>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-08-09 11:24:09 +00:00
|
|
|
side_name = event["args_split"][0].lower()
|
2018-08-13 15:01:06 +00:00
|
|
|
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
|
|
|
|
|
2018-10-12 10:19:41 +00:00
|
|
|
coin_bet = utils.parse_number(coin_bet)
|
2018-08-13 15:01:06 +00:00
|
|
|
match = REGEX_FLOAT.match(coin_bet)
|
|
|
|
if not match or round(decimal.Decimal(coin_bet), 2) <= DECIMAL_ZERO:
|
2018-08-09 11:24:09 +00:00
|
|
|
event["stderr"].write("Please provide a number of coins to bet")
|
|
|
|
return
|
2018-08-13 15:01:06 +00:00
|
|
|
coin_bet = decimal.Decimal(match.group(0))
|
2018-08-10 09:28:43 +00:00
|
|
|
coin_bet_str = "{0:.2f}".format(coin_bet)
|
2018-08-09 11:24:09 +00:00
|
|
|
if not side_name in SIDES:
|
|
|
|
event["stderr"].write("Please provide 'heads' or 'tails'")
|
|
|
|
return
|
|
|
|
|
2018-08-10 11:22:41 +00:00
|
|
|
user_coins = decimal.Decimal(event["user"].get_setting(
|
|
|
|
"coins", "0.0"))
|
2018-08-09 11:24:09 +00:00
|
|
|
if coin_bet > user_coins:
|
|
|
|
event["stderr"].write("You don't have enough coins to bet")
|
|
|
|
return
|
|
|
|
|
2018-10-10 11:02:41 +00:00
|
|
|
chosen_side = secrets.choice(list(SIDES.keys()))
|
2018-08-09 11:24:09 +00:00
|
|
|
win = side_name == chosen_side
|
|
|
|
|
|
|
|
if win:
|
2018-10-11 13:13:37 +00:00
|
|
|
new_coins = str(user_coins+coin_bet)
|
|
|
|
event["user"].set_setting("coins", new_coins)
|
2018-10-10 23:26:16 +00:00
|
|
|
event["stdout"].write(
|
|
|
|
"%s flips %s and wins %s coin%s! (new total: %s)" % (
|
|
|
|
event["user"].nickname, side_name, coin_bet_str,
|
2018-10-11 13:13:37 +00:00
|
|
|
"" if coin_bet == 1 else "s", new_coins
|
2018-10-10 23:26:16 +00:00
|
|
|
)
|
|
|
|
)
|
2018-08-09 11:24:09 +00:00
|
|
|
else:
|
2018-10-11 13:13:37 +00:00
|
|
|
new_coins = str(user_coins-coin_bet)
|
|
|
|
event["user"].set_setting("coins", new_coins)
|
2018-10-10 23:26:16 +00:00
|
|
|
event["stdout"].write(
|
2018-10-11 09:35:41 +00:00
|
|
|
"%s flips %s and loses %s coin%s! (new total: %s)" % (
|
2018-10-10 23:26:16 +00:00
|
|
|
event["user"].nickname, side_name, coin_bet_str,
|
2018-10-11 13:13:37 +00:00
|
|
|
"" if coin_bet == 1 else "s", new_coins
|
2018-10-10 23:26:16 +00:00
|
|
|
)
|
|
|
|
)
|
2018-08-09 12:18:05 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.sendcoins", min_args=2, authenticated=True)
|
2018-08-09 12:18:05 +00:00
|
|
|
def send(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Send coins to another user
|
|
|
|
:usage: <nickname> <amount>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-05 12:32:21 +00:00
|
|
|
if event["user"].get_id() == event["server"].get_user(event[
|
|
|
|
"args_split"][0]).get_id():
|
2018-08-25 19:09:44 +00:00
|
|
|
event["stderr"].write("You can't send coins to yourself")
|
|
|
|
return
|
2018-08-09 12:18:05 +00:00
|
|
|
send_amount = event["args_split"][1]
|
2018-08-13 15:01:06 +00:00
|
|
|
match = REGEX_FLOAT.match(send_amount)
|
|
|
|
if not match or round(decimal.Decimal(send_amount), 2
|
|
|
|
) <= DECIMAL_ZERO:
|
2018-08-09 12:18:05 +00:00
|
|
|
event["stderr"].write(
|
|
|
|
"Please provide a positive number of coins to send")
|
|
|
|
return
|
2018-08-13 15:01:06 +00:00
|
|
|
send_amount = decimal.Decimal(match.group(0))
|
2018-08-09 12:18:05 +00:00
|
|
|
|
2018-08-10 11:22:41 +00:00
|
|
|
user_coins = decimal.Decimal(event["user"].get_setting("coins",
|
|
|
|
"0.0"))
|
|
|
|
redeem_amount = decimal.Decimal(event["server"].get_setting(
|
|
|
|
"redeem-amount", DEFAULT_REDEEM_AMOUNT))
|
|
|
|
new_user_coins = user_coins-send_amount
|
2018-08-09 12:18:05 +00:00
|
|
|
|
2018-08-10 11:22:41 +00:00
|
|
|
if new_user_coins == DECIMAL_ZERO:
|
2018-08-09 12:18:05 +00:00
|
|
|
event["stderr"].write("You have no coins")
|
|
|
|
return
|
|
|
|
elif new_user_coins < redeem_amount:
|
|
|
|
event["stderr"].write(
|
|
|
|
"You cannot send an amount of money that puts"
|
2018-08-10 09:28:43 +00:00
|
|
|
" you below %s coins" % "{0:.2f}".format(redeem_amount))
|
2018-08-09 12:18:05 +00:00
|
|
|
return
|
|
|
|
target_user = event["server"].get_user(event["args_split"][0])
|
2018-08-28 11:45:42 +00:00
|
|
|
target_user_coins = target_user.get_setting("coins", None)
|
|
|
|
if target_user_coins == None:
|
|
|
|
event["stderr"].write("You can only send coins to users that "
|
|
|
|
"have had coins before")
|
|
|
|
return
|
|
|
|
|
2018-08-10 11:22:41 +00:00
|
|
|
event["user"].set_setting("coins", str(new_user_coins))
|
2018-09-05 11:58:30 +00:00
|
|
|
# get target_user_coins again, just in case *somehow* someone's
|
|
|
|
# sending coins to themselves.
|
|
|
|
target_user_coins = target_user.get_setting("coins", None)
|
|
|
|
target_user_coins = decimal.Decimal(target_user_coins)
|
|
|
|
|
2018-08-10 11:22:41 +00:00
|
|
|
target_user.set_setting("coins", str(target_user_coins+send_amount))
|
2018-08-09 12:18:05 +00:00
|
|
|
|
2018-08-10 09:28:43 +00:00
|
|
|
event["stdout"].write("%s sent %s coins to %s" % (
|
|
|
|
event["user"].nickname, "{0:.2f}".format(send_amount),
|
|
|
|
target_user.nickname))
|
2018-08-09 13:22:25 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("timer.coin-interest")
|
2018-08-09 13:22:25 +00:00
|
|
|
def interest(self, event):
|
|
|
|
for server in self.bot.servers.values():
|
2018-08-09 14:16:15 +00:00
|
|
|
all_coins = server.get_all_user_settings(
|
2018-08-09 13:22:25 +00:00
|
|
|
"coins", [])
|
2018-08-10 11:22:41 +00:00
|
|
|
interest_rate = decimal.Decimal(server.get_setting(
|
|
|
|
"interest-rate", DEFAULT_INTEREST_RATE))
|
|
|
|
redeem_amount = decimal.Decimal(server.get_setting(
|
|
|
|
"redeem-amount", DEFAULT_REDEEM_AMOUNT))
|
2018-08-09 13:22:25 +00:00
|
|
|
for nickname, coins in all_coins:
|
2018-08-10 11:22:41 +00:00
|
|
|
coins = decimal.Decimal(coins)
|
2018-08-09 13:22:25 +00:00
|
|
|
if coins > redeem_amount:
|
2018-08-10 09:28:43 +00:00
|
|
|
coins += round(coins*interest_rate, 2)
|
2018-08-10 11:22:41 +00:00
|
|
|
server.get_user(nickname).set_setting("coins",
|
|
|
|
str(coins))
|
2018-08-09 17:02:29 +00:00
|
|
|
event["timer"].redo()
|
2018-08-15 16:55:05 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.roulette", min_args=2, authenticated=True)
|
2018-08-15 16:55:05 +00:00
|
|
|
def roulette(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Spin a roulette wheel
|
|
|
|
:usage: <type> <amount>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-08-16 10:54:51 +00:00
|
|
|
bets = event["args_split"][0].lower().split(",")
|
|
|
|
if "0" in bets:
|
2018-08-15 16:55:05 +00:00
|
|
|
event["stderr"].write("You can't bet on 0")
|
|
|
|
return
|
2018-08-16 10:54:51 +00:00
|
|
|
bet_amounts = [amount.lower() for amount in event["args_split"][1:]]
|
2018-08-18 17:26:47 +00:00
|
|
|
if len(bet_amounts) < len(bets):
|
|
|
|
event["stderr"].write("Please provide an amount for each bet")
|
|
|
|
return
|
2018-08-16 10:54:51 +00:00
|
|
|
if len(bet_amounts) == 1 and bet_amounts[0] == "all":
|
|
|
|
bet_amounts[0] = event["user"].get_setting("coins", "0.0")
|
|
|
|
if decimal.Decimal(bet_amounts[0]) <= DECIMAL_ZERO:
|
2018-08-15 16:55:05 +00:00
|
|
|
event["stderr"].write("You have no coins to bet")
|
|
|
|
return
|
|
|
|
|
2018-08-16 10:54:51 +00:00
|
|
|
for i, bet_amount in enumerate(bet_amounts):
|
2018-10-12 10:19:41 +00:00
|
|
|
bet_amount = utils.parse_number(bet_amount)
|
2018-08-16 10:54:51 +00:00
|
|
|
match = REGEX_FLOAT.match(bet_amount)
|
|
|
|
if not match or round(decimal.Decimal(bet_amount), 2
|
|
|
|
) <= DECIMAL_ZERO:
|
|
|
|
event["stderr"].write(
|
|
|
|
"Please provide a positive number of coins to bet")
|
|
|
|
return
|
|
|
|
bet_amounts[i] = decimal.Decimal(match.group(0))
|
|
|
|
bet_amount_total = sum(bet_amounts)
|
2018-08-15 16:55:05 +00:00
|
|
|
|
|
|
|
user_coins = decimal.Decimal(event["user"].get_setting("coins",
|
|
|
|
"0.0"))
|
2018-08-16 10:54:51 +00:00
|
|
|
if bet_amount_total > user_coins:
|
2018-08-15 16:55:05 +00:00
|
|
|
event["stderr"].write("You don't have enough coins to bet")
|
|
|
|
return
|
|
|
|
|
|
|
|
# black, red, odds, evens, high (1-18), low (19-36)
|
|
|
|
# 1dozen (1-12), 2dozen (13-24), 3dozen (25-36)
|
|
|
|
# 1column (1,4..34), 2column (2,5..35), 3column (3,6..36)
|
2018-10-10 17:12:54 +00:00
|
|
|
choice = secrets.randbelow(37)
|
2018-08-16 10:54:51 +00:00
|
|
|
winnings = {}
|
|
|
|
losses = {}
|
2018-08-15 16:55:05 +00:00
|
|
|
if choice == 0:
|
2018-08-16 10:54:51 +00:00
|
|
|
loss = sum(bet_amounts)
|
|
|
|
event["user"].set_setting("coins", str(user_coins-loss))
|
2018-08-15 16:55:05 +00:00
|
|
|
event["stdout"].write("Roulette spin lands on 0, "
|
|
|
|
"the house wins, %s loses %s" % (
|
2018-08-16 10:54:51 +00:00
|
|
|
event["user"].nickname, loss))
|
2018-08-15 16:55:05 +00:00
|
|
|
return
|
2018-08-16 10:54:51 +00:00
|
|
|
|
|
|
|
failed = False
|
2018-08-18 17:26:47 +00:00
|
|
|
colour = "red" if choice in RED else "black"
|
2018-08-16 10:54:51 +00:00
|
|
|
for i, bet in enumerate(bets):
|
|
|
|
street_match = REGEX_STREET.match(bet)
|
|
|
|
odds = 0
|
|
|
|
if bet == "even":
|
|
|
|
odds = 1*((choice % 2) == 0)
|
|
|
|
elif bet == "odd":
|
|
|
|
odds = 1*((choice % 2) == 1)
|
|
|
|
elif bet == "red":
|
|
|
|
odds = 1*(choice in RED)
|
|
|
|
elif bet == "black":
|
|
|
|
odds = 1*(choice in BLACK)
|
2018-08-18 17:26:47 +00:00
|
|
|
elif bet == "small" or bet == "low":
|
2018-08-16 10:54:51 +00:00
|
|
|
odds = 1*(choice in SMALL)
|
2018-08-18 17:26:47 +00:00
|
|
|
elif bet == "big" or bet == "high":
|
2018-08-16 10:54:51 +00:00
|
|
|
odds = 1*(choice in BIG)
|
|
|
|
elif bet == "dozen1":
|
|
|
|
odds = 2*(choice in FIRST_DOZEN)
|
|
|
|
elif bet == "dozen2":
|
|
|
|
odds = 2*(choice in SECOND_DOZEN)
|
|
|
|
elif bet == "dozen3":
|
|
|
|
odds = 2*(choice in THIRD_DOZEN)
|
|
|
|
elif bet == "column1":
|
|
|
|
odds = 2*(choice in FIRST_COLUMN)
|
|
|
|
elif bet == "column2":
|
|
|
|
odds = 2*(choice in SECOND_COLUMN)
|
|
|
|
elif bet == "column3":
|
|
|
|
odds = 2*(choice in THIRD_COLUMN)
|
|
|
|
elif street_match:
|
|
|
|
row = int(street_match.group(1))
|
|
|
|
odds = 11*(((row*3)-2) <= choice <= (row*3))
|
|
|
|
elif bet.isdigit() and (1 <= int(bet) <= 36):
|
|
|
|
odds = 35*(choice == int(bet))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Unknown bet")
|
|
|
|
failed = True
|
|
|
|
break
|
|
|
|
if odds == 0:
|
|
|
|
losses[bet] = bet_amounts[i]
|
|
|
|
else:
|
|
|
|
winnings[bet] = [odds, bet_amounts[i]*odds]
|
|
|
|
if failed:
|
2018-08-15 16:55:05 +00:00
|
|
|
return
|
|
|
|
|
2018-08-16 10:54:51 +00:00
|
|
|
winnings_str = ["%s for %s (%d to 1)" % (winnings[bet][1], bet,
|
|
|
|
winnings[bet][0]) for bet in winnings.keys()]
|
|
|
|
|
|
|
|
coin_winnings = sum(bet[1] for bet in winnings.values())
|
|
|
|
coin_losses = sum([loss for loss in losses.values()])
|
2018-08-18 17:26:47 +00:00
|
|
|
total_winnings_str = " (%s total)" % coin_winnings if len(
|
|
|
|
winnings.keys()) > 1 else ""
|
2018-08-16 10:54:51 +00:00
|
|
|
|
|
|
|
new_user_coins = (user_coins-coin_losses)+coin_winnings
|
|
|
|
event["user"].set_setting("coins", str(new_user_coins))
|
2018-08-18 17:26:47 +00:00
|
|
|
|
|
|
|
choice = "%d %s" % (choice, colour)
|
2018-08-16 10:54:51 +00:00
|
|
|
if not losses and winnings:
|
2018-08-18 17:26:47 +00:00
|
|
|
event["stdout"].write("Roulette spin lands on %s, "
|
|
|
|
"%s wins %s%s" % (choice, event["user"].nickname,
|
|
|
|
", ".join(winnings_str), str(total_winnings_str)))
|
2018-08-16 10:54:51 +00:00
|
|
|
elif losses and winnings:
|
2018-08-18 17:26:47 +00:00
|
|
|
event["stdout"].write("Roulette spin lands on %s, "
|
|
|
|
"%s wins %s%s; loses %s" % (choice,
|
|
|
|
event["user"].nickname, ", ".join(winnings_str),
|
|
|
|
str(total_winnings_str), str(coin_losses)))
|
2018-08-15 16:55:05 +00:00
|
|
|
else:
|
2018-08-18 17:26:47 +00:00
|
|
|
event["stdout"].write("Roulette spin lands on %s, "
|
2018-08-16 10:54:51 +00:00
|
|
|
"%s loses %s" % (choice, event["user"].nickname,
|
|
|
|
str(coin_losses)))
|