A-0.1 - Modularer Aufbau #13

Merged
edraft merged 118 commits from 0.1 into Alpha 2021-11-25 21:02:12 +01:00
2 changed files with 27 additions and 7 deletions
Showing only changes of commit 9c25ec9f24 - Show all commits

View File

@ -1,7 +1,9 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from discord.ext import commands
class BotServiceABC(ABC):
class BotServiceABC(ABC, commands.Bot):
@abstractmethod @abstractmethod
def __init__(self): pass def __init__(self): pass

View File

@ -1,22 +1,40 @@
from datetime import datetime from datetime import datetime
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.logging import LoggerABC from cpl_core.console import Console
from cpl_core.logging import LoggerABC, LoggingLevelEnum
from cpl_core.logging.logging_settings import LoggingSettings
from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.abc.bot_service_abc import BotServiceABC
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
class BootLog(ModuleABC): class BootLog(ModuleABC):
def __init__(self, config: ConfigurationABC, logger: LoggerABC): def __init__(self, config: ConfigurationABC, logging_st: LoggingSettings, logger: LoggerABC, bot: BotServiceABC):
self._config = config self._config = config
self._logging_st = logging_st
self._logger = logger self._logger = logger
self._bot = bot
ModuleABC.__init__(self) ModuleABC.__init__(self)
async def on_ready(self): async def on_ready(self):
self._logger.info(__name__, f'Bot started') self._logger.info(__name__, f'Bot started')
try:
start_time = self._config.get_configuration('StartTime') start_time = self._config.get_configuration('StartTime')
init_time = round((datetime.now() - start_time).total_seconds(), 2) init_time = round((datetime.now() - start_time).total_seconds(), 2)
self._logger.debug(__name__, f'InitTime: {init_time}s') self._logger.info(__name__, f'Init time: {init_time}s')
# print warning if initialisation took too long
if init_time >= 30:
self._logger.warn(__name__, 'It takes long time to start the bot!')
# print error if initialisation took way too long
elif init_time >= 90:
self._logger.error(__name__, 'It takes very long time to start the bot!!!')
except Exception as e:
self._logger.error(__name__, 'Init time calculation failed', e)
return
self._logger.header(f'{self._bot.user.name}:')
if self._logging_st.console.value >= LoggingLevelEnum.INFO.value:
Console.banner(self._bot.user.name)