aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/halloween
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons/halloween')
-rw-r--r--bot/seasons/halloween/8ball.py6
-rw-r--r--bot/seasons/halloween/candy_collection.py25
-rw-r--r--bot/seasons/halloween/halloween_facts.py13
-rw-r--r--bot/seasons/halloween/halloweenify.py6
-rw-r--r--bot/seasons/halloween/monstersurvey.py12
-rw-r--r--bot/seasons/halloween/scarymovie.py10
-rw-r--r--bot/seasons/halloween/spookyavatar.py8
-rw-r--r--bot/seasons/halloween/spookygif.py6
-rw-r--r--bot/seasons/halloween/spookyrating.py6
-rw-r--r--bot/seasons/halloween/spookyreact.py8
-rw-r--r--bot/seasons/halloween/spookysound.py8
-rw-r--r--bot/seasons/halloween/timeleft.py11
12 files changed, 61 insertions, 58 deletions
diff --git a/bot/seasons/halloween/8ball.py b/bot/seasons/halloween/8ball.py
index faf59ca9..2e1c2804 100644
--- a/bot/seasons/halloween/8ball.py
+++ b/bot/seasons/halloween/8ball.py
@@ -15,11 +15,11 @@ with open(Path("bot/resources/halloween/responses.json"), "r", encoding="utf8")
class SpookyEightBall(commands.Cog):
"""Spooky Eightball answers."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(aliases=('spooky8ball',))
- async def spookyeightball(self, ctx, *, question: str):
+ async def spookyeightball(self, ctx: commands.Context, *, question: str) -> None:
"""Responds with a random response to a question."""
choice = random.choice(responses['responses'])
msg = await ctx.send(choice[0])
@@ -28,7 +28,7 @@ class SpookyEightBall(commands.Cog):
await msg.edit(content=f"{choice[0]} \n{choice[1]}")
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Spooky Eight Ball Cog Load."""
bot.add_cog(SpookyEightBall(bot))
log.info("SpookyEightBall cog loaded")
diff --git a/bot/seasons/halloween/candy_collection.py b/bot/seasons/halloween/candy_collection.py
index d35cbee5..65fa9af8 100644
--- a/bot/seasons/halloween/candy_collection.py
+++ b/bot/seasons/halloween/candy_collection.py
@@ -3,6 +3,7 @@ import json
import logging
import os
import random
+from typing import List, Union
import discord
from discord.ext import commands
@@ -23,7 +24,7 @@ ADD_SKULL_EXISTING_REACTION_CHANCE = 20 # 5%
class CandyCollection(commands.Cog):
"""Candy collection game Cog."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
with open(json_location) as candy:
self.candy_json = json.load(candy)
@@ -34,7 +35,7 @@ class CandyCollection(commands.Cog):
self.get_candyinfo[userid] = userinfo
@commands.Cog.listener()
- async def on_message(self, message):
+ async def on_message(self, message: discord.Message) -> None:
"""Randomly adds candy or skull reaction to non-bot messages in the Event channel."""
# make sure its a human message
if message.author.bot:
@@ -55,7 +56,7 @@ class CandyCollection(commands.Cog):
return await message.add_reaction('\N{CANDY}')
@commands.Cog.listener()
- async def on_reaction_add(self, reaction, user):
+ async def on_reaction_add(self, reaction: discord.Reaction, user: discord.Member) -> None:
"""Add/remove candies from a person if the reaction satisfies criteria."""
message = reaction.message
# check to ensure the reactor is human
@@ -101,7 +102,7 @@ class CandyCollection(commands.Cog):
self.candy_json['records'].append(d)
await self.remove_reactions(reaction)
- async def reacted_msg_chance(self, message):
+ async def reacted_msg_chance(self, message: discord.Message) -> None:
"""
Randomly add a skull or candy reaction to a message if there is a reaction there already.
@@ -118,7 +119,7 @@ class CandyCollection(commands.Cog):
self.msg_reacted.append(d)
return await message.add_reaction('\N{CANDY}')
- async def ten_recent_msg(self):
+ async def ten_recent_msg(self) -> List[int]:
"""Get the last 10 messages sent in the channel."""
ten_recent = []
recent_msg = max(message.id for message
@@ -135,7 +136,7 @@ class CandyCollection(commands.Cog):
return ten_recent
- async def get_message(self, msg_id):
+ async def get_message(self, msg_id: int) -> Union[discord.Message, None]:
"""Get the message from its ID."""
try:
o = discord.Object(id=msg_id + 1)
@@ -151,11 +152,11 @@ class CandyCollection(commands.Cog):
except Exception:
return None
- async def hacktober_channel(self):
+ async def hacktober_channel(self) -> discord.TextChannel:
"""Get #hacktoberbot channel from its ID."""
return self.bot.get_channel(id=Channels.seasonalbot_chat)
- async def remove_reactions(self, reaction):
+ async def remove_reactions(self, reaction: discord.Reaction) -> None:
"""Remove all candy/skull reactions."""
try:
async for user in reaction.users():
@@ -164,20 +165,20 @@ class CandyCollection(commands.Cog):
except discord.HTTPException:
pass
- async def send_spook_msg(self, author, channel, candies):
+ async def send_spook_msg(self, author: discord.Member, channel: discord.TextChannel, candies: int) -> None:
"""Send a spooky message."""
e = discord.Embed(colour=author.colour)
e.set_author(name="Ghosts and Ghouls and Jack o' lanterns at night; "
f"I took {candies} candies and quickly took flight.")
await channel.send(embed=e)
- def save_to_json(self):
+ def save_to_json(self) -> None:
"""Save JSON to a local file."""
with open(json_location, 'w') as outfile:
json.dump(self.candy_json, outfile)
@commands.command()
- async def candy(self, ctx):
+ async def candy(self, ctx: commands.Context) -> None:
"""Get the candy leaderboard and save to JSON."""
# Use run_in_executor to prevent blocking
thing = functools.partial(self.save_to_json)
@@ -213,7 +214,7 @@ class CandyCollection(commands.Cog):
await ctx.send(embed=e)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Candy Collection game Cog load."""
bot.add_cog(CandyCollection(bot))
log.info("CandyCollection cog loaded")
diff --git a/bot/seasons/halloween/halloween_facts.py b/bot/seasons/halloween/halloween_facts.py
index f09aa4ad..f8610bd3 100644
--- a/bot/seasons/halloween/halloween_facts.py
+++ b/bot/seasons/halloween/halloween_facts.py
@@ -3,6 +3,7 @@ import logging
import random
from datetime import timedelta
from pathlib import Path
+from typing import Tuple
import discord
from discord.ext import commands
@@ -28,7 +29,7 @@ INTERVAL = timedelta(hours=6).total_seconds()
class HalloweenFacts(commands.Cog):
"""A Cog for displaying interesting facts about Halloween."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
with open(Path("bot/resources/halloween/halloween_facts.json"), "r") as file:
self.halloween_facts = json.load(file)
@@ -37,31 +38,31 @@ class HalloweenFacts(commands.Cog):
random.shuffle(self.facts)
@commands.Cog.listener()
- async def on_ready(self):
+ async def on_ready(self) -> None:
"""Get event Channel object and initialize fact task loop."""
self.channel = self.bot.get_channel(Channels.seasonalbot_chat)
self.bot.loop.create_task(self._fact_publisher_task())
- def random_fact(self):
+ def random_fact(self) -> Tuple[int, str]:
"""Return a random fact from the loaded facts."""
return random.choice(self.facts)
@commands.command(name="spookyfact", aliases=("halloweenfact",), brief="Get the most recent Halloween fact")
- async def get_random_fact(self, ctx):
+ async def get_random_fact(self, ctx: commands.Context) -> None:
"""Reply with the most recent Halloween fact."""
index, fact = self.random_fact()
embed = self._build_embed(index, fact)
await ctx.send(embed=embed)
@staticmethod
- def _build_embed(index, fact):
+ def _build_embed(index: int, fact: str) -> discord.Embed:
"""Builds a Discord embed from the given fact and its index."""
emoji = random.choice(SPOOKY_EMOJIS)
title = f"{emoji} Halloween Fact #{index + 1}"
return discord.Embed(title=title, description=fact, color=PUMPKIN_ORANGE)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Halloween facts Cog load."""
bot.add_cog(HalloweenFacts(bot))
log.info("HalloweenFacts cog loaded")
diff --git a/bot/seasons/halloween/halloweenify.py b/bot/seasons/halloween/halloweenify.py
index 334781ab..dfcc2b1e 100644
--- a/bot/seasons/halloween/halloweenify.py
+++ b/bot/seasons/halloween/halloweenify.py
@@ -13,12 +13,12 @@ log = logging.getLogger(__name__)
class Halloweenify(commands.Cog):
"""A cog to change a invokers nickname to a spooky one!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.cooldown(1, 300, BucketType.user)
@commands.command()
- async def halloweenify(self, ctx):
+ async def halloweenify(self, ctx: commands.Context) -> None:
"""Change your nickname into a much spookier one!"""
async with ctx.typing():
with open(Path("bot/resources/halloween/halloweenify.json"), "r") as f:
@@ -46,7 +46,7 @@ class Halloweenify(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Halloweenify Cog load."""
bot.add_cog(Halloweenify(bot))
log.info("Halloweenify cog loaded")
diff --git a/bot/seasons/halloween/monstersurvey.py b/bot/seasons/halloween/monstersurvey.py
index 173ce8eb..cfd3edaf 100644
--- a/bot/seasons/halloween/monstersurvey.py
+++ b/bot/seasons/halloween/monstersurvey.py
@@ -30,7 +30,7 @@ class MonsterSurvey(Cog):
with open(self.registry_location, 'r') as jason:
self.voter_registry = json.load(jason)
- def json_write(self):
+ def json_write(self) -> None:
"""Write voting results to a local JSON file."""
log.info("Saved Monster Survey Results")
with open(self.registry_location, 'w') as jason:
@@ -50,7 +50,7 @@ class MonsterSurvey(Cog):
if id in vr[m]['votes'] and m != monster:
vr[m]['votes'].remove(id)
- def get_name_by_leaderboard_index(self, n):
+ def get_name_by_leaderboard_index(self, n: int) -> str:
"""Return the monster at the specified leaderboard index."""
n = n - 1
vr = self.voter_registry
@@ -62,7 +62,7 @@ class MonsterSurvey(Cog):
name='monster',
aliases=('ms',)
)
- async def monster_group(self, ctx: Context):
+ async def monster_group(self, ctx: Context) -> None:
"""The base voting command. If nothing is called, then it will return an embed."""
if ctx.invoked_subcommand is None:
async with ctx.typing():
@@ -92,7 +92,7 @@ class MonsterSurvey(Cog):
@monster_group.command(
name='vote'
)
- async def monster_vote(self, ctx: Context, name=None):
+ async def monster_vote(self, ctx: Context, name: str = None) -> None:
"""
Cast a vote for a particular monster.
@@ -143,7 +143,7 @@ class MonsterSurvey(Cog):
@monster_group.command(
name='show'
)
- async def monster_show(self, ctx: Context, name=None) -> None:
+ async def monster_show(self, ctx: Context, name: str = None) -> None:
"""Shows the named monster. If one is not named, it sends the default voting embed instead."""
if name is None:
await ctx.invoke(self.monster_leaderboard)
@@ -200,7 +200,7 @@ class MonsterSurvey(Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: Bot) -> None:
"""Monster survey Cog load."""
bot.add_cog(MonsterSurvey(bot))
log.info("MonsterSurvey cog loaded")
diff --git a/bot/seasons/halloween/scarymovie.py b/bot/seasons/halloween/scarymovie.py
index cd95a3a2..3823a3e4 100644
--- a/bot/seasons/halloween/scarymovie.py
+++ b/bot/seasons/halloween/scarymovie.py
@@ -16,11 +16,11 @@ TMDB_TOKEN = environ.get('TMDB_TOKEN')
class ScaryMovie(commands.Cog):
"""Selects a random scary movie and embeds info into Discord chat."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(name='scarymovie', alias=['smovie'])
- async def random_movie(self, ctx):
+ async def random_movie(self, ctx: commands.Context) -> None:
"""Randomly select a scary movie and display information about it."""
async with ctx.typing():
selection = await self.select_movie()
@@ -29,7 +29,7 @@ class ScaryMovie(commands.Cog):
await ctx.send(embed=movie_details)
@staticmethod
- async def select_movie():
+ async def select_movie() -> dict:
"""Selects a random movie and returns a JSON of movie details from TMDb."""
url = 'https://api.themoviedb.org/4/discover/movie'
params = {
@@ -62,7 +62,7 @@ class ScaryMovie(commands.Cog):
return await selection.json()
@staticmethod
- async def format_metadata(movie):
+ async def format_metadata(movie: dict) -> Embed:
"""Formats raw TMDb data to be embedded in Discord chat."""
# Build the relevant URLs.
movie_id = movie.get("id")
@@ -126,7 +126,7 @@ class ScaryMovie(commands.Cog):
return embed
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Scary movie Cog load."""
bot.add_cog(ScaryMovie(bot))
log.info("ScaryMovie cog loaded")
diff --git a/bot/seasons/halloween/spookyavatar.py b/bot/seasons/halloween/spookyavatar.py
index 9bdef1a8..268de3fb 100644
--- a/bot/seasons/halloween/spookyavatar.py
+++ b/bot/seasons/halloween/spookyavatar.py
@@ -15,10 +15,10 @@ log = logging.getLogger(__name__)
class SpookyAvatar(commands.Cog):
"""A cog that spookifies an avatar."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
- async def get(self, url):
+ async def get(self, url: str) -> bytes:
"""Returns the contents of the supplied URL."""
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
@@ -26,7 +26,7 @@ class SpookyAvatar(commands.Cog):
@commands.command(name='savatar', aliases=('spookyavatar', 'spookify'),
brief='Spookify an user\'s avatar.')
- async def spooky_avatar(self, ctx, user: discord.Member = None):
+ async def spooky_avatar(self, ctx: commands.Context, user: discord.Member = None) -> None:
"""A command to print the user's spookified avatar."""
if user is None:
user = ctx.message.author
@@ -47,7 +47,7 @@ class SpookyAvatar(commands.Cog):
os.remove(str(ctx.message.id)+'.png')
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Spooky avatar Cog load."""
bot.add_cog(SpookyAvatar(bot))
log.info("SpookyAvatar cog loaded")
diff --git a/bot/seasons/halloween/spookygif.py b/bot/seasons/halloween/spookygif.py
index ba2ad6e5..818de8cd 100644
--- a/bot/seasons/halloween/spookygif.py
+++ b/bot/seasons/halloween/spookygif.py
@@ -12,11 +12,11 @@ log = logging.getLogger(__name__)
class SpookyGif(commands.Cog):
"""A cog to fetch a random spooky gif from the web!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(name="spookygif", aliases=("sgif", "scarygif"))
- async def spookygif(self, ctx):
+ async def spookygif(self, ctx: commands.Context) -> None:
"""Fetches a random gif from the GIPHY API and responds with it."""
async with ctx.typing():
async with aiohttp.ClientSession() as session:
@@ -33,7 +33,7 @@ class SpookyGif(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Spooky GIF Cog load."""
bot.add_cog(SpookyGif(bot))
log.info("SpookyGif cog loaded")
diff --git a/bot/seasons/halloween/spookyrating.py b/bot/seasons/halloween/spookyrating.py
index 08c17a27..02e6f6b9 100644
--- a/bot/seasons/halloween/spookyrating.py
+++ b/bot/seasons/halloween/spookyrating.py
@@ -19,13 +19,13 @@ with Path("bot/resources/halloween/spooky_rating.json").open() as file:
class SpookyRating(commands.Cog):
"""A cog for calculating one's spooky rating"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.local_random = random.Random()
@commands.command()
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
- async def spookyrating(self, ctx, who: discord.Member = None):
+ async def spookyrating(self, ctx: commands.Context, who: discord.Member = None) -> None:
"""
Calculates the spooky rating of someone.
@@ -61,7 +61,7 @@ class SpookyRating(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Spooky Rating Cog load."""
bot.add_cog(SpookyRating(bot))
log.info("SpookyRating cog loaded")
diff --git a/bot/seasons/halloween/spookyreact.py b/bot/seasons/halloween/spookyreact.py
index 5a086072..90b1254d 100644
--- a/bot/seasons/halloween/spookyreact.py
+++ b/bot/seasons/halloween/spookyreact.py
@@ -2,7 +2,7 @@ import logging
import re
import discord
-from discord.ext.commands import Cog
+from discord.ext.commands import Bot, Cog
log = logging.getLogger(__name__)
@@ -20,11 +20,11 @@ SPOOKY_TRIGGERS = {
class SpookyReact(Cog):
"""A cog that makes the bot react to message triggers."""
- def __init__(self, bot):
+ def __init__(self, bot: Bot):
self.bot = bot
@Cog.listener()
- async def on_message(self, ctx: discord.Message):
+ async def on_message(self, ctx: discord.Message) -> None:
"""
A command to send the seasonalbot github project.
@@ -66,7 +66,7 @@ class SpookyReact(Cog):
return False
-def setup(bot):
+def setup(bot: Bot) -> None:
"""Spooky reaction Cog load."""
bot.add_cog(SpookyReact(bot))
log.info("SpookyReact cog loaded")
diff --git a/bot/seasons/halloween/spookysound.py b/bot/seasons/halloween/spookysound.py
index 44fdd9d6..e0676d0a 100644
--- a/bot/seasons/halloween/spookysound.py
+++ b/bot/seasons/halloween/spookysound.py
@@ -13,14 +13,14 @@ log = logging.getLogger(__name__)
class SpookySound(commands.Cog):
"""A cog that plays a spooky sound in a voice channel on command."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.sound_files = list(Path("bot/resources/halloween/spookysounds").glob("*.mp3"))
self.channel = None
@commands.cooldown(rate=1, per=1)
@commands.command(brief="Play a spooky sound, restricted to once per 2 mins")
- async def spookysound(self, ctx):
+ async def spookysound(self, ctx: commands.Context) -> None:
"""
Connect to the Hacktoberbot voice channel, play a random spooky sound, then disconnect.
@@ -37,12 +37,12 @@ class SpookySound(commands.Cog):
voice.play(src, after=lambda e: self.bot.loop.create_task(self.disconnect(voice)))
@staticmethod
- async def disconnect(voice):
+ async def disconnect(voice: discord.VoiceClient) -> None:
"""Helper method to disconnect a given voice client."""
await voice.disconnect()
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Spooky sound Cog load."""
bot.add_cog(SpookySound(bot))
log.info("SpookySound cog loaded")
diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py
index a2b16a6c..77767baa 100644
--- a/bot/seasons/halloween/timeleft.py
+++ b/bot/seasons/halloween/timeleft.py
@@ -1,5 +1,6 @@
import logging
from datetime import datetime
+from typing import Tuple
from discord.ext import commands
@@ -9,16 +10,16 @@ log = logging.getLogger(__name__)
class TimeLeft(commands.Cog):
"""A Cog that tells you how long left until Hacktober is over!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@staticmethod
- def in_october():
+ def in_october() -> bool:
"""Return True if the current month is October."""
return datetime.utcnow().month == 10
@staticmethod
- def load_date():
+ def load_date() -> Tuple[int, datetime, datetime]:
"""Return of a tuple of the current time and the end and start times of the next October."""
now = datetime.utcnow()
year = now.year
@@ -29,7 +30,7 @@ class TimeLeft(commands.Cog):
return now, end, start
@commands.command()
- async def timeleft(self, ctx):
+ async def timeleft(self, ctx: commands.Context) -> None:
"""
Calculates the time left until the end of Hacktober.
@@ -53,7 +54,7 @@ class TimeLeft(commands.Cog):
)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Cog load."""
bot.add_cog(TimeLeft(bot))
log.info("TimeLeft cog loaded")