From fb3c2b95f89fbcff8e8866b89abeebe2d7ec8d86 Mon Sep 17 00:00:00 2001 From: JefeThePug <107787719+JefeThePug@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:57:56 +0900 Subject: [PATCH] Update general_coinflip.py Attempted to redirect all gambling to the Off Topic channel with a ping for the user. Could not test fully because I cannot connect to the db, but The message saying I do not have any points (because my wallet wasn't found in the db) was directed to Off Topic. So I think the rest of the messages in this cog will work similarly. --- src/zorak/cogs/general/general_coinflip.py | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/zorak/cogs/general/general_coinflip.py b/src/zorak/cogs/general/general_coinflip.py index 185642ce..2ff01b21 100644 --- a/src/zorak/cogs/general/general_coinflip.py +++ b/src/zorak/cogs/general/general_coinflip.py @@ -33,29 +33,35 @@ async def get_bets(self, ctx: discord.AutocompleteContext): @option("bet", description="Bet amount", autocomplete=get_bets) async def coinflip(self, ctx: discord.ApplicationContext, side: str, bet_amount: int): """Flips a coin, adds or removes points from the user based on their bet.""" + + # Get Off Topic channel for response + channel = next((c for c in ctx.guild.channels if c.name == "📁-off-topic"), None) + ping = ctx.author.mention + wallet = self.bot.db_client.get_user_points(int(ctx.user.id)) if wallet is None: # User is not yet added to the DB self.bot.db_client.add_user_to_table(ctx.author) - await ctx.respond( - "You have no points yet.\n" + await channel.send( + f"{ping}\nYou have no points yet.\n" "You can get points by chatting in the server," " or by doing things that make mods happy.") return if bet_amount < 0: - await ctx.respond("You betting negative points? You are a madman!") + await channel.send(f"{ping}\nYou betting negative points? You are a madman!") return if bet_amount == 0: - await ctx.respond("You betting zero points? You are a coward!") + await channel.send(f"{ping}\nYou betting zero points? You are a coward!") return if wallet < bet_amount: # User is trying to be a sly little fox - await ctx.respond(f"You cant bet **{bet_amount:,}** points" - f", because you only have **{wallet:,}**") + await channel.send( + f"{ping}\nYou can't bet **{bet_amount:,}** points" + f", because you only have **{wallet:,}**") return if wallet >= bet_amount: @@ -64,22 +70,19 @@ async def coinflip(self, ctx: discord.ApplicationContext, side: str, bet_amount: name = ctx.author.name if ctx.author.nick is None else ctx.author.nick if coin == side: - await ctx.respond( - f"{name} flipped a coin and chose **{side}**\n" - f"The coin landed on **{coin}**!\n" - f"You won **{bet_amount:,} points**!\n" - f"You now have **{(wallet + bet_amount):,} points!**") - self.bot.db_client.add_points_to_user(ctx.author.id, bet_amount) - return - + status = "won" + bet_result = bet_amount else: - await ctx.respond( - f"{name} flipped a coin and chose **{side}**\n" - f"The coin landed on **{coin}**!\n" - f"You lost **{bet_amount:,} points**!\n" - f"You now have **{(wallet - bet_amount):,} points**!") - self.bot.db_client.add_points_to_user(ctx.author.id, -bet_amount) - return + status = "lost" + bet_result = -bet_amount + + await channel.send( + f"{ping} flipped a coin and chose **{side}**\n" + f"The coin landed on **{coin}**!\n" + f"You {status} **{bet_amount:,} points**!\n" + f"You now have **{(wallet + bet_result):,} points!**") + self.bot.db_client.add_points_to_user(ctx.author.id, bet_result) + return def setup(bot):