style(repo): ruff fixes
This commit is contained in:
parent
9df7f15bbe
commit
ea5f51892a
7 changed files with 39 additions and 38 deletions
|
@ -183,7 +183,7 @@ class Backup(commands.Cog):
|
||||||
continue
|
continue
|
||||||
cog_modules.append(cog_module)
|
cog_modules.append(cog_module)
|
||||||
|
|
||||||
for cog in set(cog.name for cog in cog_modules):
|
for cog in {cog.name for cog in cog_modules}:
|
||||||
poss_installed_path = (await downloader.cog_install_path()) / cog
|
poss_installed_path = (await downloader.cog_install_path()) / cog
|
||||||
if poss_installed_path.exists():
|
if poss_installed_path.exists():
|
||||||
with contextlib.suppress(commands.ExtensionNotLoaded):
|
with contextlib.suppress(commands.ExtensionNotLoaded):
|
||||||
|
|
|
@ -91,11 +91,11 @@ class Bible(commands.Cog):
|
||||||
response.status,
|
response.status,
|
||||||
)
|
)
|
||||||
if response.status == 401:
|
if response.status == 401:
|
||||||
raise bible.errors.UnauthorizedError()
|
raise bible.errors.UnauthorizedError
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError
|
||||||
if response.status == 503:
|
if response.status == 503:
|
||||||
raise bible.errors.ServiceUnavailableError()
|
raise bible.errors.ServiceUnavailableError
|
||||||
return Version(
|
return Version(
|
||||||
bible_id=bible_id,
|
bible_id=bible_id,
|
||||||
abbreviation=data["data"]["abbreviation"],
|
abbreviation=data["data"]["abbreviation"],
|
||||||
|
@ -135,15 +135,15 @@ class Bible(commands.Cog):
|
||||||
response.status,
|
response.status,
|
||||||
)
|
)
|
||||||
if response.status == 400:
|
if response.status == 400:
|
||||||
raise bible.errors.InexplicableError()
|
raise bible.errors.InexplicableError
|
||||||
if response.status == 401:
|
if response.status == 401:
|
||||||
raise bible.errors.UnauthorizedError()
|
raise bible.errors.UnauthorizedError
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError
|
||||||
if response.status == 404:
|
if response.status == 404:
|
||||||
raise bible.errors.NotFoundError()
|
raise bible.errors.NotFoundError
|
||||||
if response.status == 503:
|
if response.status == 503:
|
||||||
raise bible.errors.ServiceUnavailableError()
|
raise bible.errors.ServiceUnavailableError
|
||||||
|
|
||||||
fums_url = "https://fums.api.bible/f3"
|
fums_url = "https://fums.api.bible/f3"
|
||||||
fums_params = {
|
fums_params = {
|
||||||
|
@ -176,11 +176,11 @@ class Bible(commands.Cog):
|
||||||
response.status,
|
response.status,
|
||||||
)
|
)
|
||||||
if response.status == 401:
|
if response.status == 401:
|
||||||
raise bible.errors.UnauthorizedError()
|
raise bible.errors.UnauthorizedError
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError
|
||||||
if response.status == 503:
|
if response.status == 503:
|
||||||
raise bible.errors.ServiceUnavailableError()
|
raise bible.errors.ServiceUnavailableError
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
async def _get_chapters(self, bible_id: str, book_id: str) -> dict:
|
async def _get_chapters(self, bible_id: str, book_id: str) -> dict:
|
||||||
|
@ -195,11 +195,11 @@ class Bible(commands.Cog):
|
||||||
response.status,
|
response.status,
|
||||||
)
|
)
|
||||||
if response.status == 401:
|
if response.status == 401:
|
||||||
raise bible.errors.UnauthorizedError()
|
raise bible.errors.UnauthorizedError
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError
|
||||||
if response.status == 503:
|
if response.status == 503:
|
||||||
raise bible.errors.ServiceUnavailableError()
|
raise bible.errors.ServiceUnavailableError
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
async def _get_verses(self, bible_id: str, book_id: str, chapter: int) -> dict:
|
async def _get_verses(self, bible_id: str, book_id: str, chapter: int) -> dict:
|
||||||
|
@ -214,11 +214,11 @@ class Bible(commands.Cog):
|
||||||
response.status,
|
response.status,
|
||||||
)
|
)
|
||||||
if response.status == 401:
|
if response.status == 401:
|
||||||
raise bible.errors.UnauthorizedError()
|
raise bible.errors.UnauthorizedError
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
raise bible.errors.BibleAccessError()
|
raise bible.errors.BibleAccessError
|
||||||
if response.status == 503:
|
if response.status == 503:
|
||||||
raise bible.errors.ServiceUnavailableError()
|
raise bible.errors.ServiceUnavailableError
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
@commands.group(autohelp=True)
|
@commands.group(autohelp=True)
|
||||||
|
|
|
@ -40,8 +40,7 @@ class EmojiInfo(commands.Cog):
|
||||||
emoji_codepoint = "-".join([hex(ord(char))[2:] for char in unicode_emoji])
|
emoji_codepoint = "-".join([hex(ord(char))[2:] for char in unicode_emoji])
|
||||||
segments = emoji_codepoint.split("-")
|
segments = emoji_codepoint.split("-")
|
||||||
valid_segments = [seg for seg in segments if len(seg) >= 4]
|
valid_segments = [seg for seg in segments if len(seg) >= 4]
|
||||||
emoji_url = f"{base_url}{valid_segments[0]}.png"
|
return f"{base_url}{valid_segments[0]}.png"
|
||||||
return emoji_url
|
|
||||||
|
|
||||||
async def fetch_primary_color(self, emoji_url: str) -> discord.Color | None:
|
async def fetch_primary_color(self, emoji_url: str) -> discord.Color | None:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
@ -50,8 +49,7 @@ class EmojiInfo(commands.Cog):
|
||||||
return None
|
return None
|
||||||
image = await response.read()
|
image = await response.read()
|
||||||
dominant_color = ColorThief(io.BytesIO(image)).get_color(quality=1)
|
dominant_color = ColorThief(io.BytesIO(image)).get_color(quality=1)
|
||||||
color = discord.Color.from_rgb(*dominant_color)
|
return discord.Color.from_rgb(*dominant_color)
|
||||||
return color
|
|
||||||
|
|
||||||
async def get_emoji_info(self, emoji: PartialEmoji) -> tuple[str, str]:
|
async def get_emoji_info(self, emoji: PartialEmoji) -> tuple[str, str]:
|
||||||
if emoji.is_unicode_emoji():
|
if emoji.is_unicode_emoji():
|
||||||
|
@ -98,8 +96,9 @@ class EmojiInfo(commands.Cog):
|
||||||
embed.set_thumbnail(url=emoji_url)
|
embed.set_thumbnail(url=emoji_url)
|
||||||
|
|
||||||
await interaction.followup.send(embed=embed)
|
await interaction.followup.send(embed=embed)
|
||||||
else:
|
return None
|
||||||
await interaction.followup.send(content=string)
|
await interaction.followup.send(content=string)
|
||||||
|
return None
|
||||||
|
|
||||||
@commands.command(name="emoji")
|
@commands.command(name="emoji")
|
||||||
async def emoji(self, ctx: commands.Context, *, emoji: str) -> None:
|
async def emoji(self, ctx: commands.Context, *, emoji: str) -> None:
|
||||||
|
@ -119,5 +118,6 @@ class EmojiInfo(commands.Cog):
|
||||||
embed.set_thumbnail(url=emoji_url)
|
embed.set_thumbnail(url=emoji_url)
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
else:
|
return None
|
||||||
await ctx.send(content=string)
|
await ctx.send(content=string)
|
||||||
|
return None
|
||||||
|
|
|
@ -105,5 +105,5 @@ class HotReloadHandler(RegexMatchingEventHandler):
|
||||||
"""Reload modified cog."""
|
"""Reload modified cog."""
|
||||||
core_logic = CoreLogic(bot=self.bot)
|
core_logic = CoreLogic(bot=self.bot)
|
||||||
self.logger.info("Reloading cogs: %s", humanize_list(cog_names, style="unit"))
|
self.logger.info("Reloading cogs: %s", humanize_list(cog_names, style="unit"))
|
||||||
await core_logic._reload(pkg_names=cog_names)
|
await core_logic._reload(pkg_names=cog_names) # noqa: SLF001 # We have to use this private method because there is no public API to reload other cogs
|
||||||
self.logger.info("Reloaded cogs: %s", humanize_list(cog_names, style="unit"))
|
self.logger.info("Reloaded cogs: %s", humanize_list(cog_names, style="unit"))
|
||||||
|
|
|
@ -40,13 +40,13 @@ class Nerdify(commands.Cog):
|
||||||
|
|
||||||
@commands.command(aliases=["nerd"])
|
@commands.command(aliases=["nerd"])
|
||||||
async def nerdify(
|
async def nerdify(
|
||||||
self, ctx: commands.Context, *, text: Optional[str] = None
|
self, ctx: commands.Context, *, text: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Nerdify the replied to message, previous message, or your own text."""
|
"""Nerdify the replied to message, previous message, or your own text."""
|
||||||
if not text:
|
if not text:
|
||||||
if hasattr(ctx.message, "reference") and ctx.message.reference:
|
if hasattr(ctx.message, "reference") and ctx.message.reference:
|
||||||
with suppress(
|
with suppress(
|
||||||
discord.Forbidden, discord.NotFound, discord.HTTPException
|
discord.Forbidden, discord.NotFound, discord.HTTPException,
|
||||||
):
|
):
|
||||||
message_id = ctx.message.reference.message_id
|
message_id = ctx.message.reference.message_id
|
||||||
if message_id:
|
if message_id:
|
||||||
|
@ -62,7 +62,7 @@ class Nerdify(commands.Cog):
|
||||||
ctx.channel,
|
ctx.channel,
|
||||||
self.nerdify_text(text),
|
self.nerdify_text(text),
|
||||||
allowed_mentions=discord.AllowedMentions(
|
allowed_mentions=discord.AllowedMentions(
|
||||||
everyone=False, users=False, roles=False
|
everyone=False, users=False, roles=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class Nerdify(commands.Cog):
|
||||||
return f'"{text}" 🤓'
|
return f'"{text}" 🤓'
|
||||||
|
|
||||||
async def type_message(
|
async def type_message(
|
||||||
self, destination: discord.abc.Messageable, content: str, **kwargs: Any
|
self, destination: discord.abc.Messageable, content: str, **kwargs: Any,
|
||||||
) -> Union[discord.Message, None]:
|
) -> Union[discord.Message, None]:
|
||||||
"""Simulate typing and sending a message to a destination.
|
"""Simulate typing and sending a message to a destination.
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ class Pterodactyl(commands.Cog):
|
||||||
"P": str(response["players"]["online"]),
|
"P": str(response["players"]["online"]),
|
||||||
"V": response["version"],
|
"V": response["version"],
|
||||||
"D": response["motd"]["clean"][0] if response["motd"]["clean"] else "unset",
|
"D": response["motd"]["clean"][0] if response["motd"]["clean"] else "unset",
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
placeholders.update(
|
placeholders.update(
|
||||||
|
@ -159,7 +159,7 @@ class Pterodactyl(commands.Cog):
|
||||||
"P": "0",
|
"P": "0",
|
||||||
"V": "Server Offline",
|
"V": "Server Offline",
|
||||||
"D": "Server Offline",
|
"D": "Server Offline",
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
for key, value in placeholders.items():
|
for key, value in placeholders.items():
|
||||||
topic = topic.replace(".$" + key, value)
|
topic = topic.replace(".$" + key, value)
|
||||||
|
@ -187,6 +187,7 @@ class Pterodactyl(commands.Cog):
|
||||||
output_str = "\n".join(response["players"]["list"])
|
output_str = "\n".join(response["players"]["list"])
|
||||||
return output_str, response["players"]["list"]
|
return output_str, response["players"]["list"]
|
||||||
return None
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
async def get_player_list_embed(self, ctx: Union[commands.Context, discord.Interaction]) -> Optional[discord.Embed]:
|
async def get_player_list_embed(self, ctx: Union[commands.Context, discord.Interaction]) -> Optional[discord.Embed]:
|
||||||
player_list = await self.get_player_list()
|
player_list = await self.get_player_list()
|
||||||
|
@ -220,9 +221,10 @@ class Pterodactyl(commands.Cog):
|
||||||
await self.websocket.send(json.dumps({"event": "set state", "args": [action]}))
|
await self.websocket.send(json.dumps({"event": "set state", "args": [action]}))
|
||||||
|
|
||||||
await message.edit(content=f"Server {action_ing}", view=None)
|
await message.edit(content=f"Server {action_ing}", view=None)
|
||||||
|
return None
|
||||||
|
|
||||||
else:
|
await message.edit(content="Cancelled.", view=None)
|
||||||
await message.edit(content="Cancelled.", view=None)
|
return None
|
||||||
|
|
||||||
async def send_command(self, ctx: Union[discord.Interaction, commands.Context], command: str):
|
async def send_command(self, ctx: Union[discord.Interaction, commands.Context], command: str):
|
||||||
channel = self.bot.get_channel(await config.console_channel())
|
channel = self.bot.get_channel(await config.console_channel())
|
||||||
|
|
|
@ -151,7 +151,7 @@ async def retrieve_websocket_credentials(coginstance: Pterodactyl) -> Optional[d
|
||||||
Socket: %s
|
Socket: %s
|
||||||
Token: %s...""",
|
Token: %s...""",
|
||||||
websocket_credentials['data']['socket'],
|
websocket_credentials['data']['socket'],
|
||||||
websocket_credentials['data']['token'][:20]
|
websocket_credentials['data']['token'][:20],
|
||||||
)
|
)
|
||||||
return websocket_credentials
|
return websocket_credentials
|
||||||
#NOTE - The token is truncated to prevent it from being logged in its entirety, for security reasons
|
#NOTE - The token is truncated to prevent it from being logged in its entirety, for security reasons
|
||||||
|
@ -262,6 +262,5 @@ async def generate_achievement_embed(coginstance: Pterodactyl, username: str, ac
|
||||||
def mask_ip(string: str) -> str:
|
def mask_ip(string: str) -> str:
|
||||||
def check(match: re.Match[str]):
|
def check(match: re.Match[str]):
|
||||||
ip = match.group(0)
|
ip = match.group(0)
|
||||||
masked_ip = '.'.join(r'\*' * len(octet) for octet in ip.split('.'))
|
return '.'.join(r'\*' * len(octet) for octet in ip.split('.'))
|
||||||
return masked_ip
|
|
||||||
return re.sub(r'\b(?:\d{1,3}\.){3}\d{1,3}\b', check, string)
|
return re.sub(r'\b(?:\d{1,3}\.){3}\d{1,3}\b', check, string)
|
||||||
|
|
Loading…
Add table
Reference in a new issue