diff options
author | 2022-11-02 02:07:29 -0700 | |
---|---|---|
committer | 2022-11-02 02:07:29 -0700 | |
commit | 43a2acf5ee4eb354ce3dfaeef9504eee9b9b46b4 (patch) | |
tree | cbdfeb08f8d582aa98acec6a529f0fa3dcd7933c /bot/exts/fun | |
parent | Appeased the formatter (diff) | |
parent | Merge pull request #1137 from DivyanshuBist/bug-issue1122-message-of-type-None (diff) |
Merge branch 'main' into main
Diffstat (limited to 'bot/exts/fun')
-rw-r--r-- | bot/exts/fun/anagram.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/battleship.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/catify.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/coinflip.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/connect_four.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/duck_game.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/fun.py | 12 | ||||
-rw-r--r-- | bot/exts/fun/game.py | 86 | ||||
-rw-r--r-- | bot/exts/fun/hangman.py | 6 | ||||
-rw-r--r-- | bot/exts/fun/latex.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/madlibs.py | 6 | ||||
-rw-r--r-- | bot/exts/fun/magic_8ball.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/minesweeper.py | 10 | ||||
-rw-r--r-- | bot/exts/fun/movie.py | 52 | ||||
-rw-r--r-- | bot/exts/fun/quack.py | 11 | ||||
-rw-r--r-- | bot/exts/fun/recommend_game.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/rps.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/snakes/__init__.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/snakes/_snakes_cog.py | 3 | ||||
-rw-r--r-- | bot/exts/fun/space.py | 8 | ||||
-rw-r--r-- | bot/exts/fun/speedrun.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/status_codes.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/tic_tac_toe.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/trivia_quiz.py | 6 | ||||
-rw-r--r-- | bot/exts/fun/uwu.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/wonder_twins.py | 4 | ||||
-rw-r--r-- | bot/exts/fun/xkcd.py | 4 |
27 files changed, 136 insertions, 132 deletions
diff --git a/bot/exts/fun/anagram.py b/bot/exts/fun/anagram.py index 79280fa9..d8ea6a55 100644 --- a/bot/exts/fun/anagram.py +++ b/bot/exts/fun/anagram.py @@ -104,6 +104,6 @@ class Anagram(commands.Cog): await game.message_creation(message) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Anagram cog.""" - bot.add_cog(Anagram(bot)) + await bot.add_cog(Anagram(bot)) diff --git a/bot/exts/fun/battleship.py b/bot/exts/fun/battleship.py index 77e38427..a8039cf2 100644 --- a/bot/exts/fun/battleship.py +++ b/bot/exts/fun/battleship.py @@ -442,6 +442,6 @@ class Battleship(commands.Cog): await ctx.send(embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Battleship Cog.""" - bot.add_cog(Battleship(bot)) + await bot.add_cog(Battleship(bot)) diff --git a/bot/exts/fun/catify.py b/bot/exts/fun/catify.py index 32dfae09..6e8c75ba 100644 --- a/bot/exts/fun/catify.py +++ b/bot/exts/fun/catify.py @@ -81,6 +81,6 @@ class Catify(commands.Cog): ) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Loads the catify cog.""" - bot.add_cog(Catify()) + await bot.add_cog(Catify()) diff --git a/bot/exts/fun/coinflip.py b/bot/exts/fun/coinflip.py index 804306bd..b7dee44d 100644 --- a/bot/exts/fun/coinflip.py +++ b/bot/exts/fun/coinflip.py @@ -48,6 +48,6 @@ class CoinFlip(commands.Cog): await ctx.send(message) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Loads the coinflip cog.""" - bot.add_cog(CoinFlip()) + await bot.add_cog(CoinFlip()) diff --git a/bot/exts/fun/connect_four.py b/bot/exts/fun/connect_four.py index 1b88d065..0d870a6e 100644 --- a/bot/exts/fun/connect_four.py +++ b/bot/exts/fun/connect_four.py @@ -447,6 +447,6 @@ class ConnectFour(commands.Cog): await self._play_game(ctx, None, board_size, str(emoji1), str(emoji2)) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load ConnectFour Cog.""" - bot.add_cog(ConnectFour(bot)) + await bot.add_cog(ConnectFour(bot)) diff --git a/bot/exts/fun/duck_game.py b/bot/exts/fun/duck_game.py index 10b03a49..a2612e51 100644 --- a/bot/exts/fun/duck_game.py +++ b/bot/exts/fun/duck_game.py @@ -341,6 +341,6 @@ class DuckGamesDirector(commands.Cog): return await ctx.send(file=file, embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the DuckGamesDirector cog.""" - bot.add_cog(DuckGamesDirector(bot)) + await bot.add_cog(DuckGamesDirector(bot)) diff --git a/bot/exts/fun/fun.py b/bot/exts/fun/fun.py index e7337cb6..8056b033 100644 --- a/bot/exts/fun/fun.py +++ b/bot/exts/fun/fun.py @@ -6,9 +6,10 @@ from pathlib import Path from typing import Literal import pyjokes +from botcore.utils.commands import clean_text_or_reply from discord import Embed from discord.ext import commands -from discord.ext.commands import BadArgument, Cog, Context, clean_content +from discord.ext.commands import BadArgument, Cog, Context from bot.bot import Bot from bot.constants import Client, Colours, Emojis @@ -60,13 +61,14 @@ class Fun(Cog): raise BadArgument(f"`{Client.prefix}roll` only supports between 1 and 6 rolls.") @commands.command(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",)) - async def randomcase_command(self, ctx: Context, *, text: clean_content(fix_channel_mentions=True)) -> None: - """Randomly converts the casing of a given `text`.""" + async def randomcase_command(self, ctx: Context, *, text: str | None) -> None: + """Randomly converts the casing of a given `text`, or the replied message.""" def conversion_func(text: str) -> str: """Randomly converts the casing of a given string.""" return "".join( char.upper() if round(random.random()) else char.lower() for char in text ) + text = await clean_text_or_reply(ctx, text) text, embed = await messages.get_text_and_embed(ctx, text) # Convert embed if it exists if embed is not None: @@ -157,6 +159,6 @@ class Fun(Cog): await ctx.send(joke) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Fun cog.""" - bot.add_cog(Fun(bot)) + await bot.add_cog(Fun(bot)) diff --git a/bot/exts/fun/game.py b/bot/exts/fun/game.py index 5f56bef7..4e01444e 100644 --- a/bot/exts/fun/game.py +++ b/bot/exts/fun/game.py @@ -2,12 +2,12 @@ import difflib import logging import random import re -from asyncio import sleep from datetime import datetime as dt, timedelta from enum import IntEnum from typing import Any, Optional from aiohttp import ClientSession +from botcore.utils import scheduling from discord import Embed from discord.ext import tasks from discord.ext.commands import Cog, Context, group @@ -15,7 +15,6 @@ from discord.ext.commands import Cog, Context, group from bot.bot import Bot from bot.constants import STAFF_ROLES, Tokens from bot.utils.decorators import with_role -from bot.utils.extensions import invoke_help_command from bot.utils.pagination import ImagePaginator, LinePaginator # Base URL of IGDB API @@ -185,46 +184,45 @@ class Games(Cog): self.genres: dict[str, int] = {} self.headers = BASE_HEADERS + self.token_refresh_scheduler = scheduling.Scheduler(__name__) - self.bot.loop.create_task(self.renew_access_token()) - - async def renew_access_token(self) -> None: - """Refeshes V4 access token a number of seconds before expiry. See `ACCESS_TOKEN_RENEWAL_WINDOW`.""" - while True: - async with self.http_session.post(OAUTH_URL, params=OAUTH_PARAMS) as resp: - result = await resp.json() - if resp.status != 200: - # If there is a valid access token continue to use that, - # otherwise unload cog. - if "Authorization" in self.headers: - time_delta = timedelta(seconds=ACCESS_TOKEN_RENEWAL_WINDOW) - logger.error( - "Failed to renew IGDB access token. " - f"Current token will last for {time_delta} " - f"OAuth response message: {result['message']}" - ) - else: - logger.warning( - "Invalid OAuth credentials. Unloading Games cog. " - f"OAuth response message: {result['message']}" - ) - self.bot.remove_cog("Games") - - return - - self.headers["Authorization"] = f"Bearer {result['access_token']}" - - # Attempt to renew before the token expires - next_renewal = result["expires_in"] - ACCESS_TOKEN_RENEWAL_WINDOW - - time_delta = timedelta(seconds=next_renewal) - logger.info(f"Successfully renewed access token. Refreshing again in {time_delta}") - - # This will be true the first time this loop runs. - # Since we now have an access token, its safe to start this task. - if self.genres == {}: - self.refresh_genres_task.start() - await sleep(next_renewal) + async def cog_load(self) -> None: + """Get an auth token and start the refresh task on cog load.""" + await self.refresh_token() + self.refresh_genres_task.start() + + async def refresh_token(self) -> None: + """ + Refresh the IGDB V4 access token. + + Once a new token has been created, schedule another refresh `ACCESS_TOKEN_RENEWAL_WINDOW` seconds before expiry. + """ + async with self.http_session.post(OAUTH_URL, params=OAUTH_PARAMS) as resp: + result = await resp.json() + if resp.status != 200: + # If there is a valid access token continue to use that, + # otherwise unload cog. + if "Authorization" in self.headers: + time_delta = timedelta(seconds=ACCESS_TOKEN_RENEWAL_WINDOW) + logger.error( + "Failed to renew IGDB access token. " + f"Current token will last for {time_delta} " + f"OAuth response message: {result['message']}" + ) + else: + logger.warning( + "Invalid OAuth credentials. Unloading Games cog. " + f"OAuth response message: {result['message']}" + ) + self.bot.remove_cog("Games") + return + + self.headers["Authorization"] = f"Bearer {result['access_token']}" + + # Attempt to renew before the token expires + seconds_until_next_renewal = result["expires_in"] - ACCESS_TOKEN_RENEWAL_WINDOW + logger.info(f"Successfully renewed access token. Refreshing again in {seconds_until_next_renewal} seconds") + self.token_refresh_scheduler.schedule_later(seconds_until_next_renewal, __name__, self.refresh_token()) @tasks.loop(hours=24.0) async def refresh_genres_task(self) -> None: @@ -267,7 +265,7 @@ class Games(Cog): """ # When user didn't specified genre, send help message if genre is None: - await invoke_help_command(ctx) + await self.bot.invoke_help_command(ctx) return # Capitalize genre for check @@ -505,7 +503,7 @@ class Games(Cog): return sorted((item for item in results if item[0] >= 0.60), reverse=True)[:4] -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Games cog.""" # Check does IGDB API key exist, if not, log warning and don't load cog if not Tokens.igdb_client_id: @@ -514,4 +512,4 @@ def setup(bot: Bot) -> None: if not Tokens.igdb_client_secret: logger.warning("No IGDB client secret. Not loading Games cog.") return - bot.add_cog(Games(bot)) + await bot.add_cog(Games(bot)) diff --git a/bot/exts/fun/hangman.py b/bot/exts/fun/hangman.py index a2c8c735..f385a955 100644 --- a/bot/exts/fun/hangman.py +++ b/bot/exts/fun/hangman.py @@ -110,7 +110,7 @@ class Hangman(commands.Cog): try: message = await self.bot.wait_for( - event="message", + "message", timeout=60.0, check=check ) @@ -177,6 +177,6 @@ class Hangman(commands.Cog): await ctx.send(embed=win_embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Hangman cog.""" - bot.add_cog(Hangman(bot)) + await bot.add_cog(Hangman(bot)) diff --git a/bot/exts/fun/latex.py b/bot/exts/fun/latex.py index aeabcd20..b5dada1c 100644 --- a/bot/exts/fun/latex.py +++ b/bot/exts/fun/latex.py @@ -133,6 +133,6 @@ class Latex(commands.Cog): await ctx.send(file=discord.File(image_path, "latex.png")) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Latex Cog.""" - bot.add_cog(Latex(bot)) + await bot.add_cog(Latex(bot)) diff --git a/bot/exts/fun/madlibs.py b/bot/exts/fun/madlibs.py index 21708e53..075dde75 100644 --- a/bot/exts/fun/madlibs.py +++ b/bot/exts/fun/madlibs.py @@ -93,7 +93,7 @@ class Madlibs(commands.Cog): await original_message.edit(embed=madlibs_embed) try: - message = await self.bot.wait_for(event="message", check=author_check, timeout=TIMEOUT) + message = await self.bot.wait_for("message", check=author_check, timeout=TIMEOUT) except TimeoutError: timeout_embed = discord.Embed( title=choice(NEGATIVE_REPLIES), @@ -143,6 +143,6 @@ class Madlibs(commands.Cog): error.handled = True -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Madlibs cog.""" - bot.add_cog(Madlibs(bot)) + await bot.add_cog(Madlibs(bot)) diff --git a/bot/exts/fun/magic_8ball.py b/bot/exts/fun/magic_8ball.py index a7b682ca..95d711c4 100644 --- a/bot/exts/fun/magic_8ball.py +++ b/bot/exts/fun/magic_8ball.py @@ -25,6 +25,6 @@ class Magic8ball(commands.Cog): await ctx.send("Usage: .8ball <question> (minimum length of 3 eg: `will I win?`)") -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Magic8Ball Cog.""" - bot.add_cog(Magic8ball()) + await bot.add_cog(Magic8ball()) diff --git a/bot/exts/fun/minesweeper.py b/bot/exts/fun/minesweeper.py index a48b5051..f16b1db2 100644 --- a/bot/exts/fun/minesweeper.py +++ b/bot/exts/fun/minesweeper.py @@ -11,7 +11,6 @@ from bot.bot import Bot from bot.constants import Client from bot.utils.converters import CoordinateConverter from bot.utils.exceptions import UserNotPlayingError -from bot.utils.extensions import invoke_help_command MESSAGE_MAPPING = { 0: ":stop_button:", @@ -51,13 +50,14 @@ class Game: class Minesweeper(commands.Cog): """Play a game of Minesweeper.""" - def __init__(self): + def __init__(self, bot: Bot): + self.bot = bot self.games: dict[int, Game] = {} @commands.group(name="minesweeper", aliases=("ms",), invoke_without_command=True) async def minesweeper_group(self, ctx: commands.Context) -> None: """Commands for Playing Minesweeper.""" - await invoke_help_command(ctx) + await self.bot.invoke_help_command(ctx) @staticmethod def get_neighbours(x: int, y: int) -> Iterator[tuple[int, int]]: @@ -265,6 +265,6 @@ class Minesweeper(commands.Cog): del self.games[ctx.author.id] -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Minesweeper cog.""" - bot.add_cog(Minesweeper()) + await bot.add_cog(Minesweeper(bot)) diff --git a/bot/exts/fun/movie.py b/bot/exts/fun/movie.py index a04eeb41..422a83ac 100644 --- a/bot/exts/fun/movie.py +++ b/bot/exts/fun/movie.py @@ -9,13 +9,16 @@ from discord.ext.commands import Cog, Context, group from bot.bot import Bot from bot.constants import Tokens -from bot.utils.extensions import invoke_help_command +from bot.utils.exceptions import APIError from bot.utils.pagination import ImagePaginator +logger = logging.getLogger(__name__) + # Define base URL of TMDB BASE_URL = "https://api.themoviedb.org/3/" -logger = logging.getLogger(__name__) +# Logo of TMDB +THUMBNAIL_URL = "https://i.imgur.com/LtFtC8H.png" # Define movie params, that will be used for every movie request MOVIE_PARAMS = { @@ -23,6 +26,10 @@ MOVIE_PARAMS = { "language": "en-US" } +# Maximum value for `pages` API parameter. The maximum is documented as 1000 but +# anything over 500 returns an error. +MAX_PAGES = 500 + class MovieGenres(Enum): """Movies Genre names and IDs.""" @@ -50,12 +57,14 @@ class Movie(Cog): """Movie Cog contains movies command that grab random movies from TMDB.""" def __init__(self, bot: Bot): + self.bot = bot self.http_session: ClientSession = bot.http_session @group(name="movies", aliases=("movie",), invoke_without_command=True) async def movies(self, ctx: Context, genre: str = "", amount: int = 5) -> None: """ - Get random movies by specifying genre. Also support amount parameter, that define how much movies will be shown. + Get random movies by specifying genre. Also support amount parameter,\ + that define how much movies will be shown. Default 5. Use .movies genres to get all available genres. """ @@ -73,28 +82,14 @@ class Movie(Cog): try: result = await self.get_movies_data(self.http_session, MovieGenres[genre].value, 1) except KeyError: - await invoke_help_command(ctx) + await self.bot.invoke_help_command(ctx) return - # Check if "results" is in result. If not, throw error. - if "results" not in result: - err_msg = ( - f"There is problem while making TMDB API request. Response Code: {result['status_code']}, " - f"{result['status_message']}." - ) - await ctx.send(err_msg) - logger.warning(err_msg) - # Get random page. Max page is last page where is movies with this genre. - page = random.randint(1, result["total_pages"]) + page = random.randint(1, min(result["total_pages"], MAX_PAGES)) # Get movies list from TMDB, check if results key in result. When not, raise error. movies = await self.get_movies_data(self.http_session, MovieGenres[genre].value, page) - if "results" not in movies: - err_msg = f"There is problem while making TMDB API request. Response Code: {result['status_code']}, " \ - f"{result['status_message']}." - await ctx.send(err_msg) - logger.warning(err_msg) # Get all pages and embed pages = await self.get_pages(self.http_session, movies, amount) @@ -124,7 +119,18 @@ class Movie(Cog): # Make discover request to TMDB, return result async with client.get(url, params=params) as resp: - return await resp.json() + result, status = await resp.json(), resp.status + # Check if "results" is in result. If not, throw error. + if "results" not in result: + err_msg = ( + f"There was a problem making the TMDB API request. Response Code: {status}, " + f"TMDB: Status Code: {result.get('status_code', None)} " + f"TMDB: Status Message: {result.get('status_message', None)}, " + f"TMDB: Errors: {result.get('errors', None)}, " + ) + logger.error(err_msg) + raise APIError("TMDB API", status, err_msg) + return result async def get_pages(self, client: ClientSession, movies: dict[str, Any], amount: int) -> list[tuple[str, str]]: """Fetch all movie pages from movies dictionary. Return list of pages.""" @@ -196,10 +202,10 @@ class Movie(Cog): """Return embed of random movies. Uses name in title.""" embed = Embed(title=f"Random {name} Movies") embed.set_footer(text="This product uses the TMDb API but is not endorsed or certified by TMDb.") - embed.set_thumbnail(url="https://i.imgur.com/LtFtC8H.png") + embed.set_thumbnail(url=THUMBNAIL_URL) return embed -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Movie Cog.""" - bot.add_cog(Movie(bot)) + await bot.add_cog(Movie(bot)) diff --git a/bot/exts/fun/quack.py b/bot/exts/fun/quack.py index 0c228aed..bb0cd731 100644 --- a/bot/exts/fun/quack.py +++ b/bot/exts/fun/quack.py @@ -50,13 +50,12 @@ class Quackstack(commands.Cog): description="The request failed. Please try again later.", color=Colours.soft_red, ) - if response.status != 200: + if response.status != 201: log.error(f"Response to Quackstack returned code {response.status}") await ctx.send(embed=error_embed) return - data = await response.json() - file = data["file"] + file = response.headers["Location"] embed = discord.Embed( title=f"Quack! Here's a {ducktype} for you.", @@ -65,11 +64,11 @@ class Quackstack(commands.Cog): url=f"{API_URL}/docs" ) - embed.set_image(url=API_URL + file) + embed.set_image(url=file) await ctx.send(embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Loads the Quack cog.""" - bot.add_cog(Quackstack(bot)) + await bot.add_cog(Quackstack(bot)) diff --git a/bot/exts/fun/recommend_game.py b/bot/exts/fun/recommend_game.py index 42c9f7c2..e972b9a5 100644 --- a/bot/exts/fun/recommend_game.py +++ b/bot/exts/fun/recommend_game.py @@ -46,6 +46,6 @@ class RecommendGame(commands.Cog): await ctx.send(embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Loads the RecommendGame cog.""" - bot.add_cog(RecommendGame(bot)) + await bot.add_cog(RecommendGame(bot)) diff --git a/bot/exts/fun/rps.py b/bot/exts/fun/rps.py index c6bbff46..50129835 100644 --- a/bot/exts/fun/rps.py +++ b/bot/exts/fun/rps.py @@ -52,6 +52,6 @@ class RPS(commands.Cog): await ctx.send(f"Sir Lancebot played {bot_move}! {player_mention} lost!") -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the RPS Cog.""" - bot.add_cog(RPS(bot)) + await bot.add_cog(RPS(bot)) diff --git a/bot/exts/fun/snakes/__init__.py b/bot/exts/fun/snakes/__init__.py index ba8333fd..8aa39fb5 100644 --- a/bot/exts/fun/snakes/__init__.py +++ b/bot/exts/fun/snakes/__init__.py @@ -6,6 +6,6 @@ from bot.exts.fun.snakes._snakes_cog import Snakes log = logging.getLogger(__name__) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Snakes Cog.""" - bot.add_cog(Snakes(bot)) + await bot.add_cog(Snakes(bot)) diff --git a/bot/exts/fun/snakes/_snakes_cog.py b/bot/exts/fun/snakes/_snakes_cog.py index 59e57199..96718200 100644 --- a/bot/exts/fun/snakes/_snakes_cog.py +++ b/bot/exts/fun/snakes/_snakes_cog.py @@ -22,7 +22,6 @@ from bot.constants import ERROR_REPLIES, Tokens from bot.exts.fun.snakes import _utils as utils from bot.exts.fun.snakes._converter import Snake from bot.utils.decorators import locked -from bot.utils.extensions import invoke_help_command log = logging.getLogger(__name__) @@ -440,7 +439,7 @@ class Snakes(Cog): @group(name="snakes", aliases=("snake",), invoke_without_command=True) async def snakes_group(self, ctx: Context) -> None: """Commands from our first code jam.""" - await invoke_help_command(ctx) + await self.bot.invoke_help_command(ctx) @bot_has_permissions(manage_messages=True) @snakes_group.command(name="antidote") diff --git a/bot/exts/fun/space.py b/bot/exts/fun/space.py index 48ad0f96..22a89050 100644 --- a/bot/exts/fun/space.py +++ b/bot/exts/fun/space.py @@ -11,7 +11,6 @@ from discord.ext.commands import Cog, Context, group from bot.bot import Bot from bot.constants import Tokens from bot.utils.converters import DateConverter -from bot.utils.extensions import invoke_help_command logger = logging.getLogger(__name__) @@ -27,6 +26,7 @@ class Space(Cog): def __init__(self, bot: Bot): self.http_session = bot.http_session + self.bot = bot self.rovers = {} self.get_rovers.start() @@ -50,7 +50,7 @@ class Space(Cog): @group(name="space", invoke_without_command=True) async def space(self, ctx: Context) -> None: """Head command that contains commands about space.""" - await invoke_help_command(ctx) + await self.bot.invoke_help_command(ctx) @space.command(name="apod") async def apod(self, ctx: Context, date: Optional[str]) -> None: @@ -227,10 +227,10 @@ class Space(Cog): ).set_image(url=image).set_footer(text="Powered by NASA API" + footer) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Space cog.""" if not Tokens.nasa: logger.warning("Can't find NASA API key. Not loading Space Cog.") return - bot.add_cog(Space(bot)) + await bot.add_cog(Space(bot)) diff --git a/bot/exts/fun/speedrun.py b/bot/exts/fun/speedrun.py index c2966ce1..43e570a2 100644 --- a/bot/exts/fun/speedrun.py +++ b/bot/exts/fun/speedrun.py @@ -21,6 +21,6 @@ class Speedrun(commands.Cog): await ctx.send(choice(LINKS)) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the Speedrun cog.""" - bot.add_cog(Speedrun()) + await bot.add_cog(Speedrun()) diff --git a/bot/exts/fun/status_codes.py b/bot/exts/fun/status_codes.py index 501cbe0a..cf544a19 100644 --- a/bot/exts/fun/status_codes.py +++ b/bot/exts/fun/status_codes.py @@ -82,6 +82,6 @@ class HTTPStatusCodes(commands.Cog): ) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the HTTPStatusCodes cog.""" - bot.add_cog(HTTPStatusCodes(bot)) + await bot.add_cog(HTTPStatusCodes(bot)) diff --git a/bot/exts/fun/tic_tac_toe.py b/bot/exts/fun/tic_tac_toe.py index 5dd38a81..fa2a7531 100644 --- a/bot/exts/fun/tic_tac_toe.py +++ b/bot/exts/fun/tic_tac_toe.py @@ -333,6 +333,6 @@ class TicTacToe(Cog): await ctx.send(embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the TicTacToe cog.""" - bot.add_cog(TicTacToe()) + await bot.add_cog(TicTacToe()) diff --git a/bot/exts/fun/trivia_quiz.py b/bot/exts/fun/trivia_quiz.py index 4a1cec5b..31652374 100644 --- a/bot/exts/fun/trivia_quiz.py +++ b/bot/exts/fun/trivia_quiz.py @@ -435,7 +435,7 @@ class TriviaQuiz(commands.Cog): def contains_correct_answer(m: discord.Message) -> bool: return m.channel == ctx.channel and any( fuzz.ratio(answer.lower(), m.content.lower()) > variation_tolerance - for answer in quiz_entry.answers + for answer in quiz_entry.answers # noqa: B023 ) return contains_correct_answer @@ -670,6 +670,6 @@ class TriviaQuiz(commands.Cog): await channel.send(embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the TriviaQuiz cog.""" - bot.add_cog(TriviaQuiz(bot)) + await bot.add_cog(TriviaQuiz(bot)) diff --git a/bot/exts/fun/uwu.py b/bot/exts/fun/uwu.py index 83497893..7a9d55d0 100644 --- a/bot/exts/fun/uwu.py +++ b/bot/exts/fun/uwu.py @@ -199,6 +199,6 @@ class Uwu(Cog): await ctx.send(content=converted_text, embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the uwu cog.""" - bot.add_cog(Uwu(bot)) + await bot.add_cog(Uwu(bot)) diff --git a/bot/exts/fun/wonder_twins.py b/bot/exts/fun/wonder_twins.py index 79d6b6d9..0c5b0a76 100644 --- a/bot/exts/fun/wonder_twins.py +++ b/bot/exts/fun/wonder_twins.py @@ -44,6 +44,6 @@ class WonderTwins(Cog): await ctx.send(f"Form of {self.format_phrase()}!") -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the WonderTwins cog.""" - bot.add_cog(WonderTwins()) + await bot.add_cog(WonderTwins()) diff --git a/bot/exts/fun/xkcd.py b/bot/exts/fun/xkcd.py index b56c53d9..380c3c80 100644 --- a/bot/exts/fun/xkcd.py +++ b/bot/exts/fun/xkcd.py @@ -86,6 +86,6 @@ class XKCD(Cog): await ctx.send(embed=embed) -def setup(bot: Bot) -> None: +async def setup(bot: Bot) -> None: """Load the XKCD cog.""" - bot.add_cog(XKCD(bot)) + await bot.add_cog(XKCD(bot)) |