diff options
Diffstat (limited to 'commands/basic_games.py')
-rw-r--r-- | commands/basic_games.py | 148 |
1 files changed, 138 insertions, 10 deletions
diff --git a/commands/basic_games.py b/commands/basic_games.py index 0b594ba..bad02c6 100644 --- a/commands/basic_games.py +++ b/commands/basic_games.py @@ -41,15 +41,17 @@ class BasicGames(Cog): async def coin_flip(self, ctx: SlashContext, num_coins: int, choice: int): user = User.get(User.discord_id == ctx.author_id) - await ctx.send(content=f"{user.username} is betting {num_coins} coins on {choice}") - result = random.randrange(0, 1) + await ctx.send( + content=f"{user.username} is betting {num_coins} {config['currency']} on {choice}" + ) choices = ["Heads", "Tails"] - await ctx.send(content=f"Coin flip lands on {choices[result]}") - if choice == choices[result]: - await ctx.send(content=f"You win {num_coins * 2} coins!") + result = random.choice(choices) + await ctx.send(content=f"Coin flip lands on {result}") + if choice == result: + await ctx.send(content=f"You win {num_coins * 2} {config['currency']}!") user.add_coins(num_coins * 2) else: - await ctx.send(content=f"You lose {num_coins} coins :(") + await ctx.send(content=f"You lose {num_coins} {config['currency']} :(") user.remove_coins(num_coins) user.save() @@ -58,12 +60,138 @@ class BasicGames(Cog): name="dice", description="Roll some dice.", guild_ids=[config["discord_server_id"]], + options=[ + create_option( + name="num_coins", + description="coins to bet", + option_type=4, + required=True, + ), + ], ) - async def dice(self, ctx: SlashContext): - print("dice") + async def dice(self, ctx: SlashContext, num_coins: int): user = User.get(User.discord_id == ctx.author_id) - result = random.randrange(1, 6) - await ctx.send(content=f"{user.display_name}, you roll a {result}") + if user.currency < num_coins: + await ctx.send( + content=f"{user.display_name}, you don't have enough {config['currency']} for that bet" + ) + return False + + results = [ + random.randint(1, 6), + random.randint(1, 6), + random.randint(1, 6), + random.randint(1, 6), + ] + await ctx.send(content=f"{user.display_name}, you roll a {results[0]} and a {results[1]}") + + user_total = results[0] + results[1] + bot_total = results[2] + results[3] + if user_total == 12: + winnings = num_coins * 2 + await ctx.channel.send(content=f"Double 6! You win {winnings} {config['currency']}!") + user.add_coins(winnings) + elif results[0] == results[1]: + winnings = num_coins * 2 + await ctx.channel.send( + content=f"You roll a double! You win {winnings} {config['currency']}!" + ) + user.add_coins(winnings) + else: + await ctx.channel.send( + content=f"{user.display_name}, I rolled a {results[2]} and a {results[3]}" + ) + if user_total > bot_total: + await ctx.channel.send(content=f"You win {num_coins} {config['currency']}!") + user.add_coins(num_coins) + elif user_total == bot_total: + await ctx.channel.send(content="It's a draw! Have your money back...") + else: + await ctx.channel.send(content=f"You lose {num_coins} {config['currency']} :(") + user.remove_coins(num_coins) + user.save() + + @cog_ext.cog_slash( + name="slots", + description="Pull the slot machine.", + guild_ids=[config["discord_server_id"]], + ) + async def slots(self, ctx: SlashContext): + user = User.get(User.discord_id == ctx.author_id) + cost = 100 + if user.currency < cost: + await ctx.send( + content=f"{user.display_name}, you don't have enough {config['currency']}, it costs 100 {config['currency']} to play" + ) + return False + + await ctx.send( + content=f"{user.display_name}, you put {cost} {config['currency']} in the machine and pull the handle..." + ) + user.remove_coins(cost) + + results = [ + random.randint(0, 5), + random.randint(0, 5), + random.randint(0, 5), + ] + results_top = [ + random.randint(0, 5), + random.randint(0, 5), + random.randint(0, 5), + ] + results_bottom = [ + random.randint(0, 5), + random.randint(0, 5), + random.randint(0, 5), + ] + + result_text = "" + e = list(config["slots"].values()) + winnings = 0 + + for r in results_top: + result_text += e[r]["dark"] + result_text += "\n" + + for r in results: + result_text += e[r]["emoji"] + winnings += e[r]["reward_single"] + result_text += "\n" + + double = False + triple = False + if results[0] == results[1] or results[0] == results[2]: + double = True + winnings += e[results[0]]["reward_double"] + elif results[1] == results[2]: + double = True + winnings += e[results[1]]["reward_double"] + elif results[0] == results[1] and results[0] == results[2]: + triple = True + winnings += e[results[0]]["reward_triple"] + + for r in results_bottom: + result_text += e[r]["dark"] + result_text += "\n" + + await ctx.channel.send(content=result_text) + + if winnings == 0: + await ctx.channel.send(content=f"No match :( You lose {cost} {config['currency']}") + user.remove_coins(cost) + else: + if triple: + await ctx.channel.send(content=f"JACKPOT! You win {winnings} {config['currency']}") + elif double: + await ctx.channel.send( + content=f"Ding ding! You win {winnings} {config['currency']}" + ) + else: + await ctx.channel.send(content=f"You win {winnings} {config['currency']}") + user.add_coins(winnings) + + user.save() def setup(bot): |