From c968fbb3d7a5951a2b43213f1e473b5d97d3e71b Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 15 Jan 2022 14:33:09 +0100 Subject: [PATCH] Registered services --- src/gismo/application.py | 3 +-- src/gismo/startup.py | 19 ++++++++++++------- src/gismo_core/abc/events/__init__.py | 25 +++++++++++++++++++++++++ src/modules/base/base.py | 14 +++++++++++--- 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 src/gismo_core/abc/events/__init__.py diff --git a/src/gismo/application.py b/src/gismo/application.py index 1562d7b..8d74f08 100644 --- a/src/gismo/application.py +++ b/src/gismo/application.py @@ -5,11 +5,9 @@ from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC from gismo_core.abc.bot_service_abc import BotServiceABC -from gismo_core.abc.module_service_abc import ModuleServiceABC from gismo_core.configuration.bot_settings import BotSettings from gismo_core.configuration.server_settings import ServerSettings from gismo_core.service.bot_service import BotService -from gismo_data.service.migration_service import MigrationService class Gismo(ApplicationABC): @@ -31,6 +29,7 @@ class Gismo(ApplicationABC): async def main(self): try: + self._logger.debug(__name__, f'Starting...\n') self._logger.trace(__name__, f'Try to start {BotService}') await self._bot.start_async() except Exception as e: diff --git a/src/gismo/startup.py b/src/gismo/startup.py index 5f64d5e..07f155e 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -5,15 +5,16 @@ from typing import Optional from cpl_core.application import StartupABC from cpl_core.configuration import ConfigurationABC from cpl_core.database import DatabaseSettings -from cpl_core.dependency_injection import (ServiceCollectionABC, - ServiceProviderABC) +from cpl_core.dependency_injection import ServiceCollectionABC, ServiceProviderABC from cpl_core.environment import ApplicationEnvironment from cpl_core.logging import LoggerABC from gismo_core.abc.bot_service_abc import BotServiceABC +from gismo_core.abc.client_utils_service_abc import ClientUtilsServiceABC from gismo_core.abc.command_abc import CommandABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.service.bot_service import BotService +from gismo_core.service.client_utils_service import ClientUtilsService from gismo_core.service.message_service import MessageService from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC from gismo_data.abc.migration_abc import MigrationABC @@ -36,15 +37,17 @@ from gismo_data.service.user_joined_server_repository_service import UserJoinedS from gismo_data.service.user_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService from gismo_data.service.user_repository_service import UserRepositoryService from modules.base.base import Base -from modules.base.service.base_command_service import BaseCommandService +from modules.base.service.afk_command_service import AFKCommandService +from modules.base.service.ping_command_service import PingCommandService +from modules.base.service.purge_command_service import PurgeCommandService from modules.boot_log.boot_log import BootLog from modules.database.database import Database from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.permission import Permission -from modules.permission.service.permission_service import PermissionService from gismo_core.abc.module_abc import ModuleABC from gismo_core.abc.module_service_abc import ModuleServiceABC from gismo_core.service.module_service import ModuleService +from modules.permission.service.permission_service import PermissionService class Startup(StartupABC): @@ -69,6 +72,7 @@ class Startup(StartupABC): return configuration async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: + provider: ServiceProviderABC = services.build_service_provider() services.add_logging() services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) @@ -78,6 +82,7 @@ class Startup(StartupABC): services.add_singleton(BotServiceABC, BotService) services.add_transient(MessageServiceABC, MessageService) services.add_transient(MigrationService) + services.add_transient(ClientUtilsServiceABC, ClientUtilsService) # data services services.add_transient(ServerRepositoryABC, ServerRepositoryService) @@ -91,7 +96,9 @@ class Startup(StartupABC): services.add_singleton(PermissionServiceABC, PermissionService) # commands - services.add_singleton(CommandABC, BaseCommandService) + services.add_singleton(CommandABC, PingCommandService) + services.add_singleton(CommandABC, PurgeCommandService) + services.add_singleton(CommandABC, AFKCommandService) # modules services.add_transient(ModuleABC, Database) @@ -104,8 +111,6 @@ class Startup(StartupABC): services.add_transient(MigrationABC, Migration_0_3) services.add_transient(MigrationABC, Migration_0_3_1) - provider: ServiceProviderABC = services.build_service_provider() - startup_init_time = round((datetime.now() - datetime.strptime(self._config.get_configuration('Startup_StartTime'), '%Y-%m-%d %H:%M:%S.%f')).total_seconds(), 2) self._config.add_configuration('Startup_InitTime', str(startup_init_time)) logger: LoggerABC = provider.get_service(LoggerABC) diff --git a/src/gismo_core/abc/events/__init__.py b/src/gismo_core/abc/events/__init__.py new file mode 100644 index 0000000..0e1ca48 --- /dev/null +++ b/src/gismo_core/abc/events/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +gismo sh-edraft Gismo +~~~~~~~~~~~~~~~~~~~ + +sh-edraft Dicord bot Gismo + +:copyright: (c) 2021 - 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'gismo_core.abc.events' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' +__version__ = '0.4.3' + +from collections import namedtuple + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/modules/base/base.py b/src/modules/base/base.py index b323a47..d4b9bd1 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -21,7 +21,9 @@ from gismo_data.model.user import User from gismo_data.model.user_joined_server import UserJoinedServer from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel from modules.base.base_settings import BaseSettings -from modules.base.service.base_command_service import BaseCommandService +from modules.base.service.afk_command_service import AFKCommandService +from modules.base.service.ping_command_service import PingCommandService +from modules.base.service.purge_command_service import PurgeCommandService from modules.permission.abc.permission_service_abc import PermissionServiceABC from gismo_core.abc.events.on_member_join_abc import OnMemberJoinABC from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC @@ -47,7 +49,9 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS db: DatabaseContextABC, messenger: MessageServiceABC, permission_service: PermissionServiceABC, - base_command_service: BaseCommandService + ping_command: PingCommandService, + purge_command: PurgeCommandService, + afk_command: AFKCommandService ): self._config = config self._logger = logger @@ -72,7 +76,11 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS }, [BaseSettings] ) - self._bot.add_cog(base_command_service) + + self._bot.add_cog(ping_command) + self._bot.add_cog(purge_command) + self._bot.add_cog(afk_command) + self._logger.info(__name__, f'Module {type(self)} loaded') def _get_config(self, g_id: int) -> BaseSettings: