From f6d06eb489a76cae92cb525356f298285884744e Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Sun, 16 May 2021 12:15:45 +0200 Subject: [PATCH] Catch discord error, make "all" match uppercase --- cogs/bitcoin.py | 4 ++-- cogs/dinks.py | 2 +- cogs/events.py | 2 +- functions/checks.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cogs/bitcoin.py b/cogs/bitcoin.py index 14a171a..1a8bda2 100644 --- a/cogs/bitcoin.py +++ b/cogs/bitcoin.py @@ -70,7 +70,7 @@ class Bitcoin(commands.Cog): if not resp[0]: return await ctx.send(resp[1]) - if amount == "all": + if str(amount).lower() == "all": amount = resp[1] # Calculate the amount of Bitcoins the user can buy with [amount] of Didier Dinks @@ -93,7 +93,7 @@ class Bitcoin(commands.Cog): :param ctx: Discord Context :param amount: the amount of Bitcoins the user wants to sell """ - if amount == "all": + if str(amount).lower() == "all": amount = float(currency.getOrAddUser(ctx.author.id)[8]) try: diff --git a/cogs/dinks.py b/cogs/dinks.py index cae1b3f..b1a2beb 100644 --- a/cogs/dinks.py +++ b/cogs/dinks.py @@ -288,7 +288,7 @@ class Dinks(commands.Cog): await ctx.send(checks.isValidAmount(ctx, amount[0])[1]) else: user = currency.getOrAddUser(ctx.author.id) - if amount[0] == "all": + if str(amount[0]).lower() == "all": amount[0] = user[1] amount[0] = float(amount[0]) diff --git a/cogs/events.py b/cogs/events.py index ee0297f..5c25224 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -116,7 +116,7 @@ class Events(commands.Cog): elif isinstance(err, (commands.ChannelNotFound, commands.ChannelNotReadable)): await ctx.send("Geen channel gevonden dat overeenkomt met het opgegeven argument.") # Someone forgot an argument or passed an invalid argument - elif isinstance(err, (commands.BadArgument, commands.MissingRequiredArgument)): + elif isinstance(err, (commands.BadArgument, commands.MissingRequiredArgument, commands.UnexpectedQuoteError)): await ctx.send("Controleer je argumenten.") else: # Remove the InvokeCommandError because it's useless information diff --git a/functions/checks.py b/functions/checks.py index a3c82cd..0cbb042 100644 --- a/functions/checks.py +++ b/functions/checks.py @@ -55,13 +55,13 @@ def isValidAmount(ctx, amount): if not amount: return [False, "Geef een geldig bedrag op."] dinks = float(currency.dinks(ctx.author.id)) - if amount == "all": + if str(amount).lower() == "all": if dinks > 0: return [True, dinks] else: return [False, "Je hebt niet genoeg Didier Dinks om dit te doen."] # Check if it's a number <= 0 or text != all - if (all(char.isalpha() for char in str(amount)) and amount != "all") or \ + if (all(char.isalpha() for char in str(amount)) and str(amount).lower() != "all") or \ (all(char.isdigit() for char in str(abs(int(amount)))) and int(amount) <= 0): return [False, "Geef een geldig bedrag op."] if int(amount) > dinks: