2022-10-02 12:14:44 +02:00
|
|
|
import os
|
|
|
|
from datetime import datetime
|
2022-07-16 19:47:04 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2022-07-14 16:32:46 +02:00
|
|
|
from cpl_core.application import StartupABC
|
|
|
|
from cpl_core.configuration import ConfigurationABC
|
2022-07-16 23:23:07 +02:00
|
|
|
from cpl_core.database import DatabaseSettings
|
2022-07-14 16:32:46 +02:00
|
|
|
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
|
|
|
from cpl_core.environment import ApplicationEnvironment
|
2022-10-02 12:14:44 +02:00
|
|
|
from cpl_core.logging import LoggerABC
|
2022-07-16 23:23:07 +02:00
|
|
|
|
|
|
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
2022-10-02 13:13:23 +02:00
|
|
|
from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC
|
2022-07-16 23:23:07 +02:00
|
|
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
2022-10-02 12:14:44 +02:00
|
|
|
from bot_core.logging.command_logger import CommandLogger
|
2022-10-02 13:13:23 +02:00
|
|
|
from bot_core.logging.database_logger import DatabaseLogger
|
|
|
|
from bot_core.logging.message_logger import MessageLogger
|
2022-07-17 14:40:11 +02:00
|
|
|
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
|
2022-07-16 23:23:07 +02:00
|
|
|
from bot_core.service.client_utils_service import ClientUtilsService
|
|
|
|
from bot_core.service.message_service import MessageService
|
|
|
|
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
|
|
|
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
|
|
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
|
|
|
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
|
|
|
from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
|
|
|
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
|
|
|
from bot_data.db_context import DBContext
|
|
|
|
from bot_data.service.client_repository_service import ClientRepositoryService
|
|
|
|
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
|
|
|
from bot_data.service.server_repository_service import ServerRepositoryService
|
|
|
|
from bot_data.service.user_joined_server_repository_service import UserJoinedServerRepositoryService
|
|
|
|
from bot_data.service.user_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService
|
|
|
|
from bot_data.service.user_repository_service import UserRepositoryService
|
|
|
|
from modules.base.abc.base_helper_abc import BaseHelperABC
|
|
|
|
from modules.base.service.base_helper_service import BaseHelperService
|
|
|
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
|
|
|
from modules.permission.service.permission_service import PermissionService
|
2022-07-14 16:32:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Startup(StartupABC):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
StartupABC.__init__(self)
|
2022-10-02 12:14:44 +02:00
|
|
|
self._start_time = datetime.now()
|
|
|
|
|
2022-07-16 19:47:04 +02:00
|
|
|
self._config: Optional[ConfigurationABC] = None
|
2022-07-14 16:32:46 +02:00
|
|
|
|
2022-07-16 19:05:39 +02:00
|
|
|
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
2022-07-16 19:47:04 +02:00
|
|
|
self._config = configuration
|
2022-07-14 16:32:46 +02:00
|
|
|
return configuration
|
|
|
|
|
2022-07-16 19:05:39 +02:00
|
|
|
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
2022-07-16 19:47:04 +02:00
|
|
|
services.add_logging()
|
2022-10-02 12:14:44 +02:00
|
|
|
# custom logging
|
|
|
|
services.add_singleton(LoggerABC, CommandLogger)
|
2022-10-02 13:13:23 +02:00
|
|
|
services.add_singleton(LoggerABC, DatabaseLogger)
|
|
|
|
services.add_singleton(LoggerABC, MessageLogger)
|
2022-10-02 12:14:44 +02:00
|
|
|
|
2022-07-16 19:47:04 +02:00
|
|
|
services.add_translation()
|
2022-07-16 23:23:07 +02:00
|
|
|
|
|
|
|
services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings))
|
|
|
|
|
|
|
|
# general services
|
2022-10-02 12:14:44 +02:00
|
|
|
services.add_transient(BaseHelperABC, BaseHelperService)
|
2022-07-16 23:23:07 +02:00
|
|
|
services.add_transient(MessageServiceABC, MessageService)
|
|
|
|
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
|
|
|
|
|
2022-07-17 14:40:11 +02:00
|
|
|
# pipes
|
|
|
|
services.add_transient(DateTimeOffsetPipe)
|
|
|
|
|
2022-07-16 23:23:07 +02:00
|
|
|
# module services
|
2022-10-02 12:14:44 +02:00
|
|
|
services.add_singleton(PermissionServiceABC, PermissionService)
|
2022-07-16 23:23:07 +02:00
|
|
|
|
|
|
|
# data services
|
|
|
|
services.add_transient(ServerRepositoryABC, ServerRepositoryService)
|
|
|
|
services.add_transient(UserRepositoryABC, UserRepositoryService)
|
|
|
|
services.add_transient(ClientRepositoryABC, ClientRepositoryService)
|
|
|
|
services.add_transient(KnownUserRepositoryABC, KnownUserRepositoryService)
|
|
|
|
services.add_transient(UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService)
|
|
|
|
services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService)
|
2022-07-16 19:47:04 +02:00
|
|
|
|
2022-10-02 13:13:23 +02:00
|
|
|
provider = services.build_service_provider()
|
|
|
|
# instantiate custom logger
|
|
|
|
for c in CustomFileLoggerABC.__subclasses__():
|
|
|
|
i: LoggerABC = provider.get_service(c)
|
|
|
|
|
|
|
|
return provider
|