aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-24 19:41:31 -0800
committerGravatar MarkKoz <[email protected]>2020-03-22 15:54:38 -0700
commitf605da9b63e8f076296fb75bd5055cc333e46a84 (patch)
tree7a356738e393145d8feb3e7b4a53a07042f2b476
parentHelpChannels: add a function to get the last message in a channel (diff)
HelpChannels: add a function to send or edit the available message
Edits the dormant message or sends a new message if the dormant one cannot be found.
-rw-r--r--bot/cogs/help_channels.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index bda6ed7bd..6c4c6c50e 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -304,13 +304,9 @@ class HelpChannels(Scheduler, commands.Cog):
log.trace("Making a channel available.")
channel = await self.get_available_candidate()
- embed = discord.Embed(description=AVAILABLE_MSG)
-
log.info(f"Making #{channel.name} ({channel.id}) available.")
- # TODO: edit or delete the dormant message
- log.trace(f"Sending available message for #{channel.name} ({channel.id}).")
- await channel.send(embed=embed)
+ await self.send_available_message(channel)
log.trace(f"Moving #{channel.name} ({channel.id}) to the Available category.")
await channel.edit(
@@ -380,6 +376,21 @@ class HelpChannels(Scheduler, commands.Cog):
# be put in the queue.
await self.move_to_available()
+ async def send_available_message(self, channel: discord.TextChannel) -> None:
+ """Send the available message by editing a dormant message or sending a new message."""
+ channel_info = f"#{channel.name} ({channel.id})"
+ log.trace(f"Sending available message in {channel_info}.")
+
+ embed = discord.Embed(description=AVAILABLE_MSG)
+
+ msg = await self.get_last_message(channel)
+ if msg:
+ log.trace(f"Found dormant message {msg.id} in {channel_info}; editing it.")
+ await msg.edit(embed=embed)
+ else:
+ log.trace(f"Dormant message not found in {channel_info}; sending a new message.")
+ await channel.send(embed=embed)
+
async def try_get_channel(self, channel_id: int) -> discord.abc.GuildChannel:
"""Attempt to get or fetch a channel and return it."""
log.trace(f"Getting the channel {channel_id}.")