diff options
Diffstat (limited to 'bot/exts/evergreen')
-rw-r--r-- | bot/exts/evergreen/avatar_modification/_effects.py | 31 | ||||
-rw-r--r-- | bot/exts/evergreen/avatar_modification/avatar_modify.py | 42 | ||||
-rw-r--r-- | bot/exts/evergreen/help.py | 4 | ||||
-rw-r--r-- | bot/exts/evergreen/snakes/_converter.py | 2 | ||||
-rw-r--r-- | bot/exts/evergreen/trivia_quiz.py | 2 |
5 files changed, 64 insertions, 17 deletions
diff --git a/bot/exts/evergreen/avatar_modification/_effects.py b/bot/exts/evergreen/avatar_modification/_effects.py index b53b26f3..92244207 100644 --- a/bot/exts/evergreen/avatar_modification/_effects.py +++ b/bot/exts/evergreen/avatar_modification/_effects.py @@ -22,6 +22,7 @@ class PfpEffects: """Applies the given effect to the image passed to it.""" im = Image.open(BytesIO(image_bytes)) im = im.convert("RGBA") + im = im.resize((1024, 1024)) im = effect(im, *args) bufferedio = BytesIO() @@ -74,7 +75,6 @@ class PfpEffects: @staticmethod def pridify_effect(image: Image.Image, pixels: int, flag: str) -> Image.Image: """Applies the given pride effect to the given image.""" - image = image.resize((1024, 1024)) image = PfpEffects.crop_avatar_circle(image) ring = Image.open(Path(f"bot/resources/pride/flags/{flag}.png")).resize((1024, 1024)) @@ -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. @@ -272,16 +283,14 @@ class PfpEffects: return new_image @staticmethod - def mosaic_effect(img_bytes: bytes, squares: int, file_name: str) -> discord.File: - """Separate function run from an executor which turns an image into a mosaic.""" - avatar = Image.open(BytesIO(img_bytes)) - avatar = avatar.convert("RGBA").resize((1024, 1024)) + def mosaic_effect(image: Image.Image, squares: int) -> Image.Image: + """ + Applies a mosaic effect to the given image. - img_squares = PfpEffects.split_image(avatar, squares) + The "squares" argument specifies the number of squares to split + the image into. This should be a square number. + """ + img_squares = PfpEffects.split_image(image, squares) new_img = PfpEffects.join_images(img_squares) - bufferedio = BytesIO() - new_img.save(bufferedio, format="PNG") - bufferedio.seek(0) - - return discord.File(bufferedio, filename=file_name) + return new_img diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index bd324f67..7b4ae9c7 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: """ @@ -301,10 +338,11 @@ class AvatarModify(commands.Cog): img_bytes = await user.avatar_url_as(size=1024).read() file = await in_executor( - PfpEffects.mosaic_effect, + PfpEffects.apply_effect, img_bytes, + PfpEffects.mosaic_effect, + file_name, squares, - file_name ) if squares == 1: diff --git a/bot/exts/evergreen/help.py b/bot/exts/evergreen/help.py index 3c9ba4d2..bfb5db17 100644 --- a/bot/exts/evergreen/help.py +++ b/bot/exts/evergreen/help.py @@ -8,7 +8,7 @@ from typing import List, NamedTuple, Union from discord import Colour, Embed, HTTPException, Message, Reaction, User from discord.ext import commands from discord.ext.commands import CheckFailure, Cog as DiscordCog, Command, Context -from fuzzywuzzy import fuzz, process +from rapidfuzz import process from bot import constants from bot.bot import Bot @@ -159,7 +159,7 @@ class HelpSession: # Combine command and cog names choices = list(self._bot.all_commands) + list(self._bot.cogs) - result = process.extractBests(query, choices, scorer=fuzz.ratio, score_cutoff=90) + result = process.extract(query, choices, score_cutoff=90) raise HelpQueryNotFound(f'Query "{query}" not found.', dict(result)) diff --git a/bot/exts/evergreen/snakes/_converter.py b/bot/exts/evergreen/snakes/_converter.py index 26bde611..c8d1909b 100644 --- a/bot/exts/evergreen/snakes/_converter.py +++ b/bot/exts/evergreen/snakes/_converter.py @@ -5,7 +5,7 @@ from typing import Iterable, List import discord from discord.ext.commands import Context, Converter -from fuzzywuzzy import fuzz +from rapidfuzz import fuzz from bot.exts.evergreen.snakes._utils import SNAKE_RESOURCES from bot.utils import disambiguate diff --git a/bot/exts/evergreen/trivia_quiz.py b/bot/exts/evergreen/trivia_quiz.py index 28924aed..bc25cbf7 100644 --- a/bot/exts/evergreen/trivia_quiz.py +++ b/bot/exts/evergreen/trivia_quiz.py @@ -9,7 +9,7 @@ from typing import Callable, List, Optional import discord from discord.ext import commands -from fuzzywuzzy import fuzz +from rapidfuzz import fuzz from bot.bot import Bot from bot.constants import Colours, NEGATIVE_REPLIES, Roles |