2021-11-15 19:36:39 +01:00
|
|
|
from cpl_core.application import ApplicationABC
|
|
|
|
from cpl_core.configuration import ConfigurationABC
|
2021-11-17 19:35:42 +01:00
|
|
|
from cpl_core.console import Console
|
2021-11-15 19:36:39 +01:00
|
|
|
from cpl_core.dependency_injection import ServiceProviderABC
|
|
|
|
from cpl_core.logging import LoggerABC
|
|
|
|
from gismo_core.abc.bot_service_abc import BotServiceABC
|
2021-11-15 21:23:06 +01:00
|
|
|
from gismo_core.service.bot_service import BotService
|
2021-11-15 19:36:39 +01:00
|
|
|
|
|
|
|
|
2021-11-19 08:58:38 +01:00
|
|
|
class Gismo(ApplicationABC):
|
2021-11-15 00:52:49 +01:00
|
|
|
|
|
|
|
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
|
|
|
ApplicationABC.__init__(self, config, services)
|
|
|
|
|
2021-11-15 18:09:34 +01:00
|
|
|
self._bot: BotService = services.get_service(BotServiceABC)
|
|
|
|
self._logger: LoggerABC = services.get_service(LoggerABC)
|
|
|
|
|
2021-11-15 00:52:49 +01:00
|
|
|
async def configure(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def main(self):
|
2021-11-15 18:09:34 +01:00
|
|
|
try:
|
2021-11-16 11:41:34 +01:00
|
|
|
self._logger.trace(__name__, f'Try to start {BotService}')
|
2021-11-15 20:34:15 +01:00
|
|
|
await self._bot.start_async()
|
2021-11-15 18:09:34 +01:00
|
|
|
except Exception as e:
|
2021-11-15 20:34:15 +01:00
|
|
|
self._logger.error(__name__, 'Start failed', e)
|
2021-11-17 19:35:42 +01:00
|
|
|
|
|
|
|
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()
|