Registered services

This commit is contained in:
Sven Heidemann 2022-01-15 14:33:09 +01:00
parent 0ef2428b9d
commit c968fbb3d7
4 changed files with 49 additions and 12 deletions

View File

@ -5,11 +5,9 @@ from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from gismo_core.abc.bot_service_abc import BotServiceABC 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.bot_settings import BotSettings
from gismo_core.configuration.server_settings import ServerSettings from gismo_core.configuration.server_settings import ServerSettings
from gismo_core.service.bot_service import BotService from gismo_core.service.bot_service import BotService
from gismo_data.service.migration_service import MigrationService
class Gismo(ApplicationABC): class Gismo(ApplicationABC):
@ -31,6 +29,7 @@ class Gismo(ApplicationABC):
async def main(self): async def main(self):
try: try:
self._logger.debug(__name__, f'Starting...\n')
self._logger.trace(__name__, f'Try to start {BotService}') self._logger.trace(__name__, f'Try to start {BotService}')
await self._bot.start_async() await self._bot.start_async()
except Exception as e: except Exception as e:

View File

@ -5,15 +5,16 @@ from typing import Optional
from cpl_core.application import StartupABC from cpl_core.application import StartupABC
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_core.database import DatabaseSettings from cpl_core.database import DatabaseSettings
from cpl_core.dependency_injection import (ServiceCollectionABC, from cpl_core.dependency_injection import ServiceCollectionABC, ServiceProviderABC
ServiceProviderABC)
from cpl_core.environment import ApplicationEnvironment from cpl_core.environment import ApplicationEnvironment
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from gismo_core.abc.bot_service_abc import BotServiceABC 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.command_abc import CommandABC
from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.abc.message_service_abc import MessageServiceABC
from gismo_core.service.bot_service import BotService 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_core.service.message_service import MessageService
from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC
from gismo_data.abc.migration_abc import MigrationABC 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_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService
from gismo_data.service.user_repository_service import UserRepositoryService from gismo_data.service.user_repository_service import UserRepositoryService
from modules.base.base import Base 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.boot_log.boot_log import BootLog
from modules.database.database import Database from modules.database.database import Database
from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.abc.permission_service_abc import PermissionServiceABC
from modules.permission.permission import Permission 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_abc import ModuleABC
from gismo_core.abc.module_service_abc import ModuleServiceABC from gismo_core.abc.module_service_abc import ModuleServiceABC
from gismo_core.service.module_service import ModuleService from gismo_core.service.module_service import ModuleService
from modules.permission.service.permission_service import PermissionService
class Startup(StartupABC): class Startup(StartupABC):
@ -69,6 +72,7 @@ class Startup(StartupABC):
return configuration return configuration
async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
provider: ServiceProviderABC = services.build_service_provider()
services.add_logging() services.add_logging()
services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings))
@ -78,6 +82,7 @@ class Startup(StartupABC):
services.add_singleton(BotServiceABC, BotService) services.add_singleton(BotServiceABC, BotService)
services.add_transient(MessageServiceABC, MessageService) services.add_transient(MessageServiceABC, MessageService)
services.add_transient(MigrationService) services.add_transient(MigrationService)
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
# data services # data services
services.add_transient(ServerRepositoryABC, ServerRepositoryService) services.add_transient(ServerRepositoryABC, ServerRepositoryService)
@ -91,7 +96,9 @@ class Startup(StartupABC):
services.add_singleton(PermissionServiceABC, PermissionService) services.add_singleton(PermissionServiceABC, PermissionService)
# commands # commands
services.add_singleton(CommandABC, BaseCommandService) services.add_singleton(CommandABC, PingCommandService)
services.add_singleton(CommandABC, PurgeCommandService)
services.add_singleton(CommandABC, AFKCommandService)
# modules # modules
services.add_transient(ModuleABC, Database) 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)
services.add_transient(MigrationABC, Migration_0_3_1) 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) 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)) self._config.add_configuration('Startup_InitTime', str(startup_init_time))
logger: LoggerABC = provider.get_service(LoggerABC) logger: LoggerABC = provider.get_service(LoggerABC)

View File

@ -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')

View File

@ -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_server import UserJoinedServer
from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
from modules.base.base_settings import BaseSettings 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 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_join_abc import OnMemberJoinABC
from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC
@ -47,7 +49,9 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
db: DatabaseContextABC, db: DatabaseContextABC,
messenger: MessageServiceABC, messenger: MessageServiceABC,
permission_service: PermissionServiceABC, permission_service: PermissionServiceABC,
base_command_service: BaseCommandService ping_command: PingCommandService,
purge_command: PurgeCommandService,
afk_command: AFKCommandService
): ):
self._config = config self._config = config
self._logger = logger self._logger = logger
@ -72,7 +76,11 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
}, },
[BaseSettings] [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') self._logger.info(__name__, f'Module {type(self)} loaded')
def _get_config(self, g_id: int) -> BaseSettings: def _get_config(self, g_id: int) -> BaseSettings: