sh_discord_bot/src/bot/startup.py

41 lines
1.6 KiB
Python
Raw Normal View History

2022-07-16 19:47:04 +02:00
import os
from datetime import datetime
from typing import Optional
2022-07-14 16:32:46 +02:00
from cpl_core.application import StartupABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironment
2022-07-16 19:47:04 +02:00
from cpl_discord import get_discord_collection
2022-07-14 16:32:46 +02:00
class Startup(StartupABC):
def __init__(self):
StartupABC.__init__(self)
2022-07-16 19:47:04 +02:00
self._start_time = datetime.now()
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
environment.set_working_directory(os.path.dirname(os.path.realpath(__file__)))
configuration.add_environment_variables('KDB_')
configuration.add_environment_variables('DISCORD_')
configuration.add_json_file(f'config/appsettings.json', optional=False)
configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True)
configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True)
configuration.add_configuration('Startup_StartTime', str(self._start_time))
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()
services.add_translation()
services.add_discord()
discord_collection = get_discord_collection(services)
2022-07-14 16:32:46 +02:00
return services.build_service_provider()