A-0.1 - Modularer Aufbau #13

Merged
edraft merged 118 commits from 0.1 into Alpha 2021-11-25 21:02:12 +01:00
3 changed files with 28 additions and 11 deletions
Showing only changes of commit 12492cf596 - Show all commits

View File

@ -1,6 +1,8 @@
import discord
from discord.ext import commands
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from discord.ext import commands
from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.abc.bot_service_abc import BotServiceABC
from gismo_core.configuration.bot_settings import BotSettings from gismo_core.configuration.bot_settings import BotSettings
from gismo_core.configuration.discord_settings import DiscordSettings from gismo_core.configuration.discord_settings import DiscordSettings
@ -28,6 +30,14 @@ class BotService(BotServiceABC, commands.Bot):
await self.start(self._discord_settings.token) await self.start(self._discord_settings.token)
# continue at on_ready # continue at on_ready
async def stop_async(self):
self._logger.debug(__name__, f'Try to stop {BotService}')
try:
pass
# save data
except Exception as e:
self._logger.error(__name__, 'Stop failed', e)
async def on_ready(self): async def on_ready(self):
self._logger.info(__name__, 'Connected to discord') self._logger.info(__name__, 'Connected to discord')
@ -41,10 +51,6 @@ class BotService(BotServiceABC, commands.Bot):
await self._modules.on_ready() await self._modules.on_ready()
async def stop_async(self): async def on_message(self, message: discord.Message):
self._logger.debug(__name__, f'Try to stop {BotService}') self._logger.debug(__name__, f'Received message:\n{message}:\n{message.content}')
try: await self._modules.on_message(message)
pass
# save data
except Exception as e:
self._logger.error(__name__, 'Stop failed', e)

View File

@ -1,5 +1,6 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from codecs import register
import discord
class ModuleServiceABC(ABC): class ModuleServiceABC(ABC):
@ -9,3 +10,6 @@ class ModuleServiceABC(ABC):
@abstractmethod @abstractmethod
async def on_ready(self): pass async def on_ready(self): pass
@abstractmethod
async def on_message(self, message: discord.Message): pass

View File

@ -1,9 +1,13 @@
import discord
from discord.ext import commands
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from cpl_query.extension import List from cpl_query.extension import List
from modules_core.abc.module_abc import ModuleABC from modules_core.abc.module_abc import ModuleABC
from modules_core.abc.module_service_abc import ModuleServiceABC from modules_core.abc.module_service_abc import ModuleServiceABC
from modules_core.events_enum import EventsEnum
class ModuleService(ModuleServiceABC): class ModuleService(ModuleServiceABC):
@ -17,7 +21,10 @@ class ModuleService(ModuleServiceABC):
async def on_ready(self): async def on_ready(self):
self._logger.debug(__name__, 'Start on_ready modules') self._logger.debug(__name__, 'Start on_ready modules')
modules = self._modules.where(lambda m: hasattr(m, 'on_ready') and callable(m.on_ready)) modules = self._modules.where(lambda m: hasattr(m, EventsEnum.on_ready.value) and callable(m.on_ready))
for module_type in modules: for module_type in modules:
module = self._services.get_service(module_type) module = self._services.get_service(module_type)
await module.on_ready() await module.on_ready()
async def on_message(self, message: discord.Message):
pass