diff options
author | 2021-03-06 12:12:22 +0000 | |
---|---|---|
committer | 2021-03-06 12:12:22 +0000 | |
commit | 013ce6da618ee9fdb7ec99d0c3a538f0aa8c745d (patch) | |
tree | 894a386029b9041259e1ca21b4663153b8c8bdbc | |
parent | Rename in_thread fuction for clarity. (diff) |
Improve readibility of code, and fix grammar issues.
-rw-r--r-- | bot/exts/evergreen/profile_pic_modification/_effects.py | 24 | ||||
-rw-r--r-- | bot/exts/evergreen/profile_pic_modification/pfp_modify.py | 18 |
2 files changed, 23 insertions, 19 deletions
diff --git a/bot/exts/evergreen/profile_pic_modification/_effects.py b/bot/exts/evergreen/profile_pic_modification/_effects.py index 1179100c..99010931 100644 --- a/bot/exts/evergreen/profile_pic_modification/_effects.py +++ b/bot/exts/evergreen/profile_pic_modification/_effects.py @@ -12,7 +12,7 @@ EASTER_COLOURS = [ ] # Pastel colours - Easter-like -class PfpEffects(): +class PfpEffects: """ Implements various image effects. @@ -37,14 +37,14 @@ class PfpEffects(): """ Finds the closest easter colour to a given pixel. - Returns a merge between the original colour and the closest colour + Returns a merge between the original colour and the closest colour. """ r1, g1, b1 = x def distance(point: t.Tuple[int, int, int]) -> t.Tuple[int, int, int]: """Finds the difference between a pastel colour and the original pixel colour.""" r2, g2, b2 = point - return ((r1 - r2)**2 + (g1 - g2)**2 + (b1 - b2)**2) + return (r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2 closest_colours = sorted(EASTER_COLOURS, key=lambda point: distance(point)) r2, g2, b2 = closest_colours[0] @@ -52,7 +52,7 @@ class PfpEffects(): g = (g1 + g2) // 2 b = (b1 + b2) // 2 - return (r, g, b) + return r, g, b @staticmethod def crop_avatar_circle(avatar: Image) -> Image: @@ -114,14 +114,18 @@ class PfpEffects(): image = ImageOps.posterize(image, 6) data = image.getdata() - setted_data = set(data) - new_d = {} + data_set = set(data) + easterified_data_set = {} - for x in setted_data: - new_d[x] = PfpEffects.closest(x) - new_data = [(*new_d[x], alpha[i]) if x in new_d else x for i, x in enumerate(data)] + for x in data_set: + easterified_data_set[x] = PfpEffects.closest(x) + new_pixel_data = [ + (*easterified_data_set[x], alpha[i]) + if x in easterified_data_set else x + for i, x in enumerate(data) + ] im = Image.new("RGBA", image.size) - im.putdata(new_data) + im.putdata(new_pixel_data) im.alpha_composite(overlay_image, (im.width - overlay_image.width, (im.height - overlay_image.height)//2)) return im diff --git a/bot/exts/evergreen/profile_pic_modification/pfp_modify.py b/bot/exts/evergreen/profile_pic_modification/pfp_modify.py index df5005c9..1d5b7208 100644 --- a/bot/exts/evergreen/profile_pic_modification/pfp_modify.py +++ b/bot/exts/evergreen/profile_pic_modification/pfp_modify.py @@ -39,7 +39,7 @@ class PfpModify(commands.Cog): @commands.group() async def pfp_modify(self, ctx: commands.Context) -> None: - """Groups all of the pfp modifing commands to allow a single concurrency limit.""" + """Groups all of the pfp modifying commands to allow a single concurrency limit.""" if not ctx.invoked_subcommand: await ctx.send_help(ctx.command) @@ -56,11 +56,11 @@ class PfpModify(commands.Cog): embed = discord.Embed( title="Your 8-bit avatar", - description='Here is your avatar. I think it looks all cool and "retro"' + description="Here is your avatar. I think it looks all cool and 'retro'." ) embed.set_image(url="attachment://modified_avatar.png") - embed.set_footer(text=f"Made by {ctx.author.display_name}", icon_url=ctx.author.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url) await ctx.send(file=file, embed=embed) @@ -104,11 +104,11 @@ class PfpModify(commands.Cog): ) embed = discord.Embed( - name="Your Lovely Easterified Avatar", + name="Your Lovely Easterified Avatar!", description="Here is your lovely avatar, all bright and colourful\nwith Easter pastel colours. Enjoy :D" ) embed.set_image(url="attachment://modified_avatar.png") - embed.set_footer(text=f"Made by {ctx.author.display_name}", icon_url=ctx.author.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url) await ctx.send(file=file, embed=embed) @@ -131,11 +131,11 @@ class PfpModify(commands.Cog): ) embed = discord.Embed( - name="Your Lovely Pride Avatar", + name="Your Lovely Pride Avatar!", description=f"Here is your lovely avatar, surrounded by\n a beautiful {option} flag. Enjoy :D" ) embed.set_image(url="attachment://modified_avatar.png") - embed.set_footer(text=f"Made by {ctx.author.display_name}", icon_url=ctx.author.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url) await ctx.send(file=file, embed=embed) @pfp_modify.group( @@ -222,11 +222,11 @@ class PfpModify(commands.Cog): embed = discord.Embed( title="Is this you or am I just really paranoid?", - colour=0xFF0000 + colour=Colours.soft_red ) embed.set_author(name=str(user.name), icon_url=user.avatar_url) embed.set_image(url='attachment://modified_avatar.png') - embed.set_footer(text=f"Made by {ctx.author.display_name}", icon_url=ctx.author.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url) await ctx.send(file=file, embed=embed) |