Skip to content

Commit

Permalink
bug: Fix voice component module not loading correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pmdevita committed Nov 29, 2023
1 parent 9e3412d commit 1e70893
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions atsume/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from atsume.db.manager import database
from atsume.component.manager import manager as component_manager
from atsume.component import Component, ComponentConfig
from atsume.extensions.loader import attach_extensions, load_module_setting
from atsume.extensions.loader import attach_extensions, load_module_class
from atsume.utils import module_to_path


Expand Down Expand Up @@ -69,9 +69,9 @@ def initialize_discord() -> typing.Tuple[hikari.GatewayBot, tanjun.Client]:
)

if settings.VOICE_COMPONENT:
bot._voice = load_module_setting(
"VOICE_COMPONENT", hikari.impl.VoiceComponentImpl
)
bot._voice = load_module_class(
settings.VOICE_COMPONENT, hikari.impl.VoiceComponentImpl
)(bot)

global_commands = not settings.DEBUG and settings.GLOBAL_COMMANDS

Expand Down
14 changes: 12 additions & 2 deletions atsume/extensions/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def attach_extensions(client: tanjun.Client) -> None:
extensions.update(settings.EXTENSIONS)
extensions.update(ATSUME_EXTENSIONS)
for module_path in extensions:
func = load_module_setting(module_path, ExtensionCallable)
func = load_module_func(module_path, ExtensionCallable)
func(client)


Expand All @@ -36,7 +36,17 @@ def __init__(self, module_path: str):
T = typing.TypeVar("T")


def load_module_setting(module_path: str, return_type: typing.Type[T]) -> T:
def load_module_func(module_path: str, return_type: typing.Type[T]) -> T:
path = module_path.split(".")
try:
module = importlib.import_module(".".join(path[:-1]))
func = getattr(module, path[-1])
except (ModuleNotFoundError, AttributeError):
raise ModulePathNotFound(module_path)
return typing.cast(T, func)


def load_module_class(module_path: str, return_type: T) -> T:
path = module_path.split(".")
try:
module = importlib.import_module(".".join(path[:-1]))
Expand Down

0 comments on commit 1e70893

Please sign in to comment.