such cleanup

This commit is contained in:
2025-02-15 08:36:45 -05:00
parent d60828df07
commit 9d23438b13
12 changed files with 357 additions and 209 deletions

View File

@ -18,16 +18,19 @@ async def get_channel_by_name(bot: discord.Bot, channel: str,
Returns:
Optional[Any]
"""
channel: str = re.sub(r'^#', '', channel.strip())
channel = re.sub(r'^#', '', channel.strip())
if not guild:
return discord.utils.get(bot.get_all_channels(),
name=channel)
else:
channels: list = bot.get_guild(guild).channels
_guild: Optional[discord.Guild] = bot.get_guild(guild)
if not _guild:
return None
channels: list = _guild.channels
for _channel in channels:
if _channel.name.lower() == channel.lower().strip():
return _channel
return
return None
async def send_message(bot: discord.Bot, channel: str,
message: str, guild: int | None = None) -> None:
@ -43,10 +46,12 @@ async def send_message(bot: discord.Bot, channel: str,
None
"""
if channel.isnumeric():
channel: int = int(channel)
_channel = bot.get_channel(channel)
channel_int: int = int(channel)
_channel = bot.get_channel(channel_int)
else:
channel: str = re.sub(r'^#', '', channel.strip())
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)