diff options
author | 2018-11-20 13:37:18 +0100 | |
---|---|---|
committer | 2018-11-20 13:37:18 +0100 | |
commit | f64061773ebde98054f5036cf65d9637070b23e4 (patch) | |
tree | 0d1c36e5174f0be883df0776d0dfee8d386e41b4 | |
parent | Merge branch 'master' of github.com:python-discord/seasonalbot (diff) | |
parent | New lockfile (diff) |
Merge branch 'hundredrab-master'
-rw-r--r-- | Pipfile | 3 | ||||
-rw-r--r-- | Pipfile.lock | 60 | ||||
-rw-r--r-- | bot/cogs/hacktober/candy_collection.py (renamed from bot/cogs/candy_collection.py) | 17 | ||||
-rw-r--r-- | bot/cogs/hacktober/monstersurvey.py | 5 | ||||
-rw-r--r-- | bot/cogs/hacktober/spookyavatar.py | 52 | ||||
-rw-r--r-- | bot/constants.py | 1 | ||||
-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/resources/halloween/candy_collection.json (renamed from bot/cogs/resources/candy_collection.json) | 0 | ||||
-rw-r--r-- | bot/utils/__init__.py | 0 | ||||
-rw-r--r-- | bot/utils/spookifications.py | 55 |
11 files changed, 179 insertions, 14 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 index 5e3d2a77..be72165f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "9d82195bc8a856a7c9f00057caf3af26c64d3d1daf09f63c6de55ad63f47f470" + "sha256": "577eb73d927cf69687453acf1d06c40b81aedab40a238402f14d5a9385413bc0" }, "pipfile-spec": 6, "requires": { @@ -23,10 +23,66 @@ "index": "pypi", "version": "==0.12.1" }, - "discord.py": { + "discord-py": { "git": "https://github.com/Rapptz/discord.py", "ref": "rewrite" }, + "pillow": { + "hashes": [ + "sha256:00203f406818c3f45d47bb8fe7e67d3feddb8dcbbd45a289a1de7dd789226360", + "sha256:0616f800f348664e694dddb0b0c88d26761dd5e9f34e1ed7b7a7d2da14b40cb7", + "sha256:091136f2a37e9ed6bd8ce96fbf5269199ba6edee490d64de7ac934316f31ecca", + "sha256:0d67ae9a5937b1348fa1d97c7dcb6b56aaef828ca6655298e96f2f3114ad829d", + "sha256:0e1aaddd00ee9014fe7a61b9da61427233fcd7c7f193b5efd6689e0ec36bc42f", + "sha256:1f7908aab90c92ad85af9d2fec5fc79456a89b3adcc26314d2cde0e238bd789e", + "sha256:2ea3517cd5779843de8a759c2349a3cd8d3893e03ab47053b66d5ec6f8bc4f93", + "sha256:39b662f65a067709a62943003c1e807d140e7fcf631fcfc66ebe905f8149b9f4", + "sha256:3ddc19447cf42ef3ec564ab7ebbd4f67838ba9816d739befe29dd70149c775bd", + "sha256:48a9f0538c91fc136b3a576bee0e7cd174773dc9920b310c21dcb5519722e82c", + "sha256:5280ebc42641a1283b7b1f2c20e5b936692198b9dd9995527c18b794850be1a8", + "sha256:576a8a7a57065dab968d9d18befa2594a7673dcdab78c9b1f34248410cc6118f", + "sha256:5e334a23c8f7cb6079987a2ed9978821a42b4323a3a3bdbc132945348737f9a9", + "sha256:5e34e4b5764af65551647f5cc67cf5198c1d05621781d5173b342e5e55bf023b", + "sha256:63b120421ab85cad909792583f83b6ca3584610c2fe70751e23f606a3c2e87f0", + "sha256:696b5e0109fe368d0057f484e2e91717b49a03f1e310f857f133a4acec9f91dd", + "sha256:6cb528de694f503ea164541c151da6c18267727a7558e0c9716cc0383d89658a", + "sha256:7306d851d5a0cfac9ea07f1177783836f4b37292e5f224a534a52111cb6a6451", + "sha256:7e3e32346d991f1788026917d0a9c182d6d32dc757163eee7ca990f1f831499e", + "sha256:870ed021a42b1b02b5fe4a739ea735f671a84128c0a666c705db2cb9abd528eb", + "sha256:916da1c19e4012d06a372127d7140dae894806fad67ef44330e5600d77833581", + "sha256:9303a289fa0811e1c6abd9ddebfc770556d7c3311cb2b32eff72164ddc49bc64", + "sha256:9577888ecc0ad7d06c3746afaba339c94d62b59da16f7a5d1cff9e491f23dace", + "sha256:987e1c94a33c93d9b209315bfda9faa54b8edfce6438a1e93ae866ba20de5956", + "sha256:99a3bbdbb844f4fb5d6dd59fac836a40749781c1fa63c563bc216c27aef63f60", + "sha256:99db8dc3097ceafbcff9cb2bff384b974795edeb11d167d391a02c7bfeeb6e16", + "sha256:a379526415f54f9462bc65a4da76fb0acc05e3b2a21717dde79621cf4377e0e6", + "sha256:a5a96cf49eb580756a44ecf12949e52f211e20bffbf5a95760ac14b1e499cd37", + "sha256:a844b5d8120f99fb7cd276ff544ac5bd562b0c053760d59694e6bf747c6ca7f5", + "sha256:a9284368e81a67a7f47d5ef1ef7e4f11a4f688485879f44cf5f9090bba1f9d94", + "sha256:aa6ca3eb56704cdc0d876fc6047ffd5ee960caad52452fbee0f99908a141a0ae", + "sha256:aade5e66795c94e4a2b2624affeea8979648d1b0ae3fcee17e74e2c647fc4a8a", + "sha256:b78905860336c1d292409e3df6ad39cc1f1c7f0964e66844bbc2ebfca434d073", + "sha256:b92f521cdc4e4a3041cc343625b699f20b0b5f976793fb45681aac1efda565f8", + "sha256:bb2baf44e97811687893873eab8cf9f18b40321cc15d15ff9f91dc031e30631f", + "sha256:bfde84bbd6ae5f782206d454b67b7ee8f7f818c29b99fd02bf022fd33bab14cb", + "sha256:c2b62d3df80e694c0e4a0ed47754c9480521e25642251b3ab1dff050a4e60409", + "sha256:c55d348c1c65896c1bd804527de4880d251ae832acf90d74ad525bb79e77d55c", + "sha256:c5e2be6c263b64f6f7656e23e18a4a9980cffc671442795682e8c4e4f815dd9f", + "sha256:c99aa3c63104e0818ec566f8ff3942fb7c7a8f35f9912cb63fd8e12318b214b2", + "sha256:dae06620d3978da346375ebf88b9e2dd7d151335ba668c995aea9ed07af7add4", + "sha256:db5499d0710823fa4fb88206050d46544e8f0e0136a9a5f5570b026584c8fd74", + "sha256:dcd3cd17d291e01e47636101c4a6638ffb44c842d009973e3b5c1b67ff718c58", + "sha256:f12df6b45abc18f27f6e21ce26f7cbf7aa19820911462e46536e22085658ca1e", + "sha256:f36baafd82119c4a114b9518202f2a983819101dcc14b26e43fc12cbefdce00e", + "sha256:f52b79c8796d81391ab295b04e520bda6feed54d54931708872e8f9ae9db0ea1", + "sha256:fa2a50f762d06d84125db0b95d0121e9c640afa7edc23fc0848896760a390f8e", + "sha256:fa49bb60792b542b95ca93a39041e7113843093ce3cfd216870118eb3798fcc9", + "sha256:ff8cff01582fa1a7e533cb97f628531c4014af4b5f38e33cdcfe5eec29b6d888", + "sha256:ffbccfe1c077b5f41738bd719518213c217be7a7a12a7e74113d05a0d6617390" + ], + "index": "pypi", + "version": "==5.3.0" + }, "python-dateutil": { "hashes": [ "sha256:063df5763652e21de43de7d9e00ccf239f953a832941e37be541614732cdfc93", diff --git a/bot/cogs/candy_collection.py b/bot/cogs/hacktober/candy_collection.py index 59eadd93..f5f17abb 100644 --- a/bot/cogs/candy_collection.py +++ b/bot/cogs/hacktober/candy_collection.py @@ -1,13 +1,14 @@ -import discord -from discord.ext import commands -import random -import json import functools +import json import os +import random + +import discord +from discord.ext import commands -json_location = os.path.join(os.getcwd(), 'resources', 'candy_collection.json') +from bot.constants import HACKTOBER_CHANNEL_ID -HACKTOBER_CHANNEL_ID = 498804484324196362 +json_location = os.path.join("bot", "resources", "halloween", "candy_collection.json") # chance is 1 in x range, so 1 in 20 range would give 5% chance (for add candy) ADD_CANDY_REACTION_CHANCE = 20 # 5% @@ -126,7 +127,7 @@ class CandyCollection: for i in range(9): o = discord.Object(id=recent_msg.id + i) - msg = await channel.history(limit=1, before=o).next() + msg = await next(channel.history(limit=1, before=o)) ten_recent.append(msg.id) return ten_recent @@ -140,7 +141,7 @@ class CandyCollection: o = discord.Object(id=msg_id + 1) # Use history rather than get_message due to # poor ratelimit (50/1s vs 1/1s) - msg = await self.hacktober_channel.history(limit=1, before=o).next() + msg = await next(self.hacktober_channel.history(limit=1, before=o)) if msg.id != msg_id: return None diff --git a/bot/cogs/hacktober/monstersurvey.py b/bot/cogs/hacktober/monstersurvey.py index 9f33e31b..45587fe1 100644 --- a/bot/cogs/hacktober/monstersurvey.py +++ b/bot/cogs/hacktober/monstersurvey.py @@ -1,7 +1,6 @@ import json import logging import os -from typing import Optional, Union from discord import Embed from discord.ext import commands @@ -91,7 +90,7 @@ class MonsterSurvey: @monster_group.command( name='vote' ) - async def monster_vote(self, ctx: Context, name = None): + async def monster_vote(self, ctx: Context, name=None): """Casts a vote for a particular monster, or displays a list of monsters that can be voted for if one is not given.""" if name is None: @@ -133,7 +132,7 @@ class MonsterSurvey: @monster_group.command( name='show' ) - async def monster_show(self, ctx: Context, name = None): + async def monster_show(self, ctx: Context, name=None): """ Shows the named monster. If one is not named, it sends the default voting embed instead. :param ctx: diff --git a/bot/cogs/hacktober/spookyavatar.py b/bot/cogs/hacktober/spookyavatar.py new file mode 100644 index 00000000..ad8a9242 --- /dev/null +++ b/bot/cogs/hacktober/spookyavatar.py @@ -0,0 +1,52 @@ +import os +from io import BytesIO + +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/constants.py b/bot/constants.py index e69de29b..7d00a360 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -0,0 +1 @@ +HACKTOBER_CHANNEL_ID = 498804484324196362 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/cogs/resources/candy_collection.json b/bot/resources/halloween/candy_collection.json index 6313dd10..6313dd10 100644 --- a/bot/cogs/resources/candy_collection.json +++ b/bot/resources/halloween/candy_collection.json 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..5f2369ae --- /dev/null +++ b/bot/utils/spookifications.py @@ -0,0 +1,55 @@ +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/halloween/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/halloween/bat-clipart.png') + bat_size = randint(wt//10, wt//7) + rot = randint(0, 90) + bat = bat.resize((bat_size, bat_size)) + bat = bat.rotate(rot) + x = randint(wt-(bat_size * 3), wt-bat_size) + y = randint(10, bat_size) + im.paste(bat, (x, y), bat) + im.paste(bat, (x + bat_size, y + (bat_size // 4)), bat) + im.paste(bat, (x - bat_size, y - (bat_size // 2)), 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) |