diff options
| author | 2019-05-11 22:12:44 -0400 | |
|---|---|---|
| committer | 2019-05-11 22:12:44 -0400 | |
| commit | 9890f64206771d715b7f3829f4d5a8d60c256631 (patch) | |
| tree | 85f16af341e4d8bc4a94d7c0a236a09b505c8740 | |
| parent | Fix broken help getter patterns (diff) | |
Fix broken avatar URL getter patterns
avatar_url_as now returns an Asset object, which cannot be passed directly to aiohttp since it's expecting a string.
Asset objects also provide a read method, returning the bytes directly so the aiohttp call is no longer necessary.
| -rw-r--r-- | bot/seasons/easter/avatar_easterifier.py | 3 | ||||
| -rw-r--r-- | bot/seasons/evergreen/snakes/utils.py | 14 | ||||
| -rw-r--r-- | bot/seasons/halloween/spookyavatar.py | 5 |
3 files changed, 10 insertions, 12 deletions
diff --git a/bot/seasons/easter/avatar_easterifier.py b/bot/seasons/easter/avatar_easterifier.py index 9f7ea271..a84e5eb4 100644 --- a/bot/seasons/easter/avatar_easterifier.py +++ b/bot/seasons/easter/avatar_easterifier.py @@ -71,8 +71,7 @@ class AvatarEasterifier(commands.Cog): async with ctx.typing(): # Grabs image of avatar - async with self.bot.http_session.get(ctx.author.avatar_url_as(size=256)) as resp: - image_bytes = await resp.read() + image_bytes = await ctx.author.avatar_url_as(size=256).read() old = Image.open(BytesIO(image_bytes)) old = old.convert("RGBA") diff --git a/bot/seasons/evergreen/snakes/utils.py b/bot/seasons/evergreen/snakes/utils.py index e2ed60bd..01e527ca 100644 --- a/bot/seasons/evergreen/snakes/utils.py +++ b/bot/seasons/evergreen/snakes/utils.py @@ -8,7 +8,6 @@ from itertools import product from pathlib import Path from typing import List, Tuple -import aiohttp from PIL import Image from PIL.ImageDraw import ImageDraw from discord import File, Member, Reaction @@ -480,18 +479,17 @@ class SnakeAndLaddersGame: async def _add_player(self, user: Member): self.players.append(user) self.player_tiles[user.id] = 1 - avatar_url = user.avatar_url_as(format='jpeg', size=PLAYER_ICON_IMAGE_SIZE) - async with aiohttp.ClientSession() as session: - async with session.get(avatar_url) as res: - avatar_bytes = await res.read() - im = Image.open(io.BytesIO(avatar_bytes)).resize((BOARD_PLAYER_SIZE, BOARD_PLAYER_SIZE)) - self.avatar_images[user.id] = im + + avatar_bytes = await user.avatar_url_as(format='jpeg', size=PLAYER_ICON_IMAGE_SIZE).read() + im = Image.open(io.BytesIO(avatar_bytes)).resize((BOARD_PLAYER_SIZE, BOARD_PLAYER_SIZE)) + self.avatar_images[user.id] = im async def player_join(self, user: Member): """ Handle players joining the game. - Prevent player joining if they have already joined, if the game is full, or if the game is + Prevent player joining if they have already cccccckgctrfebkrntucrvrktivvefvdjvnnniiehbde + joined, if the game is full, or if the game is in a waiting state. """ diff --git a/bot/seasons/halloween/spookyavatar.py b/bot/seasons/halloween/spookyavatar.py index 15c7c431..2cc81da8 100644 --- a/bot/seasons/halloween/spookyavatar.py +++ b/bot/seasons/halloween/spookyavatar.py @@ -37,8 +37,9 @@ class SpookyAvatar(commands.Cog): embed = discord.Embed(colour=0xFF0000) embed.title = "Is this you or am I just really paranoid?" embed.set_author(name=str(user.name), icon_url=user.avatar_url) - resp = await self.get(user.avatar_url) - im = Image.open(BytesIO(resp)) + + image_bytes = await ctx.author.avatar_url.read() + im = Image.open(BytesIO(image_bytes)) modified_im = spookifications.get_random_effect(im) modified_im.save(str(ctx.message.id)+'.png') f = discord.File(str(ctx.message.id)+'.png') |