48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
from cpl_core.application import ApplicationABC
|
|
from cpl_core.configuration import ConfigurationABC
|
|
from cpl_core.console import Console
|
|
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):
|
|
|
|
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
|
ApplicationABC.__init__(self, config, services)
|
|
|
|
self._bot: BotService = services.get_service(BotServiceABC)
|
|
self._logger: LoggerABC = services.get_service(LoggerABC)
|
|
self._bot_settings: BotSettings = config.get_configuration(BotSettings)
|
|
|
|
async def configure(self):
|
|
self._logger.debug(__name__, 'Try to load discord server configs')
|
|
for server in self._bot_settings.servers:
|
|
server: ServerSettings = server
|
|
self._logger.trace(__name__, f'Try to load config for server: {server.id}')
|
|
self._configuration.add_configuration(f'DSERVER_{server.id}', server)
|
|
self._logger.trace(__name__, f'Loaded config for server: {server.id}')
|
|
|
|
async def main(self):
|
|
try:
|
|
self._logger.trace(__name__, f'Try to start {BotService}')
|
|
await self._bot.start_async()
|
|
except Exception as e:
|
|
self._logger.error(__name__, 'Start failed', e)
|
|
|
|
async def stop_async(self):
|
|
try:
|
|
self._logger.trace(__name__, f'Try to stop {BotService}')
|
|
await self._bot.close()
|
|
self._logger.trace(__name__, f'Stopped {BotService}')
|
|
except Exception as e:
|
|
self._logger.error(__name__, 'stop failed', e)
|
|
|
|
Console.write_line()
|