diff options
author | 2023-11-06 10:40:24 +0000 | |
---|---|---|
committer | 2023-11-06 10:42:02 +0000 | |
commit | 428c8def8ba10b4a512971115243b6993a3d940b (patch) | |
tree | 5986c80aca7158e13b19a59f75cc3a6ca6d0f53e | |
parent | Use ruff's isort implementation (diff) |
Format code with new ruff rules
-rw-r--r-- | bot/exts/fun/battleship.py | 5 | ||||
-rw-r--r-- | bot/exts/fun/connect_four.py | 5 | ||||
-rw-r--r-- | bot/exts/fun/game.py | 8 | ||||
-rw-r--r-- | bot/exts/fun/hangman.py | 1 | ||||
-rw-r--r-- | bot/exts/fun/madlibs.py | 1 | ||||
-rw-r--r-- | bot/exts/fun/snakes/_snakes_cog.py | 6 | ||||
-rw-r--r-- | bot/exts/fun/snakes/_utils.py | 5 | ||||
-rw-r--r-- | bot/exts/fun/tic_tac_toe.py | 5 | ||||
-rw-r--r-- | bot/exts/fun/trivia_quiz.py | 2 | ||||
-rw-r--r-- | bot/exts/holidays/pride/pride_facts.py | 2 | ||||
-rw-r--r-- | bot/exts/utilities/conversationstarters.py | 3 | ||||
-rw-r--r-- | bot/exts/utilities/githubinfo.py | 2 | ||||
-rw-r--r-- | bot/utils/__init__.py | 2 | ||||
-rw-r--r-- | bot/utils/checks.py | 9 | ||||
-rw-r--r-- | bot/utils/pagination.py | 5 | ||||
-rw-r--r-- | pyproject.toml | 2 |
16 files changed, 31 insertions, 32 deletions
diff --git a/bot/exts/fun/battleship.py b/bot/exts/fun/battleship.py index 4a552605..ded784be 100644 --- a/bot/exts/fun/battleship.py +++ b/bot/exts/fun/battleship.py @@ -1,4 +1,3 @@ -import asyncio import logging import random import re @@ -244,7 +243,7 @@ class Game: while True: try: await self.bot.wait_for("message", check=self.predicate, timeout=60.0) - except asyncio.TimeoutError: + except TimeoutError: await self.turn.user.send("You took too long. Game over!") await self.next.user.send(f"{self.turn.user} took too long. Game over!") await self.public_channel.send( @@ -400,7 +399,7 @@ class Battleship(commands.Cog): check=partial(self.predicate, ctx, announcement), timeout=60.0 ) - except asyncio.TimeoutError: + except TimeoutError: self.waiting.remove(ctx.author) await announcement.delete() await ctx.send(f"{ctx.author.mention} Seems like there's no one here to play...") diff --git a/bot/exts/fun/connect_four.py b/bot/exts/fun/connect_four.py index 6544dc48..eec092d1 100644 --- a/bot/exts/fun/connect_four.py +++ b/bot/exts/fun/connect_four.py @@ -1,4 +1,3 @@ -import asyncio import random from functools import partial @@ -131,7 +130,7 @@ class Game: while True: try: reaction, user = await self.bot.wait_for("reaction_add", check=self.predicate, timeout=30.0) - except asyncio.TimeoutError: + except TimeoutError: await self.channel.send(f"{self.player_active.mention}, you took too long. Game over!") return None else: @@ -406,7 +405,7 @@ class ConnectFour(commands.Cog): check=partial(self.get_player, ctx, announcement), timeout=60.0 ) - except asyncio.TimeoutError: + except TimeoutError: self.waiting.remove(ctx.author) await announcement.delete() await ctx.send( diff --git a/bot/exts/fun/game.py b/bot/exts/fun/game.py index b2b18f04..c9824f22 100644 --- a/bot/exts/fun/game.py +++ b/bot/exts/fun/game.py @@ -421,13 +421,13 @@ class Games(Cog): "url": data["url"], "description": f"{data['summary']}\n\n" if "summary" in data else "\n", "release_date": release_date, - "rating": round(data["total_rating"] if "total_rating" in data else 0, 2), - "rating_count": data["total_rating_count"] if "total_rating_count" in data else "?", + "rating": round(data.get("total_rating", 0), 2), + "rating_count": data.get("total_rating_count", "?"), "platforms": ", ".join(platform["name"] for platform in data["platforms"]) if "platforms" in data else "?", "status": GameStatus(data["status"]).name if "status" in data else "?", "age_ratings": rating, "made_by": ", ".join(companies), - "storyline": data["storyline"] if "storyline" in data else "" + "storyline": data.get("storyline", "") } page = GAME_PAGE.format(**formatting) @@ -448,7 +448,7 @@ class Games(Cog): formatting = { "name": game["name"], "url": game["url"], - "rating": round(game["total_rating"] if "total_rating" in game else 0, 2), + "rating": round(game.get("total_rating", 0), 2), "rating_count": game["total_rating_count"] if "total_rating" in game else "?" } line = GAME_SEARCH_LINE.format(**formatting) diff --git a/bot/exts/fun/hangman.py b/bot/exts/fun/hangman.py index 7a02a552..869e0644 100644 --- a/bot/exts/fun/hangman.py +++ b/bot/exts/fun/hangman.py @@ -1,4 +1,3 @@ -from asyncio import TimeoutError from pathlib import Path from random import choice diff --git a/bot/exts/fun/madlibs.py b/bot/exts/fun/madlibs.py index c14e8a3a..f457a191 100644 --- a/bot/exts/fun/madlibs.py +++ b/bot/exts/fun/madlibs.py @@ -1,5 +1,4 @@ import json -from asyncio import TimeoutError from pathlib import Path from random import choice from typing import TypedDict diff --git a/bot/exts/fun/snakes/_snakes_cog.py b/bot/exts/fun/snakes/_snakes_cog.py index c0210e43..6f359928 100644 --- a/bot/exts/fun/snakes/_snakes_cog.py +++ b/bot/exts/fun/snakes/_snakes_cog.py @@ -283,7 +283,7 @@ class Snakes(Cog): params = {} async with self.bot.http_session.get(url, params=params, timeout=ClientTimeout(total=10)) as response: - return await response.json() + return await response.json() def _get_random_long_message(self, messages: list[str], retries: int = 10) -> str: """ @@ -422,7 +422,7 @@ class Snakes(Cog): # Validate the answer try: reaction, user = await ctx.bot.wait_for("reaction_add", timeout=45.0, check=predicate) - except asyncio.TimeoutError: + except TimeoutError: await ctx.send(f"You took too long. The correct answer was **{options[answer]}**.") await message.clear_reactions() return @@ -516,7 +516,7 @@ class Snakes(Cog): try: reaction, user = await ctx.bot.wait_for( "reaction_add", timeout=300, check=predicate) - except asyncio.TimeoutError: + except TimeoutError: log.debug("Antidote timed out waiting for a reaction") break # We're done, no reactions for the last 5 minutes diff --git a/bot/exts/fun/snakes/_utils.py b/bot/exts/fun/snakes/_utils.py index a967f47b..c48ecf8d 100644 --- a/bot/exts/fun/snakes/_utils.py +++ b/bot/exts/fun/snakes/_utils.py @@ -1,4 +1,3 @@ -import asyncio import io import json import logging @@ -453,7 +452,7 @@ class SnakeAndLaddersGame: await startup.remove_reaction(reaction.emoji, user) - except asyncio.TimeoutError: + except TimeoutError: log.debug("Snakes and Ladders timed out waiting for a reaction") await self.cancel_game() return # We're done, no reactions for the last 5 minutes @@ -630,7 +629,7 @@ class SnakeAndLaddersGame: if self._check_all_rolled(): break - except asyncio.TimeoutError: + except TimeoutError: log.debug("Snakes and Ladders timed out waiting for a reaction") await self.cancel_game() return # We're done, no reactions for the last 5 minutes diff --git a/bot/exts/fun/tic_tac_toe.py b/bot/exts/fun/tic_tac_toe.py index d4ae7107..f6ee6293 100644 --- a/bot/exts/fun/tic_tac_toe.py +++ b/bot/exts/fun/tic_tac_toe.py @@ -1,4 +1,3 @@ -import asyncio import random from collections.abc import Callable @@ -59,7 +58,7 @@ class Player: try: react, _ = await self.ctx.bot.wait_for("reaction_add", timeout=30.0, check=check_for_move) - except asyncio.TimeoutError: + except TimeoutError: return True, None else: return False, list(Emojis.number_emojis.keys())[list(Emojis.number_emojis.values()).index(react.emoji)] @@ -162,7 +161,7 @@ class Game: timeout=60.0, check=confirm_check ) - except asyncio.TimeoutError: + except TimeoutError: self.over = True self.canceled = True await confirm_message.delete() diff --git a/bot/exts/fun/trivia_quiz.py b/bot/exts/fun/trivia_quiz.py index b96007b5..4f352b71 100644 --- a/bot/exts/fun/trivia_quiz.py +++ b/bot/exts/fun/trivia_quiz.py @@ -430,7 +430,7 @@ class TriviaQuiz(commands.Cog): try: msg = await self.bot.wait_for("message", check=check_func(quiz_entry.var_tol), timeout=10) - except asyncio.TimeoutError: + except TimeoutError: # In case of TimeoutError and the game has been stopped, then do nothing. if not self.game_status[ctx.channel.id]: break diff --git a/bot/exts/holidays/pride/pride_facts.py b/bot/exts/holidays/pride/pride_facts.py index 5be1b085..7dca953b 100644 --- a/bot/exts/holidays/pride/pride_facts.py +++ b/bot/exts/holidays/pride/pride_facts.py @@ -56,7 +56,7 @@ class PrideFacts(commands.Cog): await ctx.send(f"Could not parse option {option}") @staticmethod - def get_fact_embed(day_num: int | None=None) -> discord.Embed: + def get_fact_embed(day_num: int | None = None) -> discord.Embed: """ Makes a embed for the fact on the given day_num to be sent. diff --git a/bot/exts/utilities/conversationstarters.py b/bot/exts/utilities/conversationstarters.py index a019c789..a2de903d 100644 --- a/bot/exts/utilities/conversationstarters.py +++ b/bot/exts/utilities/conversationstarters.py @@ -1,4 +1,3 @@ -import asyncio from contextlib import suppress from functools import partial from pathlib import Path @@ -94,7 +93,7 @@ class ConvoStarters(commands.Cog): check=partial(self._predicate, command_invoker, message), timeout=60.0 ) - except asyncio.TimeoutError: + except TimeoutError: with suppress(discord.NotFound): await message.clear_reaction("🔄") break diff --git a/bot/exts/utilities/githubinfo.py b/bot/exts/utilities/githubinfo.py index 74120f2d..41b9415a 100644 --- a/bot/exts/utilities/githubinfo.py +++ b/bot/exts/utilities/githubinfo.py @@ -285,7 +285,7 @@ class GithubInfo(commands.Cog): embed.add_field(name="Gists", value=f"[{gists}](https://gist.github.com/{quote(username, safe='')})") embed.add_field( - name=f"Organization{'s' if len(orgs)!=1 else ''}", + name=f"Organization{'s' if len(orgs) != 1 else ''}", value=orgs_to_add if orgs else "No organizations." ) embed.add_field(name="Website", value=blog) diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py index f1ae0e75..5ff25faf 100644 --- a/bot/utils/__init__.py +++ b/bot/utils/__init__.py @@ -73,7 +73,7 @@ async def disambiguate( try: message = await ctx.bot.wait_for("message", check=check, timeout=timeout) - except asyncio.TimeoutError: + except TimeoutError: raise BadArgument("Timed out.") try: diff --git a/bot/utils/checks.py b/bot/utils/checks.py index f1c2b3ce..c8a03935 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -3,7 +3,14 @@ import logging from collections.abc import Callable, Container, Iterable from discord.ext.commands import ( - BucketType, CheckFailure, Cog, Command, CommandOnCooldown, Context, Cooldown, CooldownMapping + BucketType, + CheckFailure, + Cog, + Command, + CommandOnCooldown, + Context, + Cooldown, + CooldownMapping, ) from bot import constants diff --git a/bot/utils/pagination.py b/bot/utils/pagination.py index 58115fd6..e5b887f1 100644 --- a/bot/utils/pagination.py +++ b/bot/utils/pagination.py @@ -1,4 +1,3 @@ -import asyncio import logging from collections.abc import Iterable @@ -197,7 +196,7 @@ class LinePaginator(Paginator): try: reaction, user = await ctx.bot.wait_for("reaction_add", timeout=timeout, check=event_check) log.trace(f"Got reaction: {reaction}") - except asyncio.TimeoutError: + except TimeoutError: log.debug("Timed out waiting for a reaction") break # We're done, no reactions for the last 5 minutes @@ -372,7 +371,7 @@ class ImagePaginator(Paginator): # Start waiting for reactions try: reaction, user = await ctx.bot.wait_for("reaction_add", timeout=timeout, check=check_event) - except asyncio.TimeoutError: + except TimeoutError: log.debug("Timed out waiting for a reaction") break # We're done, no reactions for the last 5 minutes diff --git a/pyproject.toml b/pyproject.toml index 1a70cfa0..72831c79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ ignore = [ "C401", "C408", "D100", "D104", "D105", "D107", "D203", "D212", "D214", "D215", "D301", "D400", "D401", "D402", "D404", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D412", "D413", "D414", "D416", "D417", - "E731", + "E226", "E731", "RET504", "RUF005", "S311", |