aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/easter
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons/easter')
-rw-r--r--bot/seasons/easter/april_fools_vids.py8
-rw-r--r--bot/seasons/easter/avatar_easterifier.py14
-rw-r--r--bot/seasons/easter/bunny_name_generator.py21
-rw-r--r--bot/seasons/easter/conversationstarters.py6
-rw-r--r--bot/seasons/easter/easter_riddle.py10
-rw-r--r--bot/seasons/easter/egg_decorating.py10
-rw-r--r--bot/seasons/easter/egg_facts.py12
-rw-r--r--bot/seasons/easter/egg_hunt/__init__.py4
-rw-r--r--bot/seasons/easter/egg_hunt/cog.py32
-rw-r--r--bot/seasons/easter/egghead_quiz.py15
-rw-r--r--bot/seasons/easter/traditions.py8
11 files changed, 73 insertions, 67 deletions
diff --git a/bot/seasons/easter/april_fools_vids.py b/bot/seasons/easter/april_fools_vids.py
index d921d07c..4869f510 100644
--- a/bot/seasons/easter/april_fools_vids.py
+++ b/bot/seasons/easter/april_fools_vids.py
@@ -11,13 +11,13 @@ log = logging.getLogger(__name__)
class AprilFoolVideos(commands.Cog):
"""A cog for April Fools' that gets a random April Fools' video from Youtube."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.yt_vids = self.load_json()
self.youtubers = ['google'] # will add more in future
@staticmethod
- def load_json():
+ def load_json() -> dict:
"""A function to load JSON data."""
p = Path('bot/resources/easter/april_fools_vids.json')
with p.open() as json_file:
@@ -25,7 +25,7 @@ class AprilFoolVideos(commands.Cog):
return all_vids
@commands.command(name='fool')
- async def aprial_fools(self, ctx):
+ async def april_fools(self, ctx: commands.Context) -> None:
"""Get a random April Fools' video from Youtube."""
random_youtuber = random.choice(self.youtubers)
category = self.yt_vids[random_youtuber]
@@ -33,7 +33,7 @@ class AprilFoolVideos(commands.Cog):
await ctx.send(f"Check out this April Fools' video by {random_youtuber}.\n\n{random_vid['link']}")
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""April Fools' Cog load."""
bot.add_cog(AprilFoolVideos(bot))
log.info('April Fools videos cog loaded!')
diff --git a/bot/seasons/easter/avatar_easterifier.py b/bot/seasons/easter/avatar_easterifier.py
index 98e15982..f056068e 100644
--- a/bot/seasons/easter/avatar_easterifier.py
+++ b/bot/seasons/easter/avatar_easterifier.py
@@ -2,7 +2,7 @@ import asyncio
import logging
from io import BytesIO
from pathlib import Path
-from typing import Union
+from typing import Tuple, Union
import discord
from PIL import Image
@@ -21,11 +21,11 @@ COLOURS = [
class AvatarEasterifier(commands.Cog):
"""Put an Easter spin on your avatar or image!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@staticmethod
- def closest(x):
+ def closest(x: Tuple[int, int, int]) -> Tuple[int, int, int]:
"""
Finds the closest easter colour to a given pixel.
@@ -33,8 +33,8 @@ class AvatarEasterifier(commands.Cog):
"""
r1, g1, b1 = x
- def distance(point):
- """Finds the difference between a pastel colour and the original pixel colour."""
+ def distance(point: Tuple[int, int, int]) -> Tuple[int, int, int]:
+ """Finds the difference between a pastel colour and the original pixel colour"""
r2, g2, b2 = point
return ((r1 - r2)**2 + (g1 - g2)**2 + (b1 - b2)**2)
@@ -47,7 +47,7 @@ class AvatarEasterifier(commands.Cog):
return (r, g, b)
@commands.command(pass_context=True, aliases=["easterify"])
- async def avatareasterify(self, ctx, *colours: Union[discord.Colour, str]):
+ async def avatareasterify(self, ctx: commands.Context, *colours: Union[discord.Colour, str]) -> None:
"""
This "Easterifies" the user's avatar.
@@ -123,7 +123,7 @@ class AvatarEasterifier(commands.Cog):
await ctx.send(file=file, embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Avatar Easterifier Cog load."""
bot.add_cog(AvatarEasterifier(bot))
log.info("AvatarEasterifier cog loaded")
diff --git a/bot/seasons/easter/bunny_name_generator.py b/bot/seasons/easter/bunny_name_generator.py
index 3ceaeb9e..22957b7f 100644
--- a/bot/seasons/easter/bunny_name_generator.py
+++ b/bot/seasons/easter/bunny_name_generator.py
@@ -3,6 +3,7 @@ import logging
import random
import re
from pathlib import Path
+from typing import List, Union
from discord.ext import commands
@@ -15,16 +16,16 @@ with Path("bot/resources/easter/bunny_names.json").open("r", encoding="utf8") as
class BunnyNameGenerator(commands.Cog):
"""Generate a random bunny name, or bunnify your Discord username!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
- def find_separators(self, displayname):
+ def find_separators(self, displayname: str) -> Union[List[str], None]:
"""Check if Discord name contains spaces so we can bunnify an individual word in the name."""
new_name = re.split(r'[_.\s]', displayname)
if displayname not in new_name:
return new_name
- def find_vowels(self, displayname):
+ def find_vowels(self, displayname: str) -> str:
"""
Finds vowels in the user's display name.
@@ -45,8 +46,8 @@ class BunnyNameGenerator(commands.Cog):
if new_name != displayname:
return new_name
- def append_name(self, displayname):
- """Adds a suffix to the end of the Discord name."""
+ def append_name(self, displayname: str) -> str:
+ """Adds a suffix to the end of the Discord name"""
extensions = ['foot', 'ear', 'nose', 'tail']
suffix = random.choice(extensions)
appended_name = displayname + suffix
@@ -54,13 +55,13 @@ class BunnyNameGenerator(commands.Cog):
return appended_name
@commands.command()
- async def bunnyname(self, ctx):
- """Picks a random bunny name from a JSON file."""
+ async def bunnyname(self, ctx: commands.Context) -> None:
+ """Picks a random bunny name from a JSON file"""
await ctx.send(random.choice(BUNNY_NAMES["names"]))
@commands.command()
- async def bunnifyme(self, ctx):
- """Gets your Discord username and bunnifies it."""
+ async def bunnifyme(self, ctx: commands.Context) -> None:
+ """Gets your Discord username and bunnifies it"""
username = ctx.message.author.display_name
# If name contains spaces or other separators, get the individual words to randomly bunnify
@@ -86,7 +87,7 @@ class BunnyNameGenerator(commands.Cog):
await ctx.send(bunnified_name)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Bunny Name Generator Cog load."""
bot.add_cog(BunnyNameGenerator(bot))
log.info("BunnyNameGenerator cog loaded.")
diff --git a/bot/seasons/easter/conversationstarters.py b/bot/seasons/easter/conversationstarters.py
index c2cdf26c..3f38ae82 100644
--- a/bot/seasons/easter/conversationstarters.py
+++ b/bot/seasons/easter/conversationstarters.py
@@ -14,16 +14,16 @@ with open(Path("bot/resources/easter/starter.json"), "r", encoding="utf8") as f:
class ConvoStarters(commands.Cog):
"""Easter conversation topics."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command()
- async def topic(self, ctx):
+ async def topic(self, ctx: commands.Context) -> None:
"""Responds with a random topic to start a conversation."""
await ctx.send(random.choice(starters['starters']))
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Conversation starters Cog load."""
bot.add_cog(ConvoStarters(bot))
log.info("ConvoStarters cog loaded")
diff --git a/bot/seasons/easter/easter_riddle.py b/bot/seasons/easter/easter_riddle.py
index b612f8b9..c3f19055 100644
--- a/bot/seasons/easter/easter_riddle.py
+++ b/bot/seasons/easter/easter_riddle.py
@@ -20,14 +20,14 @@ TIMELIMIT = 10
class EasterRiddle(commands.Cog):
"""This cog contains the command for the Easter quiz!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.winners = []
self.correct = ""
self.current_channel = None
@commands.command(aliases=["riddlemethis", "riddleme"])
- async def riddle(self, ctx):
+ async def riddle(self, ctx: commands.Context) -> None:
"""
Gives a random riddle, then provides 2 hints at certain intervals before revealing the answer.
@@ -83,8 +83,8 @@ class EasterRiddle(commands.Cog):
self.current_channel = None
@commands.Cog.listener()
- async def on_message(self, message):
- """If a non-bot user enters a correct answer, their username gets added to self.winners."""
+ async def on_message(self, message: discord.Messaged) -> None:
+ """If a non-bot user enters a correct answer, their username gets added to self.winners"""
if self.current_channel != message.channel:
return
@@ -95,7 +95,7 @@ class EasterRiddle(commands.Cog):
self.winners.append(message.author.mention)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Easter Riddle Cog load."""
bot.add_cog(EasterRiddle(bot))
log.info("Easter Riddle bot loaded")
diff --git a/bot/seasons/easter/egg_decorating.py b/bot/seasons/easter/egg_decorating.py
index ee8a80e5..51f52264 100644
--- a/bot/seasons/easter/egg_decorating.py
+++ b/bot/seasons/easter/egg_decorating.py
@@ -31,11 +31,11 @@ IRREPLACEABLE = [
class EggDecorating(commands.Cog):
"""Decorate some easter eggs!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@staticmethod
- def replace_invalid(colour: str):
+ def replace_invalid(colour: str) -> Union[int, None]:
"""Attempts to match with HTML or XKCD colour names, returning the int value."""
with suppress(KeyError):
return int(HTML_COLOURS[colour], 16)
@@ -44,7 +44,9 @@ class EggDecorating(commands.Cog):
return None
@commands.command(aliases=["decorateegg"])
- async def eggdecorate(self, ctx, *colours: Union[discord.Colour, str]):
+ async def eggdecorate(
+ self, ctx: commands.Context, *colours: Union[discord.Colour, str]
+ ) -> Union[Image, discord.Message]:
"""
Picks a random egg design and decorates it using the given colours.
@@ -111,7 +113,7 @@ class EggDecorating(commands.Cog):
return new_im
-def setup(bot):
+def setup(bot: commands.bot) -> None:
"""Egg decorating Cog load."""
bot.add_cog(EggDecorating(bot))
log.info("EggDecorating cog loaded.")
diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py
index ae08ccd4..9e6fb1cb 100644
--- a/bot/seasons/easter/egg_facts.py
+++ b/bot/seasons/easter/egg_facts.py
@@ -21,18 +21,18 @@ class EasterFacts(commands.Cog):
It also contains a background task which sends an easter egg fact in the event channel everyday.
"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.facts = self.load_json()
@staticmethod
- def load_json():
+ def load_json() -> dict:
"""Load a list of easter egg facts from the resource JSON file."""
p = Path("bot/resources/easter/easter_egg_facts.json")
with p.open(encoding="utf8") as f:
return load(f)
- async def send_egg_fact_daily(self):
+ async def send_egg_fact_daily(self) -> None:
"""A background task that sends an easter egg fact in the event channel everyday."""
channel = self.bot.get_channel(Channels.seasonalbot_chat)
while True:
@@ -41,12 +41,12 @@ class EasterFacts(commands.Cog):
await asyncio.sleep(24 * 60 * 60)
@commands.command(name='eggfact', aliases=['fact'])
- async def easter_facts(self, ctx):
+ async def easter_facts(self, ctx: commands.Context) -> None:
"""Get easter egg facts."""
embed = self.make_embed()
await ctx.send(embed=embed)
- def make_embed(self):
+ def make_embed(self) -> discord.Embed:
"""Makes a nice embed for the message to be sent."""
return discord.Embed(
colour=Colours.soft_red,
@@ -55,7 +55,7 @@ class EasterFacts(commands.Cog):
)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Easter Egg facts cog load."""
bot.loop.create_task(EasterFacts(bot).send_egg_fact_daily())
bot.add_cog(EasterFacts(bot))
diff --git a/bot/seasons/easter/egg_hunt/__init__.py b/bot/seasons/easter/egg_hunt/__init__.py
index 0e4b9e16..e7e71ccb 100644
--- a/bot/seasons/easter/egg_hunt/__init__.py
+++ b/bot/seasons/easter/egg_hunt/__init__.py
@@ -1,11 +1,13 @@
import logging
+from discord.ext import commands
+
from .cog import EggHunt
log = logging.getLogger(__name__)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Easter Egg Hunt Cog load."""
bot.add_cog(EggHunt())
log.info("EggHunt cog loaded")
diff --git a/bot/seasons/easter/egg_hunt/cog.py b/bot/seasons/easter/egg_hunt/cog.py
index a4ad27df..8178b4ef 100644
--- a/bot/seasons/easter/egg_hunt/cog.py
+++ b/bot/seasons/easter/egg_hunt/cog.py
@@ -91,7 +91,7 @@ class EggMessage:
"""Builds the SQL for adding a score to a team in the database."""
return f"UPDATE team_scores SET team_score=team_score+{score} WHERE team_id='{team_name}'"
- def finalise_score(self):
+ def finalise_score(self) -> None:
"""Sums and actions scoring for this egg drop session."""
db = sqlite3.connect(DB_PATH)
c = db.cursor()
@@ -133,7 +133,7 @@ class EggMessage:
f"FIRST({self.first}) REST({self.users})."
)
- async def start_timeout(self, seconds: int = 5):
+ async def start_timeout(self, seconds: int = 5) -> None:
"""Begins a task that will sleep until the given seconds before finalizing the session."""
if self.timeout_task:
self.timeout_task.cancel()
@@ -164,7 +164,7 @@ class EggMessage:
return True
- async def collect_reacts(self, reaction: discord.Reaction, user: discord.Member):
+ async def collect_reacts(self, reaction: discord.Reaction, user: discord.Member) -> None:
"""Handles emitted reaction_add events via listener."""
if not self.is_valid_react(reaction, user):
return
@@ -182,7 +182,7 @@ class EggMessage:
if user != self.first:
self.users.add(user)
- async def start(self):
+ async def start(self) -> None:
"""Starts the egg drop session."""
log.debug(f"EggHunt session started for message {self.message.id}.")
bot.add_listener(self.collect_reacts, name="on_reaction_add")
@@ -207,7 +207,7 @@ class SuperEggMessage(EggMessage):
super().__init__(message, egg)
self.window = window
- async def finalise_score(self):
+ async def finalise_score(self) -> None:
"""Sums and actions scoring for this super egg session."""
try:
message = await self.message.channel.fetch_message(self.message.id)
@@ -280,7 +280,7 @@ class SuperEggMessage(EggMessage):
with contextlib.suppress(discord.HTTPException):
await self.message.edit(embed=embed)
- async def start_timeout(self, seconds=None):
+ async def start_timeout(self, seconds: int = None) -> None:
"""Starts the super egg session."""
if not seconds:
return
@@ -337,7 +337,7 @@ class EggHunt(commands.Cog):
self.task = asyncio.create_task(self.super_egg())
self.task.add_done_callback(self.task_cleanup)
- def prepare_db(self):
+ def prepare_db(self) -> None:
"""Ensures database tables all exist and if not, creates them."""
db = sqlite3.connect(DB_PATH)
c = db.cursor()
@@ -358,7 +358,7 @@ class EggHunt(commands.Cog):
db.commit()
db.close()
- def task_cleanup(self, task):
+ def task_cleanup(self, task: asyncio.Task) -> None:
"""Returns task result and restarts. Used as a done callback to show raised exceptions."""
task.result()
self.task = asyncio.create_task(self.super_egg())
@@ -368,7 +368,7 @@ class EggHunt(commands.Cog):
"""Returns a timestamp of the current UTC time."""
return datetime.utcnow().replace(tzinfo=timezone.utc).timestamp()
- async def super_egg(self):
+ async def super_egg(self) -> None:
"""Manages the timing of super egg drops."""
while True:
now = int(self.current_timestamp())
@@ -455,7 +455,7 @@ class EggHunt(commands.Cog):
await asyncio.sleep(next_loop)
@commands.Cog.listener()
- async def on_raw_reaction_add(self, payload):
+ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None:
"""Reaction event listener for reaction logging for later anti-cheat analysis."""
if payload.channel_id not in EggHuntSettings.allowed_channels:
return
@@ -471,7 +471,7 @@ class EggHunt(commands.Cog):
db.close()
@commands.Cog.listener()
- async def on_message(self, message):
+ async def on_message(self, message: discord.Message) -> None:
"""Message event listener for random egg drops."""
if self.current_timestamp() < EggHuntSettings.start_time:
return
@@ -487,7 +487,7 @@ class EggHunt(commands.Cog):
await EggMessage(message, random.choice([Emoji.egg_white, Emoji.egg_blurple])).start()
@commands.group(invoke_without_command=True)
- async def hunt(self, ctx):
+ async def hunt(self, ctx: commands.Context) -> None:
"""
For 48 hours, hunt down as many eggs randomly appearing as possible.
@@ -514,7 +514,7 @@ class EggHunt(commands.Cog):
await ctx.invoke(bot.get_command("help"), command="hunt")
@hunt.command()
- async def countdown(self, ctx):
+ async def countdown(self, ctx: commands.Context) -> None:
"""Show the time status of the Egg Hunt event."""
now = self.current_timestamp()
if now > EggHuntSettings.end_time:
@@ -532,7 +532,7 @@ class EggHunt(commands.Cog):
await ctx.send(f"{msg} {hours:.0f}hrs, {minutes:.0f}mins & {r:.0f}secs")
@hunt.command()
- async def leaderboard(self, ctx):
+ async def leaderboard(self, ctx: commands.Context) -> None:
"""Show the Egg Hunt Leaderboards."""
db = sqlite3.connect(DB_PATH)
c = db.cursor()
@@ -573,7 +573,7 @@ class EggHunt(commands.Cog):
await ctx.send(embed=embed)
@hunt.command()
- async def rank(self, ctx, *, member: discord.Member = None):
+ async def rank(self, ctx: commands.Context, *, member: discord.Member = None) -> None:
"""Get your ranking in the Egg Hunt Leaderboard."""
member = member or ctx.author
db = sqlite3.connect(DB_PATH)
@@ -593,7 +593,7 @@ class EggHunt(commands.Cog):
@with_role(MainRoles.admin)
@hunt.command()
- async def clear_db(self, ctx):
+ async def clear_db(self, ctx: commands.Context) -> None:
"""Resets the database to it's initial state."""
def check(msg):
if msg.author != ctx.author:
diff --git a/bot/seasons/easter/egghead_quiz.py b/bot/seasons/easter/egghead_quiz.py
index b3841993..0b175bf1 100644
--- a/bot/seasons/easter/egghead_quiz.py
+++ b/bot/seasons/easter/egghead_quiz.py
@@ -3,6 +3,7 @@ import logging
import random
from json import load
from pathlib import Path
+from typing import Union
import discord
from discord.ext import commands
@@ -30,12 +31,12 @@ TIMELIMIT = 30
class EggheadQuiz(commands.Cog):
"""This cog contains the command for the Easter quiz!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
self.quiz_messages = {}
@commands.command(aliases=["eggheadquiz", "easterquiz"])
- async def eggquiz(self, ctx):
+ async def eggquiz(self, ctx: commands.Context) -> None:
"""
Gives a random quiz question, waits 30 seconds and then outputs the answer.
@@ -95,14 +96,14 @@ class EggheadQuiz(commands.Cog):
await ctx.send(content, embed=a_embed)
@staticmethod
- async def already_reacted(message, user):
- """Returns whether a given user has reacted more than once to a given message."""
+ async def already_reacted(message: discord.Message, user: Union[discord.Member, discord.User]) -> bool:
+ """Returns whether a given user has reacted more than once to a given message"""
users = [u.id for reaction in [await r.users().flatten() for r in message.reactions] for u in reaction]
return users.count(user.id) > 1 # Old reaction plus new reaction
@commands.Cog.listener()
- async def on_reaction_add(self, reaction, user):
- """Listener to listen specifically for reactions of quiz messages."""
+ async def on_reaction_add(self, reaction: discord.Reaction, user: Union[discord.Member, discord.User]) -> None:
+ """Listener to listen specifically for reactions of quiz messages"""
if user.bot:
return
if reaction.message.id not in self.quiz_messages:
@@ -113,7 +114,7 @@ class EggheadQuiz(commands.Cog):
return await reaction.message.remove_reaction(reaction, user)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Egghead Quiz Cog load."""
bot.add_cog(EggheadQuiz(bot))
log.info("EggheadQuiz bot loaded")
diff --git a/bot/seasons/easter/traditions.py b/bot/seasons/easter/traditions.py
index b0bf04d7..4fb4694f 100644
--- a/bot/seasons/easter/traditions.py
+++ b/bot/seasons/easter/traditions.py
@@ -14,18 +14,18 @@ with open(Path("bot/resources/easter/traditions.json"), "r", encoding="utf8") as
class Traditions(commands.Cog):
"""A cog which allows users to get a random easter tradition or custom from a random country."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(aliases=('eastercustoms',))
- async def easter_tradition(self, ctx):
- """Responds with a random tradition or custom."""
+ async def easter_tradition(self, ctx: commands.Context) -> None:
+ """Responds with a random tradition or custom"""
random_country = random.choice(list(traditions))
await ctx.send(f"{random_country}:\n{traditions[random_country]}")
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Traditions Cog load."""
bot.add_cog(Traditions(bot))
log.info("Traditions cog loaded")