diff options
| author | 2020-02-29 07:58:35 -0800 | |
|---|---|---|
| committer | 2020-03-22 15:54:39 -0700 | |
| commit | a3f4f3d19b6ba82b7bbb2e2bf01416c5fd1c0f31 (patch) | |
| tree | 37ff27658cd2f9dfc5de55b430d804ecf4ce25a4 | |
| parent | HelpChannels: move reading of element names to a function (diff) | |
HelpChannels: return elements as a truncated dict of names
| -rw-r--r-- | bot/cogs/help_channels.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 0c6c48914..c8609f168 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -1,4 +1,5 @@ import asyncio +import itertools import json import logging import random @@ -205,12 +206,13 @@ class HelpChannels(Scheduler, commands.Cog): yield channel @staticmethod - def get_names() -> t.List[str]: - """Return a list of element names.""" + 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.""" with Path("bot/resources/elements.json").open(encoding="utf-8") as elements_file: - # Discord has a hard limit of 50 channels per category. - # Easiest way to prevent more channels from being created is to limit available names. - return json.load(elements_file)[:50] + all_names = json.load(elements_file) + + truncated_names = itertools.islice(all_names.items(), count) + return dict(truncated_names) def get_used_names(self) -> t.Set[str]: """Return channels names which are already being used.""" |