aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/__init__.py2
-rw-r--r--bot/decorators.py6
-rw-r--r--bot/seasons/pride/pride_anthem.py6
-rw-r--r--bot/seasons/pride/pride_avatar.py12
-rw-r--r--bot/seasons/valentines/be_my_valentine.py34
-rw-r--r--bot/seasons/valentines/lovecalculator.py6
-rw-r--r--bot/seasons/valentines/movie_generator.py6
-rw-r--r--bot/seasons/valentines/myvalenstate.py8
-rw-r--r--bot/seasons/valentines/pickuplines.py6
-rw-r--r--bot/seasons/valentines/savethedate.py6
-rw-r--r--bot/seasons/valentines/valentine_zodiac.py8
-rw-r--r--bot/seasons/valentines/whoisvalentine.py8
-rw-r--r--bot/utils/__init__.py4
-rw-r--r--bot/utils/halloween/spookifications.py8
14 files changed, 62 insertions, 58 deletions
diff --git a/bot/__init__.py b/bot/__init__.py
index 8950423f..4729e50c 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -13,7 +13,7 @@ logging.TRACE = 5
logging.addLevelName(logging.TRACE, "TRACE")
-def monkeypatch_trace(self, msg: str, *args, **kwargs) -> None:
+def monkeypatch_trace(self: logging.Logger, msg: str, *args, **kwargs) -> None:
"""
Log 'msg % args' with severity 'TRACE'.
diff --git a/bot/decorators.py b/bot/decorators.py
index e12c3f34..dbaad4a2 100644
--- a/bot/decorators.py
+++ b/bot/decorators.py
@@ -117,7 +117,7 @@ def override_in_channel(func: typing.Callable) -> typing.Callable:
return func
-def locked():
+def locked() -> typing.Union[typing.Callable, None]:
"""
Allows the user to only run one instance of the decorated command at a time.
@@ -125,11 +125,11 @@ def locked():
This decorator has to go before (below) the `command` decorator.
"""
- def wrap(func: typing.Callable):
+ def wrap(func: typing.Callable) -> typing.Union[typing.Callable, None]:
func.__locks = WeakValueDictionary()
@wraps(func)
- async def inner(self, ctx: Context, *args, **kwargs):
+ async def inner(self: typing.Callable, ctx: Context, *args, **kwargs) -> typing.Union[typing.Callable, None]:
lock = func.__locks.setdefault(ctx.author.id, Lock())
if lock.locked():
embed = Embed()
diff --git a/bot/seasons/pride/pride_anthem.py b/bot/seasons/pride/pride_anthem.py
index f226f4bb..b0c6d34e 100644
--- a/bot/seasons/pride/pride_anthem.py
+++ b/bot/seasons/pride/pride_anthem.py
@@ -11,7 +11,7 @@ log = logging.getLogger(__name__)
class PrideAnthem(commands.Cog):
"""Embed a random youtube video for a gay anthem!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.anthems = self.load_vids()
@@ -39,7 +39,7 @@ class PrideAnthem(commands.Cog):
return anthems
@commands.command(name="prideanthem", aliases=["anthem", "pridesong"])
- async def prideanthem(self, ctx, genre: str = None):
+ async def prideanthem(self, ctx: commands.Context, genre: str = None) -> None:
"""
Sends a message with a video of a random pride anthem.
@@ -52,7 +52,7 @@ class PrideAnthem(commands.Cog):
await ctx.send("I couldn't find a video, sorry!")
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Cog loader for pride anthem."""
bot.add_cog(PrideAnthem(bot))
log.info("Pride anthems cog loaded!")
diff --git a/bot/seasons/pride/pride_avatar.py b/bot/seasons/pride/pride_avatar.py
index a5b38d20..85e49d5c 100644
--- a/bot/seasons/pride/pride_avatar.py
+++ b/bot/seasons/pride/pride_avatar.py
@@ -56,11 +56,11 @@ OPTIONS = {
class PrideAvatar(commands.Cog):
"""Put an LGBT spin on your avatar!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@staticmethod
- def crop_avatar(avatar):
+ def crop_avatar(avatar: Image) -> Image:
"""This crops the avatar into a circle."""
mask = Image.new("L", avatar.size, 0)
draw = ImageDraw.Draw(mask)
@@ -69,7 +69,7 @@ class PrideAvatar(commands.Cog):
return avatar
@staticmethod
- def crop_ring(ring, px):
+ def crop_ring(ring: Image, px: int) -> Image:
"""This crops the ring into a circle."""
mask = Image.new("L", ring.size, 0)
draw = ImageDraw.Draw(mask)
@@ -79,7 +79,7 @@ class PrideAvatar(commands.Cog):
return ring
@commands.group(aliases=["avatarpride", "pridepfp", "prideprofile"], invoke_without_command=True)
- async def prideavatar(self, ctx, option="lgbt", pixels: int = 64):
+ async def prideavatar(self, ctx: commands.Context, option: str = "lgbt", pixels: int = 64) -> None:
"""
This surrounds an avatar with a border of a specified LGBT flag.
@@ -126,7 +126,7 @@ class PrideAvatar(commands.Cog):
await ctx.send(file=file, embed=embed)
@prideavatar.command()
- async def flags(self, ctx):
+ async def flags(self, ctx: commands.Context) -> None:
"""This lists the flags that can be used with the prideavatar command."""
choices = sorted(set(OPTIONS.values()))
options = "• " + "\n• ".join(choices)
@@ -139,7 +139,7 @@ class PrideAvatar(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Cog load."""
bot.add_cog(PrideAvatar(bot))
log.info("PrideAvatar cog loaded")
diff --git a/bot/seasons/valentines/be_my_valentine.py b/bot/seasons/valentines/be_my_valentine.py
index c4acf17a..a073e1bd 100644
--- a/bot/seasons/valentines/be_my_valentine.py
+++ b/bot/seasons/valentines/be_my_valentine.py
@@ -1,8 +1,8 @@
import logging
import random
-import typing
from json import load
from pathlib import Path
+from typing import Optional, Tuple
import discord
from discord.ext import commands
@@ -18,12 +18,12 @@ HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_hea
class BeMyValentine(commands.Cog):
"""A cog that sends Valentines to other users!"""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.valentines = self.load_json()
@staticmethod
- def load_json():
+ def load_json() -> dict:
"""Load Valentines messages from the static resources."""
p = Path("bot/resources/valentines/bemyvalentine_valentines.json")
with p.open() as json_data:
@@ -31,7 +31,7 @@ class BeMyValentine(commands.Cog):
return valentines
@commands.group(name="lovefest", invoke_without_command=True)
- async def lovefest_role(self, ctx):
+ async def lovefest_role(self, ctx: commands.Context) -> None:
"""
Subscribe or unsubscribe from the lovefest role.
@@ -43,7 +43,7 @@ class BeMyValentine(commands.Cog):
await ctx.send_help(ctx.command)
@lovefest_role.command(name="sub")
- async def add_role(self, ctx):
+ async def add_role(self, ctx: commands.Context) -> None:
"""Adds the lovefest role."""
user = ctx.author
role = discord.utils.get(ctx.guild.roles, id=Lovefest.role_id)
@@ -54,7 +54,7 @@ class BeMyValentine(commands.Cog):
await ctx.send("You already have the role !")
@lovefest_role.command(name="unsub")
- async def remove_role(self, ctx):
+ async def remove_role(self, ctx: commands.Context) -> None:
"""Removes the lovefest role."""
user = ctx.author
role = discord.utils.get(ctx.guild.roles, id=Lovefest.role_id)
@@ -66,7 +66,9 @@ class BeMyValentine(commands.Cog):
@commands.cooldown(1, 1800, BucketType.user)
@commands.group(name='bemyvalentine', invoke_without_command=True)
- async def send_valentine(self, ctx, user: typing.Optional[discord.Member] = None, *, valentine_type=None):
+ async def send_valentine(
+ self, ctx: commands.Context, user: Optional[discord.Member] = None, *, valentine_type: str = None
+ ) -> None:
"""
Send a valentine to user, if specified, or to a random user with the lovefest role.
@@ -112,7 +114,9 @@ class BeMyValentine(commands.Cog):
@commands.cooldown(1, 1800, BucketType.user)
@send_valentine.command(name='secret')
- async def anonymous(self, ctx, user: typing.Optional[discord.Member] = None, *, valentine_type=None):
+ async def anonymous(
+ self, ctx: commands.Context, user: Optional[discord.Member] = None, *, valentine_type: str = None
+ ) -> None:
"""
Send an anonymous Valentine via DM to to a user, if specified, or to a random with the lovefest role.
@@ -164,7 +168,7 @@ class BeMyValentine(commands.Cog):
else:
await ctx.author.send(f"Your message has been sent to {user}")
- def valentine_check(self, valentine_type):
+ def valentine_check(self, valentine_type: str) -> Tuple[str, str]:
"""Return the appropriate Valentine type & title based on the invoking user's input."""
if valentine_type is None:
valentine, title = self.random_valentine()
@@ -184,7 +188,7 @@ class BeMyValentine(commands.Cog):
return valentine, title
@staticmethod
- def random_user(author: discord.Member, members: discord.Member):
+ def random_user(author: discord.Member, members: discord.Member) -> None:
"""
Picks a random member from the list provided in `members`.
@@ -196,13 +200,13 @@ class BeMyValentine(commands.Cog):
return random.choice(members) if members else None
@staticmethod
- def random_emoji():
+ def random_emoji() -> Tuple[str, str]:
"""Return two random emoji from the module-defined constants."""
EMOJI_1 = random.choice(HEART_EMOJIS)
EMOJI_2 = random.choice(HEART_EMOJIS)
return EMOJI_1, EMOJI_2
- def random_valentine(self):
+ def random_valentine(self) -> Tuple[str, str]:
"""Grabs a random poem or a compliment (any message)."""
valentine_poem = random.choice(self.valentines['valentine_poems'])
valentine_compliment = random.choice(self.valentines['valentine_compliments'])
@@ -213,18 +217,18 @@ class BeMyValentine(commands.Cog):
title = 'A compliment for '
return random_valentine, title
- def valentine_poem(self):
+ def valentine_poem(self) -> str:
"""Grabs a random poem."""
valentine_poem = random.choice(self.valentines['valentine_poems'])
return valentine_poem
- def valentine_compliment(self):
+ def valentine_compliment(self) -> str:
"""Grabs a random compliment."""
valentine_compliment = random.choice(self.valentines['valentine_compliments'])
return valentine_compliment
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Be my Valentine Cog load."""
bot.add_cog(BeMyValentine(bot))
log.info("BeMyValentine cog loaded")
diff --git a/bot/seasons/valentines/lovecalculator.py b/bot/seasons/valentines/lovecalculator.py
index 1d5a028d..207ef557 100644
--- a/bot/seasons/valentines/lovecalculator.py
+++ b/bot/seasons/valentines/lovecalculator.py
@@ -23,12 +23,12 @@ with Path("bot/resources/valentines/love_matches.json").open() as file:
class LoveCalculator(Cog):
"""A cog for calculating the love between two people."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(aliases=('love_calculator', 'love_calc'))
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
- async def love(self, ctx, who: Union[Member, str], whom: Union[Member, str] = None):
+ async def love(self, ctx: commands.Context, who: Union[Member, str], whom: Union[Member, str] = None) -> None:
"""
Tells you how much the two love each other.
@@ -98,7 +98,7 @@ class LoveCalculator(Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Love calculator Cog load."""
bot.add_cog(LoveCalculator(bot))
log.info("LoveCalculator cog loaded")
diff --git a/bot/seasons/valentines/movie_generator.py b/bot/seasons/valentines/movie_generator.py
index fa5f236a..ce1d7d5b 100644
--- a/bot/seasons/valentines/movie_generator.py
+++ b/bot/seasons/valentines/movie_generator.py
@@ -14,11 +14,11 @@ log = logging.getLogger(__name__)
class RomanceMovieFinder(commands.Cog):
"""A Cog that returns a random romance movie suggestion to a user."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(name="romancemovie")
- async def romance_movie(self, ctx):
+ async def romance_movie(self, ctx: commands.Context) -> None:
"""Randomly selects a romance movie and displays information about it."""
# Selecting a random int to parse it to the page parameter
random_page = random.randint(0, 20)
@@ -57,7 +57,7 @@ class RomanceMovieFinder(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Romance movie Cog load."""
bot.add_cog(RomanceMovieFinder(bot))
log.info("RomanceMovieFinder cog loaded")
diff --git a/bot/seasons/valentines/myvalenstate.py b/bot/seasons/valentines/myvalenstate.py
index fad202e3..0256c39a 100644
--- a/bot/seasons/valentines/myvalenstate.py
+++ b/bot/seasons/valentines/myvalenstate.py
@@ -18,10 +18,10 @@ with open(Path("bot/resources/valentines/valenstates.json"), "r") as file:
class MyValenstate(commands.Cog):
"""A Cog to find your most likely Valentine's vacation destination."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
- def levenshtein(self, source, goal):
+ def levenshtein(self, source: str, goal: str) -> int:
"""Calculates the Levenshtein Distance between source and goal."""
if len(source) < len(goal):
return self.levenshtein(goal, source)
@@ -42,7 +42,7 @@ class MyValenstate(commands.Cog):
return pre_row[-1]
@commands.command()
- async def myvalenstate(self, ctx, *, name=None):
+ async def myvalenstate(self, ctx: commands.Context, *, name: str = None) -> None:
"""Find the vacation spot(s) with the most matching characters to the invoking user."""
eq_chars = collections.defaultdict(int)
if name is None:
@@ -81,7 +81,7 @@ class MyValenstate(commands.Cog):
await ctx.channel.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Valenstate Cog load."""
bot.add_cog(MyValenstate(bot))
log.info("MyValenstate cog loaded")
diff --git a/bot/seasons/valentines/pickuplines.py b/bot/seasons/valentines/pickuplines.py
index 46772197..8b2c9822 100644
--- a/bot/seasons/valentines/pickuplines.py
+++ b/bot/seasons/valentines/pickuplines.py
@@ -17,11 +17,11 @@ with open(Path("bot/resources/valentines/pickup_lines.json"), "r", encoding="utf
class PickupLine(commands.Cog):
"""A cog that gives random cheesy pickup lines."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command()
- async def pickupline(self, ctx):
+ async def pickupline(self, ctx: commands.Context) -> None:
"""
Gives you a random pickup line.
@@ -39,7 +39,7 @@ class PickupLine(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Pickup lines Cog load."""
bot.add_cog(PickupLine(bot))
log.info('PickupLine cog loaded')
diff --git a/bot/seasons/valentines/savethedate.py b/bot/seasons/valentines/savethedate.py
index 34264183..e0bc3904 100644
--- a/bot/seasons/valentines/savethedate.py
+++ b/bot/seasons/valentines/savethedate.py
@@ -19,11 +19,11 @@ with open(Path("bot/resources/valentines/date_ideas.json"), "r", encoding="utf8"
class SaveTheDate(commands.Cog):
"""A cog that gives random suggestion for a Valentine's date."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command()
- async def savethedate(self, ctx):
+ async def savethedate(self, ctx: commands.Context) -> None:
"""Gives you ideas for what to do on a date with your valentine."""
random_date = random.choice(VALENTINES_DATES['ideas'])
emoji_1 = random.choice(HEART_EMOJIS)
@@ -36,7 +36,7 @@ class SaveTheDate(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Save the date Cog Load."""
bot.add_cog(SaveTheDate(bot))
log.info("SaveTheDate cog loaded")
diff --git a/bot/seasons/valentines/valentine_zodiac.py b/bot/seasons/valentines/valentine_zodiac.py
index fa849cb2..c8d77e75 100644
--- a/bot/seasons/valentines/valentine_zodiac.py
+++ b/bot/seasons/valentines/valentine_zodiac.py
@@ -17,12 +17,12 @@ HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_hea
class ValentineZodiac(commands.Cog):
"""A Cog that returns a counter compatible zodiac sign to the given user's zodiac sign."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.zodiacs = self.load_json()
@staticmethod
- def load_json():
+ def load_json() -> dict:
"""Load zodiac compatibility from static JSON resource."""
p = Path("bot/resources/valentines/zodiac_compatibility.json")
with p.open() as json_data:
@@ -30,7 +30,7 @@ class ValentineZodiac(commands.Cog):
return zodiacs
@commands.command(name="partnerzodiac")
- async def counter_zodiac(self, ctx, zodiac_sign):
+ async def counter_zodiac(self, ctx: commands.Context, zodiac_sign: str) -> None:
"""Provides a counter compatible zodiac sign to the given user's zodiac sign."""
try:
compatible_zodiac = random.choice(self.zodiacs[zodiac_sign.lower()])
@@ -52,7 +52,7 @@ class ValentineZodiac(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Valentine zodiac Cog load."""
bot.add_cog(ValentineZodiac(bot))
log.info("ValentineZodiac cog loaded")
diff --git a/bot/seasons/valentines/whoisvalentine.py b/bot/seasons/valentines/whoisvalentine.py
index d73ccd9b..b8586dca 100644
--- a/bot/seasons/valentines/whoisvalentine.py
+++ b/bot/seasons/valentines/whoisvalentine.py
@@ -17,11 +17,11 @@ with open(Path("bot/resources/valentines/valentine_facts.json"), "r") as file:
class ValentineFacts(commands.Cog):
"""A Cog for displaying facts about Saint Valentine."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(aliases=('whoisvalentine', 'saint_valentine'))
- async def who_is_valentine(self, ctx):
+ async def who_is_valentine(self, ctx: commands.Context) -> None:
"""Displays info about Saint Valentine."""
embed = discord.Embed(
title="Who is Saint Valentine?",
@@ -36,7 +36,7 @@ class ValentineFacts(commands.Cog):
await ctx.channel.send(embed=embed)
@commands.command()
- async def valentine_fact(self, ctx):
+ async def valentine_fact(self, ctx: commands.Context) -> None:
"""Shows a random fact about Valentine's Day."""
embed = discord.Embed(
title=choice(FACTS['titles']),
@@ -47,7 +47,7 @@ class ValentineFacts(commands.Cog):
await ctx.channel.send(embed=embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Who is Valentine Cog load."""
bot.add_cog(ValentineFacts(bot))
log.info("ValentineFacts cog loaded")
diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py
index 3249a9cf..8732eb22 100644
--- a/bot/utils/__init__.py
+++ b/bot/utils/__init__.py
@@ -29,7 +29,7 @@ async def disambiguate(
choices = (f'{index}: {entry}' for index, entry in enumerate(entries, start=1))
- def check(message):
+ def check(message: discord.Message) -> bool:
return (message.content.isdigit()
and message.author == ctx.author
and message.channel == ctx.channel)
@@ -109,7 +109,7 @@ def replace_many(
pattern = "|".join(re.escape(word) for word in words_to_replace)
regex = re.compile(pattern, re.I if ignore_case else 0)
- def _repl(match):
+ def _repl(match: re.Match) -> str:
"""Returns replacement depending on `ignore_case` and `match_case`"""
word = match.group(0)
replacement = replacements[word.lower() if ignore_case else word]
diff --git a/bot/utils/halloween/spookifications.py b/bot/utils/halloween/spookifications.py
index 69b49919..11f69850 100644
--- a/bot/utils/halloween/spookifications.py
+++ b/bot/utils/halloween/spookifications.py
@@ -7,7 +7,7 @@ from PIL import ImageOps
log = logging.getLogger()
-def inversion(im):
+def inversion(im: Image) -> Image:
"""
Inverts the image.
@@ -18,7 +18,7 @@ def inversion(im):
return inv
-def pentagram(im):
+def pentagram(im: Image) -> Image:
"""Adds pentagram to the image."""
im = im.convert('RGB')
wt, ht = im.size
@@ -28,7 +28,7 @@ def pentagram(im):
return im
-def bat(im):
+def bat(im: Image) -> Image:
"""
Adds a bat silhoutte to the image.
@@ -50,7 +50,7 @@ def bat(im):
return im
-def get_random_effect(im):
+def get_random_effect(im: Image) -> Image:
"""Randomly selects and applies an effect."""
effects = [inversion, pentagram, bat]
effect = choice(effects)