diff options
| author | 2021-09-03 16:28:04 +0100 | |
|---|---|---|
| committer | 2021-09-03 16:28:04 +0100 | |
| commit | cd7060835b5b0d150c6e91d75bc3227ee43db0ba (patch) | |
| tree | 4264ddbb25e86184255574cfd0e8fa9bb11d7bcb /bot/exts/evergreen/avatar_modification | |
| parent | Handle status not found with 404 picture (diff) | |
| parent | Merge pull request #839 from python-discord/android-codeblock-fix (diff) | |
Merge branch 'main' into teapot-support
Diffstat (limited to 'bot/exts/evergreen/avatar_modification')
| -rw-r--r-- | bot/exts/evergreen/avatar_modification/_effects.py | 12 | ||||
| -rw-r--r-- | bot/exts/evergreen/avatar_modification/avatar_modify.py | 40 |
2 files changed, 26 insertions, 26 deletions
diff --git a/bot/exts/evergreen/avatar_modification/_effects.py b/bot/exts/evergreen/avatar_modification/_effects.py index 92244207..df741973 100644 --- a/bot/exts/evergreen/avatar_modification/_effects.py +++ b/bot/exts/evergreen/avatar_modification/_effects.py @@ -1,8 +1,8 @@ import math import random -import typing as t from io import BytesIO from pathlib import Path +from typing import Callable, Optional import discord from PIL import Image, ImageDraw, ImageOps @@ -18,7 +18,7 @@ class PfpEffects: """ @staticmethod - def apply_effect(image_bytes: bytes, effect: t.Callable, filename: str, *args) -> discord.File: + def apply_effect(image_bytes: bytes, effect: Callable, filename: str, *args) -> discord.File: """Applies the given effect to the image passed to it.""" im = Image.open(BytesIO(image_bytes)) im = im.convert("RGBA") @@ -32,7 +32,7 @@ class PfpEffects: return discord.File(bufferedio, filename=filename) @staticmethod - def closest(x: t.Tuple[int, int, int]) -> t.Tuple[int, int, int]: + def closest(x: tuple[int, int, int]) -> tuple[int, int, int]: """ Finds the closest "easter" colour to a given pixel. @@ -40,7 +40,7 @@ class PfpEffects: """ r1, g1, b1 = x - def distance(point: t.Tuple[int, int, int]) -> t.Tuple[int, int, int]: + def distance(point: tuple[int, 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 @@ -108,7 +108,7 @@ class PfpEffects: return image @staticmethod - def easterify_effect(image: Image.Image, overlay_image: t.Optional[Image.Image] = None) -> Image.Image: + def easterify_effect(image: Image.Image, overlay_image: Optional[Image.Image] = None) -> Image.Image: """ Applies the easter effect to the given image. @@ -212,7 +212,7 @@ class PfpEffects: return new_imgs @staticmethod - def join_images(images: t.List[Image.Image]) -> Image.Image: + def join_images(images: list[Image.Image]) -> Image.Image: """ Stitches all the image squares into a new image. diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 7b4ae9c7..18202902 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -3,10 +3,10 @@ import json import logging import math import string -import typing as t import unicodedata from concurrent.futures import ThreadPoolExecutor from pathlib import Path +from typing import Callable, Optional, TypeVar, Union import discord from discord.ext import commands @@ -25,12 +25,12 @@ FILENAME_STRING = "{effect}_{author}.png" MAX_SQUARES = 10_000 -T = t.TypeVar("T") +T = TypeVar("T") GENDER_OPTIONS = json.loads(Path("bot/resources/pride/gender_options.json").read_text("utf8")) -async def in_executor(func: t.Callable[..., T], *args) -> T: +async def in_executor(func: Callable[..., T], *args) -> T: """ Runs the given synchronous function `func` in an executor. @@ -62,10 +62,10 @@ def file_safe_name(effect: str, display_name: str) -> str: class AvatarModify(commands.Cog): """Various commands for users to apply affects to their own avatars.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot - async def _fetch_user(self, user_id: int) -> t.Optional[discord.User]: + async def _fetch_user(self, user_id: int) -> Optional[discord.User]: """ Fetches a user and handles errors. @@ -100,7 +100,7 @@ class AvatarModify(commands.Cog): await ctx.send(f"{Emojis.cross_mark} Could not get user info.") return - image_bytes = await user.avatar_url_as(size=1024).read() + image_bytes = await user.display_avatar.replace(size=1024).read() file_name = file_safe_name("eightbit_avatar", ctx.author.display_name) file = await in_executor( @@ -116,12 +116,12 @@ class AvatarModify(commands.Cog): ) embed.set_image(url=f"attachment://{file_name}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.display_avatar.url) 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: + async def reverse(self, ctx: commands.Context, *, text: Optional[str]) -> None: """ Reverses the sent text. @@ -137,7 +137,7 @@ class AvatarModify(commands.Cog): await ctx.send(f"{Emojis.cross_mark} Could not get user info.") return - image_bytes = await user.avatar_url_as(size=1024).read() + image_bytes = await user.display_avatar.replace(size=1024).read() filename = file_safe_name("reverse_avatar", ctx.author.display_name) file = await in_executor( @@ -153,12 +153,12 @@ class AvatarModify(commands.Cog): ) embed.set_image(url=f"attachment://{filename}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.display_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: + async def avatareasterify(self, ctx: commands.Context, *colours: Union[discord.Colour, str]) -> None: """ This "Easterifies" the user's avatar. @@ -193,7 +193,7 @@ class AvatarModify(commands.Cog): return ctx.send = send_message # Reassigns ctx.send - image_bytes = await user.avatar_url_as(size=256).read() + image_bytes = await user.display_avatar.replace(size=256).read() file_name = file_safe_name("easterified_avatar", ctx.author.display_name) file = await in_executor( @@ -205,11 +205,11 @@ class AvatarModify(commands.Cog): ) embed = discord.Embed( - name="Your Lovely Easterified Avatar!", + title="Your Lovely Easterified Avatar!", description="Here is your lovely avatar, all bright and colourful\nwith Easter pastel colours. Enjoy :D" ) embed.set_image(url=f"attachment://{file_name}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=user.display_avatar.url) await ctx.send(file=file, embed=embed) @@ -235,7 +235,7 @@ class AvatarModify(commands.Cog): ) embed = discord.Embed( - name="Your Lovely Pride Avatar!", + title="Your Lovely Pride Avatar!", description=f"Here is your lovely avatar, surrounded by\n a beautiful {option} flag. Enjoy :D" ) embed.set_image(url=f"attachment://{file_name}") @@ -268,7 +268,7 @@ class AvatarModify(commands.Cog): 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() + image_bytes = await user.display_avatar.replace(size=1024).read() await self.send_pride_image(ctx, image_bytes, pixels, flag, option) @prideavatar.command() @@ -296,7 +296,7 @@ class AvatarModify(commands.Cog): return async with ctx.typing(): - image_bytes = await user.avatar_url_as(size=1024).read() + image_bytes = await user.display_avatar.replace(size=1024).read() file_name = file_safe_name("spooky_avatar", ctx.author.display_name) @@ -312,7 +312,7 @@ class AvatarModify(commands.Cog): colour=Colours.soft_red ) embed.set_image(url=f"attachment://{file_name}") - 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.display_avatar.url) await ctx.send(file=file, embed=embed) @@ -335,7 +335,7 @@ class AvatarModify(commands.Cog): file_name = file_safe_name("mosaic_avatar", ctx.author.display_name) - img_bytes = await user.avatar_url_as(size=1024).read() + img_bytes = await user.display_avatar.replace(size=1024).read() file = await in_executor( PfpEffects.apply_effect, @@ -362,7 +362,7 @@ class AvatarModify(commands.Cog): ) embed.set_image(url=f"attachment://{file_name}") - embed.set_footer(text=f"Made by {ctx.author.display_name}", icon_url=user.avatar_url) + embed.set_footer(text=f"Made by {ctx.author.display_name}", icon_url=user.display_avatar.url) await ctx.send(file=file, embed=embed) |