aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
authorGravatar hundredrab <[email protected]>2018-10-21 22:52:15 +0530
committerGravatar hundredrab <[email protected]>2018-10-21 22:52:15 +0530
commit138bb28e9d1cfef8cab48d216e550efafcd85454 (patch)
treef1b811224c5ad71e8e8a38f100cb8c36217fbcdf /bot
parentAdd pillow to Pipfile. (diff)
Fix issues related to spookyavatar cog.
Diffstat (limited to 'bot')
-rw-r--r--bot/cogs/spookyavatar.py18
-rw-r--r--bot/resources/spookifications.py7
2 files changed, 18 insertions, 7 deletions
diff --git a/bot/cogs/spookyavatar.py b/bot/cogs/spookyavatar.py
index 11f4705c..d06b259a 100644
--- a/bot/cogs/spookyavatar.py
+++ b/bot/cogs/spookyavatar.py
@@ -1,9 +1,11 @@
+import aiohttp
+from io import BytesIO
+
from discord.ext import commands
import discord
-import aiohttp
-from PIL import ImageOps
from PIL import Image
-from io import BytesIO
+
+from bot.resources import spookifications
class SpookyAvatar:
@@ -16,12 +18,15 @@ class SpookyAvatar:
self.bot = bot
async def get(self, url):
+ """
+ Returns the contents of the supplied url.
+ """
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
return await resp.read()
@commands.command(name='savatar', aliases=['spookyavatar', 'spookify'], brief='Spookify an user\'s avatar.')
- async def repository(self, ctx, user: discord.Member=None):
+ async def spookyavatar(self, ctx, user: discord.Member=None):
"""
A command to print the user's spookified avatar.
"""
@@ -33,9 +38,8 @@ class SpookyAvatar:
embed.set_author(name=str(user.name), icon_url=user.avatar_url)
resp = await self.get(user.avatar_url)
im = Image.open(BytesIO(resp))
- im = im.convert('RGB')
- inv = ImageOps.invert(im)
- inv.save(str(ctx.message.id)+'.png')
+ modified_im = spookifications.inversion(im)
+ modified_im.save(str(ctx.message.id)+'.png')
f = discord.File(str(ctx.message.id)+'.png')
embed.set_image(url='attachment://'+str(ctx.message.id)+'.png')
await ctx.send(file=f, embed=embed)
diff --git a/bot/resources/spookifications.py b/bot/resources/spookifications.py
new file mode 100644
index 00000000..aeb8388b
--- /dev/null
+++ b/bot/resources/spookifications.py
@@ -0,0 +1,7 @@
+from PIL import ImageOps
+
+
+def inversion(im):
+ im = im.convert('RGB')
+ inv = ImageOps.invert(im)
+ return inv