diff options
| -rw-r--r-- | Pipfile | 3 | ||||
| -rw-r--r-- | Pipfile.lock | 123 | ||||
| -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 | 
8 files changed, 107 insertions, 124 deletions
| @@ -4,8 +4,9 @@ verify_ssl = true  name = "pypi"  [packages] -"discord.py" = {ref = "rewrite", git = "https://github.com/Rapptz/discord.py"} +"discord-py" = {ref = "rewrite", git = "https://github.com/Rapptz/discord.py"}  arrow = "*" +pillow = "*"  [dev-packages]  "flake8" = "*" diff --git a/Pipfile.lock b/Pipfile.lock deleted file mode 100644 index 5e3d2a77..00000000 --- a/Pipfile.lock +++ /dev/null @@ -1,123 +0,0 @@ -{ -    "_meta": { -        "hash": { -            "sha256": "9d82195bc8a856a7c9f00057caf3af26c64d3d1daf09f63c6de55ad63f47f470" -        }, -        "pipfile-spec": 6, -        "requires": { -            "python_version": "3.7" -        }, -        "sources": [ -            { -                "name": "pypi", -                "url": "https://pypi.org/simple", -                "verify_ssl": true -            } -        ] -    }, -    "default": { -        "arrow": { -            "hashes": [ -                "sha256:a558d3b7b6ce7ffc74206a86c147052de23d3d4ef0e17c210dd478c53575c4cd" -            ], -            "index": "pypi", -            "version": "==0.12.1" -        }, -        "discord.py": { -            "git": "https://github.com/Rapptz/discord.py", -            "ref": "rewrite" -        }, -        "python-dateutil": { -            "hashes": [ -                "sha256:063df5763652e21de43de7d9e00ccf239f953a832941e37be541614732cdfc93", -                "sha256:88f9287c0174266bb0d8cedd395cfba9c58e87e5ad86b2ce58859bc11be3cf02" -            ], -            "version": "==2.7.5" -        }, -        "six": { -            "hashes": [ -                "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", -                "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" -            ], -            "version": "==1.11.0" -        } -    }, -    "develop": { -        "attrs": { -            "hashes": [ -                "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", -                "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" -            ], -            "version": "==18.2.0" -        }, -        "flake8": { -            "hashes": [ -                "sha256:6a35f5b8761f45c5513e3405f110a86bea57982c3b75b766ce7b65217abe1670", -                "sha256:c01f8a3963b3571a8e6bd7a4063359aff90749e160778e03817cd9b71c9e07d2" -            ], -            "index": "pypi", -            "version": "==3.6.0" -        }, -        "flake8-bugbear": { -            "hashes": [ -                "sha256:07b6e769d7f4e168d590f7088eae40f6ddd9fa4952bed31602def65842682c83", -                "sha256:0ccf56975f4db1d69dc1cf3598c99d768ebf95d0cad27d76087954aa399b515a" -            ], -            "index": "pypi", -            "version": "==18.8.0" -        }, -        "flake8-import-order": { -            "hashes": [ -                "sha256:9be5ca10d791d458eaa833dd6890ab2db37be80384707b0f76286ddd13c16cbf", -                "sha256:feca2fd0a17611b33b7fa84449939196c2c82764e262486d5c3e143ed77d387b" -            ], -            "index": "pypi", -            "version": "==0.18" -        }, -        "flake8-string-format": { -            "hashes": [ -                "sha256:68ea72a1a5b75e7018cae44d14f32473c798cf73d75cbaed86c6a9a907b770b2", -                "sha256:774d56103d9242ed968897455ef49b7d6de272000cfa83de5814273a868832f1" -            ], -            "index": "pypi", -            "version": "==0.2.3" -        }, -        "flake8-tidy-imports": { -            "hashes": [ -                "sha256:5fc28c82bba16abb4f1154dc59a90487f5491fbdb27e658cbee241e8fddc1b91", -                "sha256:c05c9f7dadb5748a04b6fa1c47cb6ae5a8170f03cfb1dca8b37aec58c1ee6d15" -            ], -            "index": "pypi", -            "version": "==1.1.0" -        }, -        "flake8-todo": { -            "hashes": [ -                "sha256:6e4c5491ff838c06fe5a771b0e95ee15fc005ca57196011011280fc834a85915" -            ], -            "index": "pypi", -            "version": "==0.7" -        }, -        "mccabe": { -            "hashes": [ -                "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", -                "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" -            ], -            "version": "==0.6.1" -        }, -        "pycodestyle": { -            "hashes": [ -                "sha256:74abc4e221d393ea5ce1f129ea6903209940c1ecd29e002e8c6933c2b21026e0", -                "sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83", -                "sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a" -            ], -            "version": "==2.4.0" -        }, -        "pyflakes": { -            "hashes": [ -                "sha256:9a7662ec724d0120012f6e29d6248ae3727d821bba522a0e6b356eff19126a49", -                "sha256:f661252913bc1dbe7fcfcbf0af0db3f42ab65aabd1a6ca68fe5d466bace94dae" -            ], -            "version": "==2.0.0" -        } -    } -} 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.pngBinary files differ new 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.pngBinary files differ new 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) | 
