diff options
author | 2018-11-20 13:10:59 +0100 | |
---|---|---|
committer | 2018-11-20 13:10:59 +0100 | |
commit | 05e35b2ccbd5ce81e4035e8bd889c5188d865c0f (patch) | |
tree | 534301dcb9b69a694c5b3d78f4865c2810c7ad4d /bot | |
parent | Merge branch 'master' of github.com:python-discord/seasonalbot (diff) | |
parent | Add whitespace. (diff) |
Solved merge conflicts
Diffstat (limited to 'bot')
-rw-r--r-- | bot/cogs/hacktober/candy_collection.py (renamed from bot/cogs/candy_collection.py) | 0 | ||||
-rw-r--r-- | bot/cogs/hacktober/spookyavatar.py | 52 | ||||
-rw-r--r-- | bot/resources/halloween/bat-clipart.png | bin | 0 -> 12313 bytes | |||
-rw-r--r-- | bot/resources/halloween/bloody-pentagram.png | bin | 0 -> 7006 bytes | |||
-rw-r--r-- | bot/utils/__init__.py | 0 | ||||
-rw-r--r-- | bot/utils/spookifications.py | 53 |
6 files changed, 105 insertions, 0 deletions
diff --git a/bot/cogs/candy_collection.py b/bot/cogs/hacktober/candy_collection.py index 59eadd93..59eadd93 100644 --- a/bot/cogs/candy_collection.py +++ b/bot/cogs/hacktober/candy_collection.py diff --git a/bot/cogs/hacktober/spookyavatar.py b/bot/cogs/hacktober/spookyavatar.py new file mode 100644 index 00000000..694eb317 --- /dev/null +++ b/bot/cogs/hacktober/spookyavatar.py @@ -0,0 +1,52 @@ +from io import BytesIO +import os + +import aiohttp +import discord +from discord.ext import commands +from PIL import Image + +from bot.utils import spookifications + + +class SpookyAvatar: + + """ + A cog that spookifies an avatar. + """ + + def __init__(self, bot): + 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 spooky_avatar(self, ctx, user: discord.Member = None): + """ + A command to print the user's spookified avatar. + """ + if user is None: + user = ctx.message.author + + 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)) + modified_im = spookifications.get_random_effect(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) + os.remove(str(ctx.message.id)+'.png') + + +def setup(bot): + bot.add_cog(SpookyAvatar(bot)) diff --git a/bot/resources/halloween/bat-clipart.png b/bot/resources/halloween/bat-clipart.png Binary files differnew file mode 100644 index 00000000..7df26ba9 --- /dev/null +++ b/bot/resources/halloween/bat-clipart.png diff --git a/bot/resources/halloween/bloody-pentagram.png b/bot/resources/halloween/bloody-pentagram.png Binary files differnew file mode 100644 index 00000000..4e6da07a --- /dev/null +++ b/bot/resources/halloween/bloody-pentagram.png diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/bot/utils/__init__.py diff --git a/bot/utils/spookifications.py b/bot/utils/spookifications.py new file mode 100644 index 00000000..2211049f --- /dev/null +++ b/bot/utils/spookifications.py @@ -0,0 +1,53 @@ +import logging +from random import choice, randint + +from PIL import Image +from PIL import ImageOps + +log = logging.getLogger() + + +def inversion(im): + """Inverts an image. + + Returns an inverted image when supplied with an Image object. + """ + im = im.convert('RGB') + inv = ImageOps.invert(im) + return inv + + +def pentagram(im): + """Adds pentagram to image.""" + im = im.convert('RGB') + wt, ht = im.size + penta = Image.open('bot/resources/bloody-pentagram.png') + penta = penta.resize((wt, ht)) + im.paste(penta, (0, 0), penta) + return im + + +def bat(im): + """Adds a bat silhoutte to the image. + + The bat silhoutte is of a size at least one-fifths that of the original + image and may be rotated upto 90 degrees anti-clockwise.""" + im = im.convert('RGB') + wt, ht = im.size + bat = Image.open('bot/resources/bat-clipart.png') + bat_size = randint(wt//5, wt) + rot = randint(0, 90) + bat = bat.resize((bat_size, bat_size)) + bat = bat.rotate(rot) + x = randint(0, wt-bat_size) + y = randint(0, wt-bat_size) + im.paste(bat, (x, y), bat) + return im + + +def get_random_effect(im): + """Randomly selects and applies an effect.""" + effects = [inversion, pentagram, bat] + effect = choice(effects) + log.info("Spookyavatar's chosen effect: " + effect.__name__) + return effect(im) |