Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class Channels(metaclass=YAMLGetter):

meta: int
python_general: int
how_to_get_help: int

cooldown: int

Expand Down
40 changes: 40 additions & 0 deletions bot/exts/help_channels/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from bot import constants
from bot.bot import Bot
from bot.constants import Channels
from bot.exts.help_channels import _caches, _channel, _cooldown, _message, _name, _stats
from bot.utils import channel as channel_utils, lock, scheduling

Expand All @@ -20,6 +21,7 @@
HELP_CHANNEL_TOPIC = """
This is a Python help channel. You can claim your own help channel in the Python Help: Available category.
"""
AVAILABLE_HELP_CHANNELS = "**Currently available help channel(s):** {available}"


class HelpChannels(commands.Cog):
Expand Down Expand Up @@ -72,6 +74,11 @@ def __init__(self, bot: Bot):

self.last_notification: t.Optional[datetime] = None

# Acquiring and modifying the channel to dynamically update the available help channels message.
self.how_to_get_help: discord.TextChannel = None
self.available_help_channels: t.Set[discord.TextChannel] = set()
self.dynamic_message: discord.Message = None

# Asyncio stuff
self.queue_tasks: t.List[asyncio.Task] = []
self.init_task = self.bot.loop.create_task(self.init_cog())
Expand Down Expand Up @@ -114,6 +121,9 @@ async def claim_channel(self, message: discord.Message) -> None:

await _caches.unanswered.set(message.channel.id, True)

# Removing the help channel from the dynamic message, and editing/sending that message.
self.available_help_channels.remove(message.channel)

# Not awaited because it may indefinitely hold the lock while waiting for a channel.
scheduling.create_task(self.move_to_available(), name=f"help_claim_{message.id}")

Expand Down Expand Up @@ -275,6 +285,10 @@ async def init_cog(self) -> None:
# This may confuse users. So would potentially long delays for the cog to become ready.
self.close_command.enabled = True

# Getting channels that need to be included in the dynamic message.
await self.update_available_help_channels()
log.trace("Dynamic available help message updated.")

await self.init_available()
_stats.report_counts()

Expand Down Expand Up @@ -332,6 +346,10 @@ async def move_to_available(self) -> None:
category_id=constants.Categories.help_available,
)

# Adding the help channel to the dynamic message, and editing/sending that message.
self.available_help_channels.add(channel)
await self.update_available_help_channels()
Comment thread
Xithrius marked this conversation as resolved.

_stats.report_counts()

async def move_to_dormant(self, channel: discord.TextChannel) -> None:
Expand Down Expand Up @@ -461,3 +479,25 @@ async def wait_for_dormant_channel(self) -> discord.TextChannel:
self.queue_tasks.remove(task)

return channel

async def update_available_help_channels(self) -> None:
"""Updates the dynamic message within #how-to-get-help for available help channels."""
if not self.available_help_channels:
self.available_help_channels = set(
c for c in self.available_category.channels if not _channel.is_excluded_channel(c)
)

available_channels = AVAILABLE_HELP_CHANNELS.format(
available=', '.join(c.mention for c in self.available_help_channels) or None
)

if self.how_to_get_help is None:
self.how_to_get_help = await channel_utils.try_get_channel(Channels.how_to_get_help)
Comment thread
Xithrius marked this conversation as resolved.

try:
if self.dynamic_message is None:
self.dynamic_message = await self.how_to_get_help.fetch_message(self.how_to_get_help.last_message_id)
await self.dynamic_message.edit(content=available_channels)
except discord.NotFound:
self.dynamic_message = await self.how_to_get_help.send(available_channels)
Comment thread
Xithrius marked this conversation as resolved.
log.trace("A dynamic message was sent for later modification because one couldn't be found.")
1 change: 1 addition & 0 deletions config-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ guild:

# Python Help: Available
cooldown: 720603994149486673
how_to_get_help: 704250143020417084

# Topical
discord_py: 343944376055103488
Expand Down