aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/evergreen
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons/evergreen')
-rw-r--r--bot/seasons/evergreen/error_handler.py10
-rw-r--r--bot/seasons/evergreen/fun.py2
-rw-r--r--bot/seasons/evergreen/issues.py8
-rw-r--r--bot/seasons/evergreen/magic_8ball.py6
-rw-r--r--bot/seasons/evergreen/minesweeper.py8
-rw-r--r--bot/seasons/evergreen/showprojects.py7
-rw-r--r--bot/seasons/evergreen/snakes/__init__.py4
-rw-r--r--bot/seasons/evergreen/snakes/converter.py11
-rw-r--r--bot/seasons/evergreen/snakes/snakes_cog.py50
-rw-r--r--bot/seasons/evergreen/snakes/utils.py54
-rw-r--r--bot/seasons/evergreen/speedrun.py6
-rw-r--r--bot/seasons/evergreen/uptime.py6
12 files changed, 91 insertions, 81 deletions
diff --git a/bot/seasons/evergreen/error_handler.py b/bot/seasons/evergreen/error_handler.py
index 6690cf89..120462ee 100644
--- a/bot/seasons/evergreen/error_handler.py
+++ b/bot/seasons/evergreen/error_handler.py
@@ -4,7 +4,7 @@ import random
import sys
import traceback
-from discord import Colour, Embed
+from discord import Colour, Embed, Message
from discord.ext import commands
from bot.constants import NEGATIVE_REPLIES
@@ -16,11 +16,11 @@ log = logging.getLogger(__name__)
class CommandErrorHandler(commands.Cog):
"""A error handler for the PythonDiscord server."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@staticmethod
- def revert_cooldown_counter(command, message):
+ def revert_cooldown_counter(command: commands.Command, message: Message) -> None:
"""Undoes the last cooldown counter for user-error cases."""
if command._buckets.valid:
bucket = command._buckets.get_bucket(message)
@@ -30,7 +30,7 @@ class CommandErrorHandler(commands.Cog):
)
@commands.Cog.listener()
- async def on_command_error(self, ctx, error):
+ async def on_command_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
"""Activates when a command opens an error."""
if hasattr(ctx.command, 'on_error'):
return logging.debug(
@@ -113,7 +113,7 @@ class CommandErrorHandler(commands.Cog):
traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Error handler Cog load."""
bot.add_cog(CommandErrorHandler(bot))
log.info("CommandErrorHandler cog loaded")
diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py
index 09e447b7..4a96743f 100644
--- a/bot/seasons/evergreen/fun.py
+++ b/bot/seasons/evergreen/fun.py
@@ -142,7 +142,7 @@ class Fun(Cog):
return Embed.from_dict(embed_dict)
-def setup(bot) -> None:
+def setup(bot: commands.Bot) -> None:
"""Fun Cog load."""
bot.add_cog(Fun(bot))
log.info("Fun cog loaded")
diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py
index f19a1129..0ba74d9c 100644
--- a/bot/seasons/evergreen/issues.py
+++ b/bot/seasons/evergreen/issues.py
@@ -12,12 +12,14 @@ log = logging.getLogger(__name__)
class Issues(commands.Cog):
"""Cog that allows users to retrieve issues from GitHub."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(aliases=("issues",))
@override_in_channel
- async def issue(self, ctx, number: int, repository: str = "seasonalbot", user: str = "python-discord"):
+ async def issue(
+ self, ctx: commands.Context, number: int, repository: str = "seasonalbot", user: str = "python-discord"
+ ) -> None:
"""Command to retrieve issues from a GitHub repository."""
api_url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}"
failed_status = {
@@ -49,7 +51,7 @@ class Issues(commands.Cog):
await ctx.send(embed=issue_embed)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Github Issues Cog Load."""
bot.add_cog(Issues(bot))
log.info("Issues cog loaded")
diff --git a/bot/seasons/evergreen/magic_8ball.py b/bot/seasons/evergreen/magic_8ball.py
index 55652af7..e47ef454 100644
--- a/bot/seasons/evergreen/magic_8ball.py
+++ b/bot/seasons/evergreen/magic_8ball.py
@@ -11,13 +11,13 @@ log = logging.getLogger(__name__)
class Magic8ball(commands.Cog):
"""A Magic 8ball command to respond to a user's question."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
with open(Path("bot/resources/evergreen/magic8ball.json"), "r") as file:
self.answers = json.load(file)
@commands.command(name="8ball")
- async def output_answer(self, ctx, *, question):
+ async def output_answer(self, ctx: commands.Context, *, question: str) -> None:
"""Return a Magic 8ball answer from answers list."""
if len(question.split()) >= 3:
answer = random.choice(self.answers)
@@ -26,7 +26,7 @@ class Magic8ball(commands.Cog):
await ctx.send("Usage: .8ball <question> (minimum length of 3 eg: `will I win?`)")
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Magic 8ball Cog load."""
bot.add_cog(Magic8ball(bot))
log.info("Magic8ball cog loaded")
diff --git a/bot/seasons/evergreen/minesweeper.py b/bot/seasons/evergreen/minesweeper.py
index 3eee92ca..b0ba8145 100644
--- a/bot/seasons/evergreen/minesweeper.py
+++ b/bot/seasons/evergreen/minesweeper.py
@@ -32,7 +32,7 @@ log = logging.getLogger(__name__)
class CoordinateConverter(commands.Converter):
"""Converter for Coordinates."""
- async def convert(self, ctx, coordinate: str) -> typing.Tuple[int, int]:
+ async def convert(self, ctx: commands.Context, coordinate: str) -> typing.Tuple[int, int]:
"""Take in a coordinate string and turn it into an (x, y) tuple."""
if not 2 <= len(coordinate) <= 3:
raise commands.BadArgument('Invalid co-ordinate provided')
@@ -80,7 +80,7 @@ class Minesweeper(commands.Cog):
self.games: GamesDict = {} # Store the currently running games
@commands.group(name='minesweeper', aliases=('ms',), invoke_without_command=True)
- async def minesweeper_group(self, ctx: commands.Context):
+ async def minesweeper_group(self, ctx: commands.Context) -> None:
"""Commands for Playing Minesweeper."""
await ctx.send_help(ctx.command)
@@ -215,7 +215,7 @@ class Minesweeper(commands.Cog):
if board[y_][x_] == 0:
self.reveal_zeros(revealed, board, x_, y_)
- async def check_if_won(self, ctx, revealed: GameBoard, board: GameBoard) -> bool:
+ async def check_if_won(self, ctx: commands.Context, revealed: GameBoard, board: GameBoard) -> bool:
"""Checks if a player has won."""
if any(
revealed[y][x] in ["hidden", "flag"] and board[y][x] != "bomb"
@@ -267,7 +267,7 @@ class Minesweeper(commands.Cog):
await self.update_boards(ctx)
@minesweeper_group.command(name="end")
- async def end_command(self, ctx: commands.Context):
+ async def end_command(self, ctx: commands.Context) -> None:
"""End your current game."""
game = self.games[ctx.author.id]
game.revealed = game.board
diff --git a/bot/seasons/evergreen/showprojects.py b/bot/seasons/evergreen/showprojects.py
index 5dea78a5..a943e548 100644
--- a/bot/seasons/evergreen/showprojects.py
+++ b/bot/seasons/evergreen/showprojects.py
@@ -1,5 +1,6 @@
import logging
+from discord import Message
from discord.ext import commands
from bot.constants import Channels
@@ -10,12 +11,12 @@ log = logging.getLogger(__name__)
class ShowProjects(commands.Cog):
"""Cog that reacts to posts in the #show-your-projects."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
self.lastPoster = 0 # Given 0 as the default last poster ID as no user can actually have 0 assigned to them
@commands.Cog.listener()
- async def on_message(self, message):
+ async def on_message(self, message: Message) -> None:
"""Adds reactions to posts in #show-your-projects."""
reactions = ["\U0001f44d", "\U00002764", "\U0001f440", "\U0001f389", "\U0001f680", "\U00002b50", "\U0001f6a9"]
if (message.channel.id == Channels.show_your_projects
@@ -27,7 +28,7 @@ class ShowProjects(commands.Cog):
self.lastPoster = message.author.id
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Show Projects Reaction Cog."""
bot.add_cog(ShowProjects(bot))
log.info("ShowProjects cog loaded")
diff --git a/bot/seasons/evergreen/snakes/__init__.py b/bot/seasons/evergreen/snakes/__init__.py
index d0e57dae..d7f9f20c 100644
--- a/bot/seasons/evergreen/snakes/__init__.py
+++ b/bot/seasons/evergreen/snakes/__init__.py
@@ -1,11 +1,13 @@
import logging
+from discord.ext import commands
+
from bot.seasons.evergreen.snakes.snakes_cog import Snakes
log = logging.getLogger(__name__)
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Snakes Cog load."""
bot.add_cog(Snakes(bot))
log.info("Snakes cog loaded")
diff --git a/bot/seasons/evergreen/snakes/converter.py b/bot/seasons/evergreen/snakes/converter.py
index f2637530..57103b57 100644
--- a/bot/seasons/evergreen/snakes/converter.py
+++ b/bot/seasons/evergreen/snakes/converter.py
@@ -1,9 +1,10 @@
import json
import logging
import random
+from typing import Iterable, List
import discord
-from discord.ext.commands import Converter
+from discord.ext.commands import Context, Converter
from fuzzywuzzy import fuzz
from bot.seasons.evergreen.snakes.utils import SNAKE_RESOURCES
@@ -18,7 +19,7 @@ class Snake(Converter):
snakes = None
special_cases = None
- async def convert(self, ctx, name):
+ async def convert(self, ctx: Context, name: str) -> str:
"""Convert the input snake name to the closest matching Snake object."""
await self.build_list()
name = name.lower()
@@ -26,7 +27,7 @@ class Snake(Converter):
if name == 'python':
return 'Python (programming language)'
- def get_potential(iterable, *, threshold=80):
+ def get_potential(iterable: Iterable, *, threshold: int = 80) -> List[str]:
nonlocal name
potential = []
@@ -58,7 +59,7 @@ class Snake(Converter):
return names.get(name, name)
@classmethod
- async def build_list(cls):
+ async def build_list(cls) -> None:
"""Build list of snakes from the static snake resources."""
# Get all the snakes
if cls.snakes is None:
@@ -72,7 +73,7 @@ class Snake(Converter):
cls.special_cases = {snake['name'].lower(): snake for snake in special_cases}
@classmethod
- async def random(cls):
+ async def random(cls) -> str:
"""
Get a random Snake from the loaded resources.
diff --git a/bot/seasons/evergreen/snakes/snakes_cog.py b/bot/seasons/evergreen/snakes/snakes_cog.py
index 38878706..1ed38f86 100644
--- a/bot/seasons/evergreen/snakes/snakes_cog.py
+++ b/bot/seasons/evergreen/snakes/snakes_cog.py
@@ -9,13 +9,13 @@ import textwrap
import urllib
from functools import partial
from io import BytesIO
-from typing import Any, Dict
+from typing import Any, Dict, List
import aiohttp
import async_timeout
from PIL import Image, ImageDraw, ImageFont
from discord import Colour, Embed, File, Member, Message, Reaction
-from discord.ext.commands import BadArgument, Bot, Cog, Context, bot_has_permissions, group
+from discord.ext.commands import BadArgument, Bot, Cog, CommandError, Context, bot_has_permissions, group
from bot.constants import ERROR_REPLIES, Tokens
from bot.decorators import locked
@@ -154,7 +154,7 @@ class Snakes(Cog):
# region: Helper methods
@staticmethod
- def _beautiful_pastel(hue):
+ def _beautiful_pastel(hue: float) -> int:
"""Returns random bright pastels."""
light = random.uniform(0.7, 0.85)
saturation = 1
@@ -250,7 +250,7 @@ class Snakes(Cog):
return buffer
@staticmethod
- def _snakify(message):
+ def _snakify(message: str) -> str:
"""Sssnakifffiesss a sstring."""
# Replace fricatives with exaggerated snake fricatives.
simple_fricatives = [
@@ -272,7 +272,7 @@ class Snakes(Cog):
return message
- async def _fetch(self, session, url, params=None):
+ async def _fetch(self, session: aiohttp.ClientSession, url: str, params: dict = None) -> dict:
"""Asynchronous web request helper method."""
if params is None:
params = {}
@@ -281,7 +281,7 @@ class Snakes(Cog):
async with session.get(url, params=params) as response:
return await response.json()
- def _get_random_long_message(self, messages, retries=10):
+ def _get_random_long_message(self, messages: List[str], retries: int = 10) -> str:
"""
Fetch a message that's at least 3 words long, if possible to do so in retries attempts.
@@ -403,9 +403,9 @@ class Snakes(Cog):
"""Gets a random snake name."""
return random.choice(self.snake_names)
- async def _validate_answer(self, ctx: Context, message: Message, answer: str, options: list):
+ async def _validate_answer(self, ctx: Context, message: Message, answer: str, options: list) -> None:
"""Validate the answer using a reaction event loop."""
- def predicate(reaction, user):
+ def predicate(reaction: Reaction, user: Member) -> bool:
"""Test if the the answer is valid and can be evaluated."""
return (
reaction.message.id == message.id # The reaction is attached to the question we asked.
@@ -436,14 +436,14 @@ class Snakes(Cog):
# region: Commands
@group(name='snakes', aliases=('snake',), invoke_without_command=True)
- async def snakes_group(self, ctx: Context):
+ async def snakes_group(self, ctx: Context) -> None:
"""Commands from our first code jam."""
await ctx.send_help(ctx.command)
@bot_has_permissions(manage_messages=True)
@snakes_group.command(name='antidote')
@locked()
- async def antidote_command(self, ctx: Context):
+ async def antidote_command(self, ctx: Context) -> None:
"""
Antidote! Can you create the antivenom before the patient dies?
@@ -458,7 +458,7 @@ class Snakes(Cog):
This game was created by Lord Bisk and Runew0lf.
"""
- def predicate(reaction_: Reaction, user_: Member):
+ def predicate(reaction_: Reaction, user_: Member) -> bool:
"""Make sure that this reaction is what we want to operate on."""
return (
all((
@@ -584,7 +584,7 @@ class Snakes(Cog):
await board_id.clear_reactions()
@snakes_group.command(name='draw')
- async def draw_command(self, ctx: Context):
+ async def draw_command(self, ctx: Context) -> None:
"""
Draws a random snek using Perlin noise.
@@ -672,7 +672,7 @@ class Snakes(Cog):
@snakes_group.command(name='guess', aliases=('identify',))
@locked()
- async def guess_command(self, ctx):
+ async def guess_command(self, ctx: Context) -> None:
"""
Snake identifying game.
@@ -706,7 +706,7 @@ class Snakes(Cog):
await self._validate_answer(ctx, guess, answer, options)
@snakes_group.command(name='hatch')
- async def hatch_command(self, ctx: Context):
+ async def hatch_command(self, ctx: Context) -> None:
"""
Hatches your personal snake.
@@ -737,7 +737,7 @@ class Snakes(Cog):
await ctx.channel.send(embed=my_snake_embed)
@snakes_group.command(name='movie')
- async def movie_command(self, ctx: Context):
+ async def movie_command(self, ctx: Context) -> None:
"""
Gets a random snake-related movie from OMDB.
@@ -807,7 +807,7 @@ class Snakes(Cog):
@snakes_group.command(name='quiz')
@locked()
- async def quiz_command(self, ctx: Context):
+ async def quiz_command(self, ctx: Context) -> None:
"""
Asks a snake-related question in the chat and validates the user's guess.
@@ -832,7 +832,7 @@ class Snakes(Cog):
await self._validate_answer(ctx, quiz, answer, options)
@snakes_group.command(name='name', aliases=('name_gen',))
- async def name_command(self, ctx: Context, *, name: str = None):
+ async def name_command(self, ctx: Context, *, name: str = None) -> None:
"""
Snakifies a username.
@@ -904,7 +904,7 @@ class Snakes(Cog):
@snakes_group.command(name='sal')
@locked()
- async def sal_command(self, ctx: Context):
+ async def sal_command(self, ctx: Context) -> None:
"""
Play a game of Snakes and Ladders.
@@ -922,7 +922,7 @@ class Snakes(Cog):
await game.open_game()
@snakes_group.command(name='about')
- async def about_command(self, ctx: Context):
+ async def about_command(self, ctx: Context) -> None:
"""Show an embed with information about the event, its participants, and its winners."""
contributors = [
"<@!245270749919576066>",
@@ -965,7 +965,7 @@ class Snakes(Cog):
await ctx.channel.send(embed=embed)
@snakes_group.command(name='card')
- async def card_command(self, ctx: Context, *, name: Snake = None):
+ async def card_command(self, ctx: Context, *, name: Snake = None) -> None:
"""
Create an interesting little card from a snake.
@@ -1003,7 +1003,7 @@ class Snakes(Cog):
)
@snakes_group.command(name='fact')
- async def fact_command(self, ctx: Context):
+ async def fact_command(self, ctx: Context) -> None:
"""
Gets a snake-related fact.
@@ -1019,7 +1019,7 @@ class Snakes(Cog):
await ctx.channel.send(embed=embed)
@snakes_group.command(name='snakify')
- async def snakify_command(self, ctx: Context, *, message: str = None):
+ async def snakify_command(self, ctx: Context, *, message: str = None) -> None:
"""
How would I talk if I were a snake?
@@ -1060,7 +1060,7 @@ class Snakes(Cog):
await ctx.channel.send(embed=embed)
@snakes_group.command(name='video', aliases=('get_video',))
- async def video_command(self, ctx: Context, *, search: str = None):
+ async def video_command(self, ctx: Context, *, search: str = None) -> None:
"""
Gets a YouTube video about snakes.
@@ -1100,7 +1100,7 @@ class Snakes(Cog):
log.warning(f"YouTube API error. Full response looks like {response}")
@snakes_group.command(name='zen')
- async def zen_command(self, ctx: Context):
+ async def zen_command(self, ctx: Context) -> None:
"""
Gets a random quote from the Zen of Python, except as if spoken by a snake.
@@ -1127,7 +1127,7 @@ class Snakes(Cog):
@get_command.error
@card_command.error
@video_command.error
- async def command_error(self, ctx, error):
+ async def command_error(self, ctx: Context, error: CommandError) -> None:
"""Local error handler for the Snake Cog."""
embed = Embed()
embed.colour = Colour.red()
diff --git a/bot/seasons/evergreen/snakes/utils.py b/bot/seasons/evergreen/snakes/utils.py
index b1d5048a..7d6caf04 100644
--- a/bot/seasons/evergreen/snakes/utils.py
+++ b/bot/seasons/evergreen/snakes/utils.py
@@ -11,7 +11,7 @@ from typing import List, Tuple
from PIL import Image
from PIL.ImageDraw import ImageDraw
from discord import File, Member, Reaction
-from discord.ext.commands import Context
+from discord.ext.commands import Cog, Context
from bot.constants import Roles
@@ -118,12 +118,12 @@ def get_resource(file: str) -> List[dict]:
return json.load(snakefile)
-def smoothstep(t):
+def smoothstep(t: float) -> float:
"""Smooth curve with a zero derivative at 0 and 1, making it useful for interpolating."""
return t * t * (3. - 2. * t)
-def lerp(t, a, b):
+def lerp(t: float, a: float, b: float) -> float:
"""Linear interpolation between a and b, given a fraction t."""
return a + t * (b - a)
@@ -140,7 +140,7 @@ class PerlinNoiseFactory(object):
Licensed under ISC
"""
- def __init__(self, dimension, octaves=1, tile=(), unbias=False):
+ def __init__(self, dimension: int, octaves: int = 1, tile: Tuple[int] = (), unbias: bool = False):
"""
Create a new Perlin noise factory in the given number of dimensions.
@@ -154,7 +154,7 @@ class PerlinNoiseFactory(object):
This will produce noise that tiles every 3 units vertically, but never tiles horizontally.
- If ``unbias`` is true, the smoothstep function will be applied to the output before returning
+ If ``unbias`` is True, the smoothstep function will be applied to the output before returning
it, to counteract some of Perlin noise's significant bias towards the center of its output range.
"""
self.dimension = dimension
@@ -168,7 +168,7 @@ class PerlinNoiseFactory(object):
self.gradient = {}
- def _generate_gradient(self):
+ def _generate_gradient(self) -> Tuple[float, ...]:
"""
Generate a random unit vector at each grid point.
@@ -188,7 +188,7 @@ class PerlinNoiseFactory(object):
scale = sum(n * n for n in random_point) ** -0.5
return tuple(coord * scale for coord in random_point)
- def get_plain_noise(self, *point):
+ def get_plain_noise(self, *point) -> float:
"""Get plain noise for a single point, without taking into account either octaves or tiling."""
if len(point) != self.dimension:
raise ValueError("Expected {0} values, got {1}".format(
@@ -236,7 +236,7 @@ class PerlinNoiseFactory(object):
return dots[0] * self.scale_factor
- def __call__(self, *point):
+ def __call__(self, *point) -> float:
"""
Get the value of this Perlin noise function at the given point.
@@ -369,7 +369,7 @@ GAME_SCREEN_EMOJI = [
class SnakeAndLaddersGame:
"""Snakes and Ladders game Cog."""
- def __init__(self, snakes, context: Context):
+ def __init__(self, snakes: Cog, context: Context):
self.snakes = snakes
self.ctx = context
self.channel = self.ctx.channel
@@ -384,14 +384,13 @@ class SnakeAndLaddersGame:
self.positions = None
self.rolls = []
- async def open_game(self):
+ async def open_game(self) -> None:
"""
Create a new Snakes and Ladders game.
- Listen for reactions until players have joined,
- and the game has been started.
+ Listen for reactions until players have joined, and the game has been started.
"""
- def startup_event_check(reaction_: Reaction, user_: Member):
+ def startup_event_check(reaction_: Reaction, user_: Member) -> bool:
"""Make sure that this reaction is what we want to operate on."""
return (
all((
@@ -456,7 +455,8 @@ class SnakeAndLaddersGame:
await self.cancel_game()
return # We're done, no reactions for the last 5 minutes
- async def _add_player(self, user: Member):
+ async def _add_player(self, user: Member) -> None:
+ """Add player to game."""
self.players.append(user)
self.player_tiles[user.id] = 1
@@ -464,7 +464,7 @@ class SnakeAndLaddersGame:
im = Image.open(io.BytesIO(avatar_bytes)).resize((BOARD_PLAYER_SIZE, BOARD_PLAYER_SIZE))
self.avatar_images[user.id] = im
- async def player_join(self, user: Member):
+ async def player_join(self, user: Member) -> None:
"""
Handle players joining the game.
@@ -520,12 +520,12 @@ class SnakeAndLaddersGame:
await self.channel.send(user.mention + " You are not in the match.", delete_after=10)
return is_surrendered
- async def cancel_game(self):
+ async def cancel_game(self) -> None:
"""Cancel the running game."""
await self.channel.send("**Snakes and Ladders**: Game has been canceled.")
self._destruct()
- async def start_game(self, user: Member):
+ async def start_game(self, user: Member) -> None:
"""
Allow the game author to begin the game.
@@ -544,9 +544,9 @@ class SnakeAndLaddersGame:
await self.channel.send("**Snakes and Ladders**: The game is starting!\nPlayers: " + player_list)
await self.start_round()
- async def start_round(self):
+ async def start_round(self) -> None:
"""Begin the round."""
- def game_event_check(reaction_: Reaction, user_: Member):
+ def game_event_check(reaction_: Reaction, user_: Member) -> bool:
"""Make sure that this reaction is what we want to operate on."""
return (
all((
@@ -639,7 +639,7 @@ class SnakeAndLaddersGame:
if not is_surrendered:
await self._complete_round()
- async def player_roll(self, user: Member):
+ async def player_roll(self, user: Member) -> None:
"""Handle the player's roll."""
if user.id not in self.player_tiles:
await self.channel.send(user.mention + " You are not in the match.", delete_after=10)
@@ -671,7 +671,8 @@ class SnakeAndLaddersGame:
self.player_tiles[user.id] = min(100, next_tile)
self.round_has_rolled[user.id] = True
- async def _complete_round(self):
+ async def _complete_round(self) -> None:
+ """At the conclusion of a round check to see if there's been a winner."""
self.state = 'post_round'
# check for winner
@@ -686,19 +687,22 @@ class SnakeAndLaddersGame:
self._destruct()
def _check_winner(self) -> Member:
+ """Return a winning member if we're in the post-round state and there's a winner."""
if self.state != 'post_round':
return None
return next((player for player in self.players if self.player_tiles[player.id] == 100),
None)
- def _check_all_rolled(self):
+ def _check_all_rolled(self) -> bool:
+ """Check if all members have made their roll."""
return all(rolled for rolled in self.round_has_rolled.values())
- def _destruct(self):
+ def _destruct(self) -> None:
+ """Clean up the finished game object."""
del self.snakes.active_sal[self.channel]
- def _board_coordinate_from_index(self, index: int):
- # converts the tile number to the x/y coordinates for graphical purposes
+ def _board_coordinate_from_index(self, index: int) -> Tuple[int, int]:
+ """Convert the tile number to the x/y coordinates for graphical purposes."""
y_level = 9 - math.floor((index - 1) / 10)
is_reversed = math.floor((index - 1) / 10) % 2 != 0
x_level = (index - 1) % 10
diff --git a/bot/seasons/evergreen/speedrun.py b/bot/seasons/evergreen/speedrun.py
index 5e3d38a0..76c5e8d3 100644
--- a/bot/seasons/evergreen/speedrun.py
+++ b/bot/seasons/evergreen/speedrun.py
@@ -13,16 +13,16 @@ with Path('bot/resources/evergreen/speedrun_links.json').open(encoding="utf-8")
class Speedrun(commands.Cog):
"""Commands about the video game speedrunning community."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(name="speedrun")
- async def get_speedrun(self, ctx):
+ async def get_speedrun(self, ctx: commands.Context) -> None:
"""Sends a link to a video of a random speedrun."""
await ctx.send(choice(LINKS))
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Load the Speedrun cog."""
bot.add_cog(Speedrun(bot))
log.info("Speedrun cog loaded")
diff --git a/bot/seasons/evergreen/uptime.py b/bot/seasons/evergreen/uptime.py
index 92066e0a..6f24f545 100644
--- a/bot/seasons/evergreen/uptime.py
+++ b/bot/seasons/evergreen/uptime.py
@@ -12,11 +12,11 @@ log = logging.getLogger(__name__)
class Uptime(commands.Cog):
"""A cog for posting the bot's uptime."""
- def __init__(self, bot):
+ def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command(name="uptime")
- async def uptime(self, ctx):
+ async def uptime(self, ctx: commands.Context) -> None:
"""Responds with the uptime of the bot."""
difference = relativedelta(start_time - arrow.utcnow())
uptime_string = start_time.shift(
@@ -28,7 +28,7 @@ class Uptime(commands.Cog):
await ctx.send(f"I started up {uptime_string}.")
-def setup(bot):
+def setup(bot: commands.Bot) -> None:
"""Uptime Cog load."""
bot.add_cog(Uptime(bot))
log.info("Uptime cog loaded")