mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-22 00:07:48 +00:00
Commit hoarding is a terrible practice
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import importlib
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from tunebot.plugins import PluginInstance
|
||||
from tunebot.plugins.exceptions import PluginInitFailed
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from tunebot import BasePluginInstance
|
||||
from tunebot import ServiceBase
|
||||
from bot import TuneBot
|
||||
|
||||
AnyDict = dict[Any, Any]
|
||||
|
||||
|
||||
class FileSystemPluginLoader:
|
||||
def __init__(self, bot: "TuneBot") -> None:
|
||||
self.bot = bot
|
||||
|
||||
def load_plugin(self, plug_conf: AnyDict) -> "BasePluginInstance":
|
||||
"""
|
||||
Loads a plugin from configuration and returns a sequence of Services
|
||||
|
||||
Raises:
|
||||
PluginInitFailed: [description]
|
||||
|
||||
Returns:
|
||||
tuple[list["ServiceBase"], list[str]]: [description]
|
||||
"""
|
||||
services: list["ServiceBase"] = []
|
||||
for service_location in plug_conf["services"]:
|
||||
module = importlib.import_module(service_location)
|
||||
|
||||
if not hasattr(module, "setup"):
|
||||
raise PluginInitFailed('Failed to find setup() for "{location}"')
|
||||
|
||||
services.append(module.setup(self.bot, plug_conf))
|
||||
|
||||
return PluginInstance(plug_conf["config"], services, plug_conf["cogs"])
|
||||
|
||||
|
||||
__all__ = ("FileSystemPluginLoader",)
|
||||
Reference in New Issue
Block a user