reformat (black)

This commit is contained in:
2025-04-17 14:35:56 -04:00
parent d12b066c8e
commit 1bb482315e
20 changed files with 1928 additions and 1326 deletions

View File

@ -6,11 +6,13 @@ from typing import Optional, Any
Discord Helper Methods
"""
async def get_channel_by_name(bot: discord.Bot, channel: str,
guild: int | None = None) -> Optional[Any]: # Optional[Any] used as pycord channel types can be ambigious
async def get_channel_by_name(
bot: discord.Bot, channel: str, guild: int | None = None
) -> Optional[Any]: # Optional[Any] used as pycord channel types can be ambigious
"""
Get Channel by Name
Args:
bot (discord.Bot)
channel (str)
@ -18,10 +20,9 @@ async def get_channel_by_name(bot: discord.Bot, channel: str,
Returns:
Optional[Any]
"""
channel = re.sub(r'^#', '', channel.strip())
channel = re.sub(r"^#", "", channel.strip())
if not guild:
return discord.utils.get(bot.get_all_channels(),
name=channel)
return discord.utils.get(bot.get_all_channels(), name=channel)
else:
_guild: Optional[discord.Guild] = bot.get_guild(guild)
if not _guild:
@ -32,12 +33,14 @@ async def get_channel_by_name(bot: discord.Bot, channel: str,
return _channel
return None
async def send_message(bot: discord.Bot, channel: str,
message: str, guild: int | None = None) -> None:
async def send_message(
bot: discord.Bot, channel: str, message: str, guild: int | None = None
) -> None:
"""
Send Message to the provided channel. If guild is provided, will limit to channels within that guild to ensure the correct
channel is selected. Useful in the event a channel exists in more than one guild that the bot resides in.
Args:
bot (discord.Bot)
channel (str)
@ -50,9 +53,8 @@ async def send_message(bot: discord.Bot, channel: str,
channel_int: int = int(channel)
_channel = bot.get_channel(channel_int)
else:
channel = re.sub(r'^#', '', channel.strip())
_channel = await get_channel_by_name(bot=bot,
channel=channel, guild=guild)
channel = re.sub(r"^#", "", channel.strip())
_channel = await get_channel_by_name(bot=bot, channel=channel, guild=guild)
if not isinstance(_channel, discord.TextChannel):
return None
await _channel.send(message)