diff options
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/seasons/__init__.py | 21 | 
1 files changed, 20 insertions, 1 deletions
diff --git a/bot/seasons/__init__.py b/bot/seasons/__init__.py index 4f091116..af270901 100644 --- a/bot/seasons/__init__.py +++ b/bot/seasons/__init__.py @@ -5,7 +5,7 @@ from typing import List  from bot.seasons.season import SeasonBase -__all__ = ("SeasonBase", "get_seasons") +__all__ = ("SeasonBase", "get_seasons", "get_extensions")  log = logging.getLogger(__name__) @@ -18,3 +18,22 @@ def get_seasons() -> List[str]:          if module.ispkg:              seasons.append(module.name)      return seasons + + +def get_extensions() -> List[str]: +    """ +    Give a list of dot-separated paths to all extensions. + +    The strings are formatted in a way such that the bot's `load_extension` +    method can take them. Use this to load all available extensions. +    """ +    base_path = Path("bot", "seasons") +    extensions = [] + +    for package in pkgutil.iter_modules([base_path]): +        package_path = base_path.joinpath(package.name) + +        for module in pkgutil.iter_modules([package_path]): +            extensions.append(f"bot.seasons.{package.name}.{module.name}") + +    return extensions  |