diff options
| author | 2021-02-20 15:50:03 +0000 | |
|---|---|---|
| committer | 2021-02-20 15:50:03 +0000 | |
| commit | e210354fc5d8e0970e1ea2e75bb28fa314fa72fa (patch) | |
| tree | b65a2671695acfb7c45479a906fcada3fd103732 /bot | |
| parent | Split effects from cog (diff) | |
Hoist apply effect and remove private _.
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/exts/evergreen/profile_pic_modification/_effects.py | 25 | ||||
| -rw-r--r-- | bot/exts/evergreen/profile_pic_modification/pfp_modify.py | 8 | 
2 files changed, 17 insertions, 16 deletions
| 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 @@ -16,6 +16,19 @@ 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]:          """          Finds the closest easter colour to a given pixel. @@ -57,18 +70,6 @@ class PfpEffects():          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,          pixels: int, 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?", | 
