diff options
-rw-r--r-- | Pipfile | 1 | ||||
-rw-r--r-- | Pipfile.lock | 44 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | bot/__main__.py | 2 | ||||
-rw-r--r-- | bot/cogs/spookyavatar.py | 52 | ||||
-rw-r--r-- | bot/resources/bat-clipart.png | bin | 0 -> 12313 bytes | |||
-rw-r--r-- | bot/resources/bloody-pentagram.png | bin | 0 -> 7006 bytes | |||
-rw-r--r-- | bot/resources/spookifications.py | 53 |
8 files changed, 152 insertions, 3 deletions
@@ -5,6 +5,7 @@ name = "pypi" [packages] "discord.py" = {ref = "rewrite", git = "https://github.com/Rapptz/discord.py"} +pillow = "*" [dev-packages] "flake8" = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 8d330b8d..dfadc525 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "4ea08ef13815b0819e975097df6bb77d74d756524db2ad106ec93873fd1594de" + "sha256": "67645999515126a2bda91e0b7b5ed6e6b9fb2bfc127649c0b85b2be8c71b4c78" }, "pipfile-spec": 6, "requires": { @@ -16,9 +16,49 @@ ] }, "default": { + "discord-py": { + "git": "https://github.com/Rapptz/discord.py", + "ref": "860d6a9ace8248dfeec18b8b159e7b757d9f56bb" + }, "discord.py": { "git": "https://github.com/Rapptz/discord.py", - "ref": "1da696258095d5c1171a1cdbe75f56c535c6683e" + "ref": "rewrite" + }, + "pillow": { + "hashes": [ + "sha256:00203f406818c3f45d47bb8fe7e67d3feddb8dcbbd45a289a1de7dd789226360", + "sha256:0616f800f348664e694dddb0b0c88d26761dd5e9f34e1ed7b7a7d2da14b40cb7", + "sha256:1f7908aab90c92ad85af9d2fec5fc79456a89b3adcc26314d2cde0e238bd789e", + "sha256:2ea3517cd5779843de8a759c2349a3cd8d3893e03ab47053b66d5ec6f8bc4f93", + "sha256:48a9f0538c91fc136b3a576bee0e7cd174773dc9920b310c21dcb5519722e82c", + "sha256:5280ebc42641a1283b7b1f2c20e5b936692198b9dd9995527c18b794850be1a8", + "sha256:5e34e4b5764af65551647f5cc67cf5198c1d05621781d5173b342e5e55bf023b", + "sha256:63b120421ab85cad909792583f83b6ca3584610c2fe70751e23f606a3c2e87f0", + "sha256:696b5e0109fe368d0057f484e2e91717b49a03f1e310f857f133a4acec9f91dd", + "sha256:870ed021a42b1b02b5fe4a739ea735f671a84128c0a666c705db2cb9abd528eb", + "sha256:916da1c19e4012d06a372127d7140dae894806fad67ef44330e5600d77833581", + "sha256:9303a289fa0811e1c6abd9ddebfc770556d7c3311cb2b32eff72164ddc49bc64", + "sha256:9577888ecc0ad7d06c3746afaba339c94d62b59da16f7a5d1cff9e491f23dace", + "sha256:987e1c94a33c93d9b209315bfda9faa54b8edfce6438a1e93ae866ba20de5956", + "sha256:99a3bbdbb844f4fb5d6dd59fac836a40749781c1fa63c563bc216c27aef63f60", + "sha256:99db8dc3097ceafbcff9cb2bff384b974795edeb11d167d391a02c7bfeeb6e16", + "sha256:a5a96cf49eb580756a44ecf12949e52f211e20bffbf5a95760ac14b1e499cd37", + "sha256:aa6ca3eb56704cdc0d876fc6047ffd5ee960caad52452fbee0f99908a141a0ae", + "sha256:aade5e66795c94e4a2b2624affeea8979648d1b0ae3fcee17e74e2c647fc4a8a", + "sha256:b78905860336c1d292409e3df6ad39cc1f1c7f0964e66844bbc2ebfca434d073", + "sha256:b92f521cdc4e4a3041cc343625b699f20b0b5f976793fb45681aac1efda565f8", + "sha256:bfde84bbd6ae5f782206d454b67b7ee8f7f818c29b99fd02bf022fd33bab14cb", + "sha256:c2b62d3df80e694c0e4a0ed47754c9480521e25642251b3ab1dff050a4e60409", + "sha256:c5e2be6c263b64f6f7656e23e18a4a9980cffc671442795682e8c4e4f815dd9f", + "sha256:c99aa3c63104e0818ec566f8ff3942fb7c7a8f35f9912cb63fd8e12318b214b2", + "sha256:dae06620d3978da346375ebf88b9e2dd7d151335ba668c995aea9ed07af7add4", + "sha256:db5499d0710823fa4fb88206050d46544e8f0e0136a9a5f5570b026584c8fd74", + "sha256:f36baafd82119c4a114b9518202f2a983819101dcc14b26e43fc12cbefdce00e", + "sha256:f52b79c8796d81391ab295b04e520bda6feed54d54931708872e8f9ae9db0ea1", + "sha256:ff8cff01582fa1a7e533cb97f628531c4014af4b5f38e33cdcfe5eec29b6d888" + ], + "index": "pypi", + "version": "==5.3.0" } }, "develop": { @@ -18,6 +18,9 @@ We know it can be difficult to get into the whole open source thing at first. To Random halloween facts are posted regularly. !hallofact - Show the last posted Halloween fact +### Avatar Spookification +!savatar - Spookifies your avatar with a few random effects. + ## Getting started If you are new to this you will find it far easier using PyCharm: diff --git a/bot/__main__.py b/bot/__main__.py index ccd69b0b..f218443a 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -5,7 +5,7 @@ from traceback import format_exc from discord.ext import commands -HACKTOBERBOT_TOKEN = environ.get('HACKTOBERBOT_TOKEN') +HACKTOBERBOT_TOKEN = 'NDk5NjAzOTk1MzkyODY4MzU1.Dq3ITw.F0f45KYcZN1NgAyPIbrsgoz49Yo'#environ.get('HACKTOBERBOT_TOKEN') log = logging.getLogger() if HACKTOBERBOT_TOKEN: diff --git a/bot/cogs/spookyavatar.py b/bot/cogs/spookyavatar.py new file mode 100644 index 00000000..8a424b1f --- /dev/null +++ b/bot/cogs/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.resources 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 spookyavatar(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/bat-clipart.png b/bot/resources/bat-clipart.png Binary files differnew file mode 100644 index 00000000..7df26ba9 --- /dev/null +++ b/bot/resources/bat-clipart.png diff --git a/bot/resources/bloody-pentagram.png b/bot/resources/bloody-pentagram.png Binary files differnew file mode 100644 index 00000000..4e6da07a --- /dev/null +++ b/bot/resources/bloody-pentagram.png diff --git a/bot/resources/spookifications.py b/bot/resources/spookifications.py new file mode 100644 index 00000000..2211049f --- /dev/null +++ b/bot/resources/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) |