From e210354fc5d8e0970e1ea2e75bb28fa314fa72fa Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 20 Feb 2021 15:50:03 +0000 Subject: Hoist apply effect and remove private _. --- .../evergreen/profile_pic_modification/_effects.py | 25 +++++++++++----------- .../profile_pic_modification/pfp_modify.py | 8 +++---- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/profile_pic_modification/_effects.py b/bot/exts/evergreen/profile_pic_modification/_effects.py index fbe5f706..a290ed3d 100644 --- a/bot/exts/evergreen/profile_pic_modification/_effects.py +++ b/bot/exts/evergreen/profile_pic_modification/_effects.py @@ -15,6 +15,19 @@ EASTER_COLOURS = [ class PfpEffects(): """Implements various image effects.""" + @staticmethod + def apply_effect(image_bytes: bytes, effect: t.Callable, *args) -> discord.File: + """Applies the given effect to the image passed to it.""" + im = Image.open(BytesIO(image_bytes)) + im = im.convert("RGBA") + im = effect(im, *args) + + bufferedio = BytesIO() + im.save(bufferedio, format="PNG") + bufferedio.seek(0) + + return discord.File(bufferedio, filename="modified_avatar.png") + @staticmethod def closest(x: t.Tuple[int, int, int]) -> t.Tuple[int, int, int]: """ @@ -56,18 +69,6 @@ class PfpEffects(): ring.putalpha(mask) return ring - @staticmethod - def _apply_effect(image_bytes: bytes, effect: t.Callable, *args) -> discord.File: - im = Image.open(BytesIO(image_bytes)) - im = im.convert("RGBA") - im = effect(im, *args) - - bufferedio = BytesIO() - im.save(bufferedio, format="PNG") - bufferedio.seek(0) - - return discord.File(bufferedio, filename="modified_avatar.png") - @staticmethod def pridify_effect( image: Image, diff --git a/bot/exts/evergreen/profile_pic_modification/pfp_modify.py b/bot/exts/evergreen/profile_pic_modification/pfp_modify.py index 51742257..a58f44d2 100644 --- a/bot/exts/evergreen/profile_pic_modification/pfp_modify.py +++ b/bot/exts/evergreen/profile_pic_modification/pfp_modify.py @@ -49,7 +49,7 @@ class PfpModify(commands.Cog): async with ctx.typing(): image_bytes = await ctx.author.avatar_url.read() file = await in_thread( - PfpEffects._apply_effect, + PfpEffects.apply_effect, image_bytes, PfpEffects.eight_bitify_effect ) @@ -97,7 +97,7 @@ class PfpModify(commands.Cog): image_bytes = await ctx.author.avatar_url_as(size=256).read() file = await in_thread( - PfpEffects._apply_effect, + PfpEffects.apply_effect, image_bytes, PfpEffects.easterify_effect, egg @@ -123,7 +123,7 @@ class PfpModify(commands.Cog): """Gets and sends the image in an embed. Used by the pride commands.""" async with ctx.typing(): file = await in_thread( - PfpEffects._apply_effect, + PfpEffects.apply_effect, image_bytes, PfpEffects.pridify_effect, pixels, @@ -216,7 +216,7 @@ class PfpModify(commands.Cog): async with ctx.typing(): image_bytes = await ctx.author.avatar_url.read() - file = await in_thread(PfpEffects._apply_effect, image_bytes, spookifications.get_random_effect) + file = await in_thread(PfpEffects.apply_effect, image_bytes, spookifications.get_random_effect) embed = discord.Embed( title="Is this you or am I just really paranoid?", -- cgit v1.2.3