diff options
| author | 2020-02-29 08:04:01 -0800 | |
|---|---|---|
| committer | 2020-03-22 15:54:39 -0700 | |
| commit | 379f4093b1ea2e8f403046512486a0d962ab697d (patch) | |
| tree | 02d4171cb221feab56fb061341515c92ca04628e | |
| parent | HelpChannels: return elements as a truncated dict of names (diff) | |
HelpChannels: warn if too many help channels will be possible
Discord only supports 50 channels per category.
* Add a constant for the maximum number of channels per category
* Add trace logging to `get_names`
| -rw-r--r-- | bot/cogs/help_channels.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index c8609f168..64443f81c 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -23,6 +23,7 @@ AVAILABLE_TOPIC = "" IN_USE_TOPIC = "" DORMANT_TOPIC = "" ASKING_GUIDE_URL = "https://pythondiscord.com/pages/asking-good-questions/" +MAX_CHANNELS_PER_CATEGORY = 50 AVAILABLE_MSG = f""" This help channel is now **available**, which means that you can claim it by simply typing your \ @@ -208,6 +209,14 @@ class HelpChannels(Scheduler, commands.Cog): @staticmethod def get_names(count: int = constants.HelpChannels.max_total_channels) -> t.Dict[str, int]: """Return a dict with the first `count` element names and their alphabetical indices.""" + log.trace(f"Getting the first {count} element names from JSON.") + + if count > MAX_CHANNELS_PER_CATEGORY: + log.warning( + f"{count} is too many help channels to make available! " + f"Discord only supports at most {MAX_CHANNELS_PER_CATEGORY} channels per category." + ) + with Path("bot/resources/elements.json").open(encoding="utf-8") as elements_file: all_names = json.load(elements_file) |