From aad91a60f5d6011dfe43b2f88a48e6ac43282eea Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Tue, 22 Jun 2021 05:41:25 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- cogs/Fun.py | 80 +++++++++++++++++++++++++-------------------------- cogs/Help.py | 19 +++++------- cogs/Utils.py | 68 ++++++++++++------------------------------- 3 files changed, 65 insertions(+), 102 deletions(-) diff --git a/cogs/Fun.py b/cogs/Fun.py index 0f1fa2e..4d076dc 100644 --- a/cogs/Fun.py +++ b/cogs/Fun.py @@ -24,29 +24,29 @@ def __init__(self, bot): @commands.command(name='8ball') @cooldown(1,5,BucketType.channel) async def eight_ball(self, ctx, *, question=None): - responses = ["It is certain.", - "It is decidedly so.", - "Without a doubt.", - "Yes - definitely.", - "You may rely on it.", - "As I see it, yes.", - "Most likely.", - "Outlook good.", - "Yes.", - "Signs point to yes.", - "Reply hazy, try again.", - "Ask again later.", - "Better not tell you now.", - "Cannot predict now.", - "Concentrate and ask again.", - "Don't count on it.", - "My reply is no.", - "My sources say no.", - "Outlook not so good.", - "Very doubtful." - ] - if question is not None: + responses = ["It is certain.", + "It is decidedly so.", + "Without a doubt.", + "Yes - definitely.", + "You may rely on it.", + "As I see it, yes.", + "Most likely.", + "Outlook good.", + "Yes.", + "Signs point to yes.", + "Reply hazy, try again.", + "Ask again later.", + "Better not tell you now.", + "Cannot predict now.", + "Concentrate and ask again.", + "Don't count on it.", + "My reply is no.", + "My sources say no.", + "Outlook not so good.", + "Very doubtful." + ] + embed = discord.Embed(title='*The 8ball*', description=f'**{ctx.message.author}** asked a question.\n\nThe question was: **{question}**\n\n\n{random.choice(responses)}', colour=0x0000ff) await ctx.send(embed=embed) else: @@ -167,12 +167,10 @@ async def cat_picture_error(self, ctx, error): @commands.command(name='fact', aliases=['facts']) async def animal_facts(self, ctx, animal:str): - colour_choices= [0x400000,0x997379,0xeb96aa,0x4870a0,0x49a7c3,0x8b3a3a,0x1e747c,0x0000ff] - if animal.lower() in {'dog', 'cat', 'bird', 'birb', 'koala', 'panda'}: fact_url = f"https://some-random-api.ml/facts/{'bird' if animal == 'birb' else animal}" - + image_url=f"https://some-random-api.ml/img/{'bird' if animal == 'bird' else animal}" async with request("GET", image_url, headers={}) as response: if response.status == 200: @@ -190,6 +188,8 @@ async def animal_facts(self, ctx, animal:str): else: description = data["fact"] + colour_choices= [0x400000,0x997379,0xeb96aa,0x4870a0,0x49a7c3,0x8b3a3a,0x1e747c,0x0000ff] + embed = discord.Embed( title = f'Facts about {animal.lower()}', description=description, @@ -221,23 +221,23 @@ async def animal_facts_error(self, ctx, error): @commands.command(name='asciify') @cooldown(1, 1, BucketType.channel) async def asciify_message(self, ctx, *, message=None): - if message is not None: - if len(message) <= 50: - if message[0] == '<' and (message[1] == '#'): - await ctx.send('im not doing that 😂') - elif message[0] == '<' and message[1] == '@': - await ctx.send('im not doing that 😂') - elif ctx.author.is_on_mobile and len(message) > 8: - await ctx.send('The output might look a bit weird on your phone! 😅\n Landscape mode might make it look Better') - msg = pyfiglet.figlet_format(message) - await ctx.send(f'```\n{msg}\n```') - else: - msg = pyfiglet.figlet_format(message) - await ctx.send(f'```\n{msg}\n```') + if message is None: + await ctx.send('Whats it you want to asciify?') + + elif len(message) <= 50: + if message[0] == '<' and (message[1] == '#'): + await ctx.send('im not doing that 😂') + elif message[0] == '<' and message[1] == '@': + await ctx.send('im not doing that 😂') + elif ctx.author.is_on_mobile and len(message) > 8: + await ctx.send('The output might look a bit weird on your phone! 😅\n Landscape mode might make it look Better') + msg = pyfiglet.figlet_format(message) + await ctx.send(f'```\n{msg}\n```') else: - await ctx.send(f"Your character length ({len(message)}) has exceeded a normal of 50.") + msg = pyfiglet.figlet_format(message) + await ctx.send(f'```\n{msg}\n```') else: - await ctx.send('Whats it you want to asciify?') + await ctx.send(f"Your character length ({len(message)}) has exceeded a normal of 50.") # ASCIIfy: Error handling diff --git a/cogs/Help.py b/cogs/Help.py index 9f104c4..2ead6c6 100644 --- a/cogs/Help.py +++ b/cogs/Help.py @@ -19,7 +19,7 @@ async def help(self, ctx, argument=None, page = None): mod_role = discord.utils.get(ctx.author.roles, name='Moderator') admin_role = discord.utils.get(ctx.author.roles, name='Administrator') - + fun_embed = discord.Embed( title = 'Fun commands for Cyberon', @@ -34,7 +34,7 @@ async def help(self, ctx, argument=None, page = None): '**quotes**\nA random quote\n**Usage:** `cyb!quote`\n\n', colour=0x01a901 ) - + utils_embed = discord.Embed( title = 'Utility commands for cyberon', description='**avatar** | **av**\nShows the avatar of the user mentioned\n**Usage:** `cyb!avatar `\nIf nothing is provided then it shows your avatar\n\n' @@ -55,7 +55,7 @@ async def help(self, ctx, argument=None, page = None): '**hackclub**\nShows the hack club\'s upcoming hackathons\n**Usage:** `cyb!hackclub`\n\n', colour=0x01a901 ) - + mod_embed = discord.Embed( title = 'Moderation commands for cyberon\nPage 1', description='**kick**\nKicks the member out of the server\n**Usage:** `cyb!kick `, reason is not neccessary\n\n' @@ -117,23 +117,18 @@ async def help(self, ctx, argument=None, page = None): await ctx.send(embed=initial_help_dialogue) elif argument.lower() == 'fun': await ctx.send(embed=fun_embed) - elif argument.lower() == 'moderation' or argument.lower() == 'mod': + elif argument.lower() in ['moderation', 'mod']: - if page == '1' or page is None: + if page == '1' or page is None or page != '2': await ctx.send(embed=mod_embed) - elif page == '2': - await ctx.send(embed=mod_embed_2) else: - await ctx.send(embed=mod_embed) - - elif argument.lower() == 'utils' or argument.lower() == 'util': + await ctx.send(embed=mod_embed_2) + elif argument.lower() in ['utils', 'util']: await ctx.send(embed=utils_embed) elif argument.lower() == 'config': await ctx.send(embed=config_embed) elif argument.lower() == 'support': await ctx.send(embed=support_embed) - else: - pass # Help console: Error handling diff --git a/cogs/Utils.py b/cogs/Utils.py index cd9665d..10c431a 100644 --- a/cogs/Utils.py +++ b/cogs/Utils.py @@ -42,31 +42,21 @@ async def avatar(self, ctx, member, override=None): member = await converter.convert(ctx, member) elif member.isdigit(): member = int(member) - else: - pass - members = await ctx.guild.fetch_members().flatten() multiple_member_array = [] - + if isinstance(member, discord.Member): for members_list in members: if member.name.lower() in members_list.name.lower(): multiple_member_array.append(members_list) - else: - pass elif isinstance(member, int): for member_list in members: if member_list.id == member: multiple_member_array.append(member_list) - else: - pass else: for members_list in members: if member.lower() in members_list.name.lower(): multiple_member_array.append(members_list) - else: - pass - if member is discord.Member: if member.isdigit() and member.lower() == 'me' and override == 'override': embed = discord.Embed(colour=0x0000ff) @@ -78,7 +68,7 @@ async def avatar(self, ctx, member, override=None): if multiple_member_array[0].name == multiple_member_array[0].display_name: embed = discord.Embed(title=f'{multiple_member_array[0]}',colour=0x0000ff) - elif multiple_member_array[0].name != multiple_member_array[0].display_name: + else: embed = discord.Embed(title=f'{multiple_member_array[0]}({multiple_member_array[0].display_name})',colour=0x0000ff) embed.set_image(url=f'{multiple_member_array[0].avatar_url}') @@ -154,35 +144,23 @@ async def userinfo(self, ctx, member): members = await ctx.guild.fetch_members().flatten() multiple_member_array = [] - - + + if isinstance(member, discord.Member): for members_list in members: if member.name.lower() in members_list.name.lower(): multiple_member_array.append(members_list) - else: - pass - elif isinstance(member, int): for member_list in members: if member_list.id == member: multiple_member_array.append(member_list) - else: - pass - else: for members_list in members: if member.lower() in members_list.name.lower(): multiple_member_array.append(members_list) - else: - pass - if len(multiple_member_array) == 1: - roles = [] - for role in multiple_member_array[0].roles: - roles.append(role) - + roles = [role for role in multiple_member_array[0].roles] embed = discord.Embed( colour = 0x0000ff, ) @@ -200,7 +178,11 @@ async def userinfo(self, ctx, member): if len(roles) == 1: embed.add_field(name=f'Roles ({len(roles) - 1})', value='**NIL**') else: - embed.add_field(name=f'Roles ({len(roles) - 1})', value=' '.join([role.mention for role in roles if role.name != '@everyone'])) + embed.add_field( + name=f'Roles ({len(roles) - 1})', + value=' '.join( + role.mention for role in roles if role.name != '@everyone'), + ) embed.add_field(name='Bot?', value=multiple_member_array[0].bot) @@ -247,16 +229,10 @@ async def userinfo_error(self, ctx, error): @commands.command(aliases=['si']) @cooldown(1, 4, BucketType.channel) async def serverinfo(self, ctx): - - count = 0 members = await ctx.guild.fetch_members().flatten() - for people in members: - if people.bot: - count = count + 1 - else: - pass + count = sum(1 for people in members if people.bot) embed = discord.Embed( title = f'{ctx.guild.name} info', @@ -290,10 +266,10 @@ async def serverinfo(self, ctx): async def serverinfo_error(self, ctx, error): if isinstance(error, commands.CommandOnCooldown): await ctx.send(error) - raise error else: await ctx.send(f"An error occured \n```\n{error}\n```\nPlease check console for traceback, or raise an issue to cyberon.") - raise error + + raise error # Servercount @@ -302,10 +278,7 @@ async def serverinfo_error(self, ctx, error): @cooldown(1, 1, BucketType.channel) async def servercount(self, ctx): - member_count = 0 - for guild in self.bot.guilds: - member_count += guild.member_count - + member_count = sum(guild.member_count for guild in self.bot.guilds) await ctx.send(f'Present in `{len(self.bot.guilds)}` servers, moderating `{member_count}` members') @@ -415,13 +388,8 @@ async def cypher(self, ctx, *, message): '?':'..--..', '/':'-..-.', '-':'-....-', '(':'-.--.', ')':'-.--.-'} - cipher = '' - - for letter in message.upper(): - if letter != ' ': - cipher += MORSE_DICT[letter] + ' ' - else: - cipher += ' ' + cipher = ''.join(MORSE_DICT[letter] + ' ' if letter != ' ' else ' ' + for letter in message.upper()) await ctx.send(f'Here is your cyphered text:\n```\n{cipher}\n```') @@ -448,7 +416,7 @@ async def base64(self, ctx, message, iterations=1): if iterations <= 20: message_bytecode = message.encode('ascii') - for i in range(iterations): + for _ in range(iterations): message_bytecode = base64.b64encode(message_bytecode) base64_message = message_bytecode.decode('ascii') @@ -506,7 +474,7 @@ async def base64_decode_error(self, ctx, error): await ctx.send('What are the arguments') elif isinstance(error, commands.BadArgument): await ctx.send("Please enter your text to be encode in quotes") - elif isinstance(error, base64.binascii.Error) or isinstance(error, binascii.Error): + elif isinstance(error, (base64.binascii.Error, binascii.Error)): await ctx.send("Please enter a valid base64 encoded message to decrypt {ctx.author.display_name}") elif isinstance(error, UnicodeDecodeError): await ctx.send("Please enter a valid base64 encoded message to decrypt {ctx.author.display_name}")