blob: ceb472d2f8345887f1386d864a8b4f478f1a3c07 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import logging
import pkgutil
from pathlib import Path
from typing import List
__all__ = ("get_season_names", "get_extensions")
log = logging.getLogger(__name__)
def get_season_names() -> List[str]:
"""Return names of all packages located in /bot/exts/."""
seasons = [
package.name
for package in pkgutil.iter_modules(__path__)
if package.ispkg
]
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(__path__[0])
extensions = []
for season in get_season_names():
for module in pkgutil.iter_modules([base_path.joinpath(season)]):
extensions.append(f"bot.exts.{season}.{module.name}")
return extensions
|