A-0.1 - Modularer Aufbau #13
@ -18,8 +18,7 @@
|
||||
"Dependencies": [
|
||||
"sh_cpl-core>=2021.10.2",
|
||||
"sh_cpl-query>=2021.10.2",
|
||||
"discord.py==1.7.3",
|
||||
"nest-asyncio==1.5.1"
|
||||
"discord.py==1.7.3"
|
||||
],
|
||||
"PythonVersion": ">=3.9.2",
|
||||
"PythonPath": {
|
||||
|
@ -32,10 +32,16 @@ class BootLog(ModuleABC, OnReadyABC):
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._message_service = message_service
|
||||
|
||||
# ModuleABC.__init__(self)
|
||||
|
||||
self._priorities = {
|
||||
OnReadyABC: 10
|
||||
}
|
||||
|
||||
self._logger.trace(__name__, f'Module {type(self)} loaded')
|
||||
|
||||
def get_priority(self, t: type) -> int:
|
||||
return self._priorities[t]
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.debug(__name__, f'Module {type(self)} started')
|
||||
try:
|
||||
|
@ -6,3 +6,6 @@ class ModuleABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_priority(self, t: type) -> int: pass
|
||||
|
@ -1,4 +1,4 @@
|
||||
from abc import ABCMeta
|
||||
from abc import ABC, ABCMeta
|
||||
from datetime import datetime
|
||||
from typing import Optional, Sequence, Union
|
||||
import discord
|
||||
@ -25,17 +25,24 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC):
|
||||
self._env = env
|
||||
self._modules: List[ModuleABC] = List()
|
||||
self._modules.extend(ModuleABC.__subclasses__())
|
||||
|
||||
|
||||
def _get_modules(self, t: type) -> List[ModuleABC]:
|
||||
module_types = self._modules.where(lambda m: issubclass(m, t))
|
||||
modules = List(t)
|
||||
for module_type in module_types:
|
||||
modules.append(self._services.get_service(module_type))
|
||||
|
||||
return modules.order_by(lambda m: m.get_priority(t))
|
||||
|
||||
async def on_connect(self): pass
|
||||
|
||||
async def on_disconnect(self): pass
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.debug(__name__, 'Start on_ready modules')
|
||||
modules = self._modules.where(lambda m: issubclass(m, OnReadyABC))
|
||||
for module_type in modules:
|
||||
module: OnReadyABC = self._services.get_service(module_type)
|
||||
self._logger.debug(__name__, f'Start on_ready modules')
|
||||
for module in self._get_modules(OnReadyABC):
|
||||
await module.on_ready()
|
||||
|
||||
self._logger.debug(__name__, 'Stopped on_ready modules')
|
||||
|
||||
async def on_resume(self): pass
|
||||
|
Reference in New Issue
Block a user