aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Mark <[email protected]>2022-06-07 12:48:41 -0700
committerGravatar Mark <[email protected]>2022-06-07 12:48:41 -0700
commit8896b2e2e2e569df2962c87429834804472b01c3 (patch)
tree0d4a918a87a0df4d7b9743df72810d542180f5a4
parentHelpChannels: pass message directly to pin_wrapper (diff)
HelpChannels: refactor pin/unpin functions
-rw-r--r--bot/exts/help_channels/_cog.py14
-rw-r--r--bot/exts/help_channels/_message.py16
2 files changed, 17 insertions, 13 deletions
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index b34431af0..6a6ada3ca 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -356,17 +356,17 @@ class HelpChannels(commands.Cog):
log.trace("Making a channel available.")
channel = await self.get_available_candidate()
- log.info(f"Making #{channel} ({channel.id}) available.")
+ channel_str = f"#{channel} ({channel.id})"
+ log.info(f"Making {channel_str} available.")
await _message.send_available_message(channel)
- log.trace(f"Moving #{channel} ({channel.id}) to the Available category.")
+ log.trace(f"Moving {channel_str} to the Available category.")
# Unpin any previously stuck pins
- log.trace(f"Looking for pins stuck in #{channel} ({channel.id}).")
- for message in await channel.pins():
- await _message.pin_wrapper(message, pin=False)
- log.debug(f"Removed a stuck pin from #{channel} ({channel.id}). ID: {message.id}")
+ log.trace(f"Looking for pins stuck in {channel_str}.")
+ if stuck_pins := await _message.unpin_all(channel):
+ log.debug(f"Removed {stuck_pins} stuck pins from {channel_str}.")
await _channel.move_to_bottom(
channel=channel,
@@ -439,7 +439,7 @@ class HelpChannels(commands.Cog):
else:
await members.handle_role_change(claimant, claimant.remove_roles, self.cooldown_role)
- await _message.unpin(channel)
+ await _message.unpin_all(channel)
await _stats.report_complete_session(channel.id, closed_on)
await self.move_to_dormant(channel)
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
index ef2366f23..720ad0774 100644
--- a/bot/exts/help_channels/_message.py
+++ b/bot/exts/help_channels/_message.py
@@ -173,8 +173,8 @@ async def notify(channel: discord.TextChannel, last_notification: t.Optional[Arr
async def pin(message: discord.Message) -> None:
- """Pin an initial question `message` and store it in a cache."""
- await pin_wrapper(message, pin=True)
+ """Pin an initial question `message`."""
+ await _pin_wrapper(message, pin=True)
async def send_available_message(channel: discord.TextChannel) -> None:
@@ -198,10 +198,14 @@ async def send_available_message(channel: discord.TextChannel) -> None:
await channel.send(embed=embed)
-async def unpin(channel: discord.TextChannel) -> None:
- """Unpin the initial question message sent in `channel`."""
+async def unpin_all(channel: discord.TextChannel) -> int:
+ """Unpin all pinned messages in `channel` and return the amount of unpinned messages."""
+ count = 0
for message in await channel.pins():
- await pin_wrapper(message, pin=False)
+ if await _pin_wrapper(message, pin=False):
+ count += 1
+
+ return count
def _match_bot_embed(message: t.Optional[discord.Message], description: str) -> bool:
@@ -216,7 +220,7 @@ def _match_bot_embed(message: t.Optional[discord.Message], description: str) ->
return message.author == bot.instance.user and bot_msg_desc.strip() == description.strip()
-async def pin_wrapper(message: discord.Message, *, pin: bool) -> bool:
+async def _pin_wrapper(message: discord.Message, *, pin: bool) -> bool:
"""
Pin `message` if `pin` is True or unpin if it's False.