From c1af4bcef3555061e5bbbc9db1d18f1ae83dfba5 Mon Sep 17 00:00:00 2001 From: Sabi <120003982+cyanogus@users.noreply.github.com> Date: Fri, 30 Jun 2023 08:12:05 +0000 Subject: [PATCH] Remove all `Exception` type exceptions --- cogs/economy.py | 4 --- cogs/fun.py | 1 - cogs/isocard.py | 82 ++++++++++++++++++++++------------------------ cogs/moderation.py | 8 ++--- cogs/osu.py | 26 +++++++-------- 5 files changed, 54 insertions(+), 67 deletions(-) diff --git a/cogs/economy.py b/cogs/economy.py index 7fb7654a..6ba21ca8 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -374,7 +374,6 @@ async def sell(self, ctx: ApplicationContext, name: str, quantity: int=1): localembed.set_footer(text='Thank you for your business.') await ctx.respond(embed=localembed) except KeyError: await ctx.respond('what are you doing that item doesn\'t even exist') - except Exception as e: await ctx.respond(f'An error occured while processing this request. ```{e}```') @commands.slash_command( name="gift", @@ -508,7 +507,6 @@ async def donate(self, ctx: ApplicationContext, id:str, amount): currency.add(id, amount) currency.remove(ctx.author.id, amount) except KeyError: return await ctx.respond("Unfortunately, we couldn't find that user in our database. Try double-checking the ID you've provided.", ephemeral=True) - except Exception as e: return await ctx.respond(e) localembed = discord.Embed(title="Donation Successful", description=f"You successfully donated {amount} coins to {reciever_info.name}!", color=discord.Color.green()) localembed.add_field(name="Your ID", value=ctx.author.id, inline=True) localembed.add_field(name="Reciever's ID", value=id, inline=True) @@ -656,7 +654,6 @@ async def balance(self, ctx: ApplicationContext, user=None): e.add_field(name="Networth", value=f"{currency.get_user_networth(user.id)} coin(s)", inline=True) await ctx.respond(embed=e) except: await ctx.respond('Looks like that user is not indexed in our server. Try again later.', ephemeral=True) - except Exception as e: await ctx.respond(f'An error occured: `{e}`. This has automatically been reported to the devs.') @commands.slash_command( name="treasury", @@ -694,7 +691,6 @@ async def leaderboard_nw(self, ctx: ApplicationContext): # parsed_output += f"{yf} **{user_context.name}:** {nw_dict[i]} coins\n" # y += 1 # except discord.errors.NotFound: continue - # except Exception as e: print(e) #localembed = discord.Embed(title="Global net worth leaderboard", description=parsed_output, color=color) #await ctx.respond(embed=localembed) diff --git a/cogs/fun.py b/cogs/fun.py index d627a86d..751ad220 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -30,7 +30,6 @@ async def stroketranslate(self, ctx: ApplicationContext, strok: str): s = strok.lower() for i, c in enumerate(s): var += random.choice(words[c]) return await ctx.respond(f"{var}") - except Exception as e: return await ctx.respond(f"{type(e).__name__}: {e}") var = ''.join(arr) await ctx.respond(f"{var}") diff --git a/cogs/isocard.py b/cogs/isocard.py index 543f2e09..077019a0 100644 --- a/cogs/isocard.py +++ b/cogs/isocard.py @@ -38,29 +38,27 @@ def __init__(self, bot): ) @option(name="ssc", description="The Special Security Code for your new card. (aka. CVV)", type=int) async def register(self, ctx: ApplicationContext, ssc: int): - try: - new_card_id = generate_card_id() - isocard_db[str(new_card_id)] = { - "cardholder_user_id": ctx.author.id, - "cardholder_name": ctx.author.name, - "ssc": ssc, # Special Security Code - "card_registration_timestamp": round(time.time()), - "type": "standard", # Card type - "config" : { - "spend_limit": 100000, # Daily spending limit for IsoCard - "shared_cardholder_ids": [], # Other users who can use this card - "card_label": None - } + new_card_id = generate_card_id() + isocard_db[str(new_card_id)] = { + "cardholder_user_id": ctx.author.id, + "cardholder_name": ctx.author.name, + "ssc": ssc, # Special Security Code + "card_registration_timestamp": round(time.time()), + "type": "standard", # Card type + "config" : { + "spend_limit": 100000, # Daily spending limit for IsoCard + "shared_cardholder_ids": [], # Other users who can use this card + "card_label": None } - save() - localembed = discord.Embed(title=":tada: Congratulations!", description="Your new IsoCard has successfully been registered!", color=discord.Color.green()) - localembed.add_field(name="Cardholder name", value=ctx.author.name, inline=False) - localembed.add_field(name="Card number", value=new_card_id, inline=False) - localembed.add_field(name="SSC", value=f"`{ssc}`", inline=True) - localembed.add_field(name="Card registration date", value=f"", inline=False) - localembed.set_footer(text="Always remember, NEVER share your card info to anyone!") - await ctx.respond(embed=localembed, ephemeral=True) - except Exception as e: print(e) + } + save() + localembed = discord.Embed(title=":tada: Congratulations!", description="Your new IsoCard has successfully been registered!", color=discord.Color.green()) + localembed.add_field(name="Cardholder name", value=ctx.author.name, inline=False) + localembed.add_field(name="Card number", value=new_card_id, inline=False) + localembed.add_field(name="SSC", value=f"`{ssc}`", inline=True) + localembed.add_field(name="Card registration date", value=f"", inline=False) + localembed.set_footer(text="Always remember, NEVER share your card info to anyone!") + await ctx.respond(embed=localembed, ephemeral=True) @isocard.command( name="info", @@ -93,27 +91,25 @@ async def info(self, ctx: ApplicationContext, card_number: int): description="View a list of all your cards." ) async def my_card(self, ctx: ApplicationContext): - try: - all_card_numbers = isocard_db.keys() - your_cards = list() - for card in all_card_numbers: - if isocard_db[str(card)]["cardholder_user_id"] == ctx.author.id: your_cards.append(str(card)) - embed_desc = str() - sr = 1 - for card in your_cards: - if isocard_db[str(card)]["config"]["card_label"] != None: - embed_desc += f"{sr}. **{card}**: {isocard_db[str(card)]['config']['card_label']}\n" - else: embed_desc += f"{sr}. **{card}**\n" - sr += 1 - embed_desc += "\n*Nothing more here*" - localembed = discord.Embed( - title=":credit_card: My cards", - description=embed_desc, - color=discord.Color.random() - ) - localembed.set_footer(text="Always remember, NEVER share your card info to anyone!") - await ctx.respond(embed=localembed, ephemeral=True) - except Exception as e: print(e) + all_card_numbers = isocard_db.keys() + your_cards = list() + for card in all_card_numbers: + if isocard_db[str(card)]["cardholder_user_id"] == ctx.author.id: your_cards.append(str(card)) + embed_desc = str() + sr = 1 + for card in your_cards: + if isocard_db[str(card)]["config"]["card_label"] != None: + embed_desc += f"{sr}. **{card}**: {isocard_db[str(card)]['config']['card_label']}\n" + else: embed_desc += f"{sr}. **{card}**\n" + sr += 1 + embed_desc += "\n*Nothing more here*" + localembed = discord.Embed( + title=":credit_card: My cards", + description=embed_desc, + color=discord.Color.random() + ) + localembed.set_footer(text="Always remember, NEVER share your card info to anyone!") + await ctx.respond(embed=localembed, ephemeral=True) @isocard.command( name="options_label", diff --git a/cogs/moderation.py b/cogs/moderation.py index e1e87c16..8000cdba 100644 --- a/cogs/moderation.py +++ b/cogs/moderation.py @@ -18,11 +18,9 @@ def __init__(self, bot): async def kick(self, ctx: ApplicationContext, user, reason=None): if not ctx.author.guild_permissions.kick_members: return await ctx.respond('https://tenor.com/view/oh-yeah-high-kick-take-down-fight-gif-14272509') else: - try: - if reason is None: await user.kick() - else: await user.kick(reason=reason) - await ctx.respond(embed=discord.Embed(title=f'{user} has been kicked.', description=f'Reason: {str(reason)}')) - except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red())) + if reason is None: await user.kick() + else: await user.kick(reason=reason) + await ctx.respond(embed=discord.Embed(title=f'{user} has been kicked.', description=f'Reason: {str(reason)}')) @commands.slash_command( name='ban', diff --git a/cogs/osu.py b/cogs/osu.py index dad0c8d1..6ed8cef8 100644 --- a/cogs/osu.py +++ b/cogs/osu.py @@ -42,20 +42,18 @@ async def osu_user(self, ctx, *, user:str): ) @option(name="query", description="The beatmap's id", type=int) async def osu_beatmap(self, ctx, *, query:int): - try: - beatmap = self.api.beatmap(beatmap_id=query) - e = discord.Embed(title=f'osu! beatmap info for {beatmap.expand()._beatmapset.title} ({beatmap.expand()._beatmapset.title_unicode})', color=0xff66aa) - e.set_thumbnail(url='https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Osu%21_Logo_2016.svg/2048px-Osu%21_Logo_2016.svg.png') - #.beatmap.data[0] - e.add_field(name='Artist', value=f'{beatmap.expand()._beatmapset.artist} ({beatmap.expand()._beatmapset.artist_unicode})') - e.add_field(name='Mapper', value=beatmap.expand()._beatmapset.creator) - e.add_field(name='Difficulty', value=f'{beatmap.expand().difficulty_rating} stars') - e.add_field(name='BPM', value=beatmap.expand().bpm) - e.add_field(name='Circles', value=beatmap.expand().count_circles) - e.add_field(name='Sliders', value=beatmap.expand().count_sliders) - e.add_field(name='HP Drain', value=beatmap.expand().drain) - await ctx.respond(embed=e) - except Exception as f: await ctx.respond(f"An error occured when trying to execute this command.\n```{type(f).__name__}: {f}```", ephemeral=True) + beatmap = self.api.beatmap(beatmap_id=query) + e = discord.Embed(title=f'osu! beatmap info for {beatmap.expand()._beatmapset.title} ({beatmap.expand()._beatmapset.title_unicode})', color=0xff66aa) + e.set_thumbnail(url='https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Osu%21_Logo_2016.svg/2048px-Osu%21_Logo_2016.svg.png') + #.beatmap.data[0] + e.add_field(name='Artist', value=f'{beatmap.expand()._beatmapset.artist} ({beatmap.expand()._beatmapset.artist_unicode})') + e.add_field(name='Mapper', value=beatmap.expand()._beatmapset.creator) + e.add_field(name='Difficulty', value=f'{beatmap.expand().difficulty_rating} stars') + e.add_field(name='BPM', value=beatmap.expand().bpm) + e.add_field(name='Circles', value=beatmap.expand().count_circles) + e.add_field(name='Sliders', value=beatmap.expand().count_sliders) + e.add_field(name='HP Drain', value=beatmap.expand().drain) + await ctx.respond(embed=e) # Cog Initialization def setup(bot): bot.add_cog(Osu(bot))