A-0.1 - Modularer Aufbau #13

Merged
edraft merged 118 commits from 0.1 into Alpha 2021-11-25 21:02:12 +01:00
6 changed files with 45 additions and 14 deletions
Showing only changes of commit 6509f628ca - Show all commits

View File

@ -8,7 +8,7 @@
"LoggingSettings": {
"Path": "logs/",
"Filename": "log_$start_time.log",
"Filename": "log_dev.log",
"ConsoleLogLevel": "TRACE",
"FileLogLevel": "TRACE"
},

View File

@ -1,17 +1,19 @@
from datetime import datetime
import discord
from discord import guild
from async_timeout import asyncio
from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console
from cpl_core.logging import LoggerABC, LoggingLevelEnum, LoggingSettings
from discord import guild
from gismo_core.abc.bot_service_abc import BotServiceABC
from gismo_core.abc.message_service_abc import MessageServiceABC
from gismo_core.configuration.server_settings import ServerSettings
from modules_core.abc.module_abc import ModuleABC
from modules_core.abc.on_ready_abc import OnReadyABC
class BootLog(ModuleABC):
class BootLog(ModuleABC, OnReadyABC):
def __init__(
self,

View File

@ -1,13 +1,8 @@
from abc import ABC, abstractmethod
from cpl_query.extension import List
from modules_core.events_enum import EventsEnum
import discord
class ModuleABC(ABC):
@abstractmethod
def __init__(self): pass
# @property
# @abstractmethod
# def events(self) -> List[EventsEnum]: pass

View File

@ -0,0 +1,11 @@
from abc import ABC, abstractmethod
import discord
class OnMessageABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
async def on_message(self, message: discord.Message): pass

View File

@ -0,0 +1,10 @@
from abc import ABC, abstractmethod
class OnReadyABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
async def on_ready(self): pass

View File

@ -1,3 +1,4 @@
from async_timeout import asyncio
import discord
from discord.ext import commands
@ -7,7 +8,8 @@ from cpl_core.logging import LoggerABC
from cpl_query.extension import List
from modules_core.abc.module_abc import ModuleABC
from modules_core.abc.module_service_abc import ModuleServiceABC
from modules_core.events_enum import EventsEnum
from modules_core.abc.on_message_abc import OnMessageABC
from modules_core.abc.on_ready_abc import OnReadyABC
class ModuleService(ModuleServiceABC):
@ -21,10 +23,21 @@ class ModuleService(ModuleServiceABC):
async def on_ready(self):
self._logger.debug(__name__, 'Start on_ready modules')
modules = self._modules.where(lambda m: hasattr(m, EventsEnum.on_ready.value) and callable(m.on_ready))
modules = self._modules.where(lambda m: issubclass(m, OnReadyABC))
for module_type in modules:
module = self._services.get_service(module_type)
module_type = module_type
module: OnReadyABC = self._services.get_service(module_type)
await module.on_ready()
self._logger.debug(__name__, 'Stopped on_ready modules')
async def on_message(self, message: discord.Message):
pass
self._logger.debug(__name__, 'Start on_message modules')
modules = self._modules.where(lambda m: issubclass(m, OnMessageABC))
for module_type in modules:
module_type = module_type
module: OnMessageABC = self._services.get_service(module_type)
await module.on_message(message)
self._logger.debug(__name__, f'Stopped on_message modules')