aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2021-08-18 16:53:38 +0100
committerGravatar GitHub <[email protected]>2021-08-18 16:53:38 +0100
commite712f39f186b32711c63eeaa2988081e879f3f58 (patch)
tree21e57bd813ffd5cc05aee3844cb6b362f10d6a0e
parentMerge pull request #792 from python-discord/more-py-topics (diff)
parentMerge branch 'main' into main (diff)
Merge pull request #760 from Kronifer/main
Adds `.reverse`
-rw-r--r--bot/exts/evergreen/avatar_modification/_effects.py11
-rw-r--r--bot/exts/evergreen/avatar_modification/avatar_modify.py37
2 files changed, 48 insertions, 0 deletions
diff --git a/bot/exts/evergreen/avatar_modification/_effects.py b/bot/exts/evergreen/avatar_modification/_effects.py
index b53b26f3..46d1a2ab 100644
--- a/bot/exts/evergreen/avatar_modification/_effects.py
+++ b/bot/exts/evergreen/avatar_modification/_effects.py
@@ -97,6 +97,17 @@ class PfpEffects:
return image.quantize()
@staticmethod
+ def flip_effect(image: Image.Image) -> Image.Image:
+ """
+ Flips the image horizontally.
+
+ This is done by just using ImageOps.mirror().
+ """
+ image = ImageOps.mirror(image)
+
+ return image
+
+ @staticmethod
def easterify_effect(image: Image.Image, overlay_image: t.Optional[Image.Image] = None) -> Image.Image:
"""
Applies the easter effect to the given image.
diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py
index bd324f67..765c316e 100644
--- a/bot/exts/evergreen/avatar_modification/avatar_modify.py
+++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py
@@ -120,6 +120,43 @@ class AvatarModify(commands.Cog):
await ctx.send(embed=embed, file=file)
+ @avatar_modify.command(name="reverse", root_aliases=("reverse",))
+ async def reverse(self, ctx: commands.Context, *, text: t.Optional[str]) -> None:
+ """
+ Reverses the sent text.
+
+ If no text is provided, the user's profile picture will be reversed.
+ """
+ if text:
+ await ctx.send(f"> {text[::-1]}", allowed_mentions=discord.AllowedMentions.none())
+ return
+
+ async with ctx.typing():
+ user = await self._fetch_user(ctx.author.id)
+ if not user:
+ await ctx.send(f"{Emojis.cross_mark} Could not get user info.")
+ return
+
+ image_bytes = await user.avatar_url_as(size=1024).read()
+ filename = file_safe_name("reverse_avatar", ctx.author.display_name)
+
+ file = await in_executor(
+ PfpEffects.apply_effect,
+ image_bytes,
+ PfpEffects.flip_effect,
+ filename
+ )
+
+ embed = discord.Embed(
+ title="Your reversed avatar.",
+ description="Here is your reversed avatar. I think it is a spitting image of you."
+ )
+
+ embed.set_image(url=f"attachment://{filename}")
+ embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url)
+
+ await ctx.send(embed=embed, file=file)
+
@avatar_modify.command(aliases=("easterify",), root_aliases=("easterify", "avatareasterify"))
async def avatareasterify(self, ctx: commands.Context, *colours: t.Union[discord.Colour, str]) -> None:
"""