diff options
Diffstat (limited to 'bot')
| -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 |
9 files changed, 119 insertions, 11 deletions
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) |