diff options
| author | 2020-04-06 17:25:44 +0200 | |
|---|---|---|
| committer | 2020-04-06 17:25:44 +0200 | |
| commit | 4cb5030fd524c4dd8adce9c9e1fe9cc26228ad9b (patch) | |
| tree | ac2d4b641e551ad787ecbc4ec3bcce7daba74a98 | |
| parent | Change help channel sorting to bottom position (diff) | |
Add channel status emoji to help channels
I've added channel status emojis as a prefix to our help channels to make it more obvious to the end user what the current status of a channel is. All channels in the Available category will be marked with a green checkmark emoji, while all channels in the In Use category will be marked with an hourglass. Channels in the Dormant category stay unadorned.
Channels will be stripped of their previous prefix when moved to another category. This relies on the `help-` naming convention, as that is the most reliable way to do it that does not break if we ever opt for another emoji.
| -rw-r--r-- | bot/cogs/help_channels.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 68dbdf9ed..4fddba627 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -60,6 +60,10 @@ question to maximize your chance of getting a good answer. If you're not sure ho through our guide for [asking a good question]({ASKING_GUIDE_URL}). """ +AVAILABLE_EMOJI = "✅" +IN_USE_EMOJI = "⌛" +NAME_SEPARATOR = "|" + class TaskData(t.NamedTuple): """Data for a scheduled task.""" @@ -236,6 +240,20 @@ class HelpChannels(Scheduler, commands.Cog): return position @staticmethod + def get_clean_channel_name(channel: discord.TextChannel) -> str: + """Return a clean channel name without status emojis prefix.""" + try: + # Try to remove the status prefix using the index of "help-" + name = channel.name[channel.name.index("help-"):] + log.trace(f"The clean name for `{channel}` is `{name}`") + except ValueError: + # If, for some reason, the channel name does not contain "help-" fall back gracefully + log.info(f"Can't get clean name as `{channel}` does not follow the `help-` naming convention.") + name = channel.name + + return name + + @staticmethod def get_category_channels(category: discord.CategoryChannel) -> t.Iterable[discord.TextChannel]: """Yield the text channels of the `category` in an unsorted manner.""" log.trace(f"Getting text channels in the category '{category}' ({category.id}).") @@ -419,7 +437,9 @@ class HelpChannels(Scheduler, commands.Cog): await self.send_available_message(channel) log.trace(f"Moving #{channel} ({channel.id}) to the Available category.") + await channel.edit( + name=f"{AVAILABLE_EMOJI}{NAME_SEPARATOR}{self.get_clean_channel_name(channel)}", category=self.available_category, sync_permissions=True, topic=AVAILABLE_TOPIC, @@ -430,6 +450,7 @@ class HelpChannels(Scheduler, commands.Cog): log.info(f"Moving #{channel} ({channel.id}) to the Dormant category.") await channel.edit( + name=self.get_clean_channel_name(channel), category=self.dormant_category, sync_permissions=True, topic=DORMANT_TOPIC, @@ -450,6 +471,7 @@ class HelpChannels(Scheduler, commands.Cog): log.info(f"Moving #{channel} ({channel.id}) to the In Use category.") await channel.edit( + name=f"{IN_USE_EMOJI}{NAME_SEPARATOR}{self.get_clean_channel_name(channel)}", category=self.in_use_category, sync_permissions=True, topic=IN_USE_TOPIC, |