Added logic to load api after bot #70

This commit is contained in:
Sven Heidemann 2022-10-16 21:36:08 +02:00
parent f634ad552e
commit 90bfee23b4
6 changed files with 24 additions and 7 deletions

View File

@ -43,10 +43,9 @@ class Application(DiscordBotApplicationABC):
async def main(self): async def main(self):
try: try:
self._logger.debug(__name__, f'Starting...') self._logger.debug(__name__, f'Starting...')
if self._feature_flags.get_flag(FeatureFlagsEnum.api_module):
self._api.start()
if self._feature_flags.get_flag(FeatureFlagsEnum.api_only) and self._environment.environment_name == 'development': if self._feature_flags.get_flag(FeatureFlagsEnum.api_module) and self._feature_flags.get_flag(FeatureFlagsEnum.api_only) and self._environment.environment_name == 'development':
self._api.start()
self._api.join() self._api.join()
return return

View File

@ -21,13 +21,13 @@ class ModuleList:
return List(type, [ return List(type, [
CoreModule, # has to be first! CoreModule, # has to be first!
DataModule, DataModule,
ApiModule,
AdminModule, AdminModule,
AutoRoleModule, AutoRoleModule,
BaseModule, BaseModule,
DatabaseModule, DatabaseModule,
ModeratorModule, ModeratorModule,
PermissionModule, PermissionModule,
ApiModule,
# has to be last! # has to be last!
BootLogModule, BootLogModule,
CoreExtensionModule, CoreExtensionModule,

View File

@ -5,7 +5,7 @@ from cpl_core.database import TableABC
from bot_api.abc.dto_abc import DtoABC from bot_api.abc.dto_abc import DtoABC
class AuthUserTransformerABC: class TransformerABC:
@staticmethod @staticmethod
@abstractmethod @abstractmethod

View File

@ -4,6 +4,7 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceCollectionABC from cpl_core.dependency_injection import ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.mailing import EMailClientABC, EMailClient from cpl_core.mailing import EMailClientABC, EMailClient
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
from flask import Flask from flask import Flask
@ -12,6 +13,7 @@ from bot_api.api import Api
from bot_api.api_thread import ApiThread from bot_api.api_thread import ApiThread
from bot_api.controller.gui_controller import GuiController from bot_api.controller.gui_controller import GuiController
from bot_api.controller.auth_controller import AuthController from bot_api.controller.auth_controller import AuthController
from bot_api.event.bot_api_on_ready_event import BotApiOnReadyEvent
from bot_api.service.auth_service import AuthService from bot_api.service.auth_service import AuthService
from bot_core.abc.module_abc import ModuleABC from bot_core.abc.module_abc import ModuleABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
@ -39,3 +41,6 @@ class ApiModule(ModuleABC):
services.add_transient(AuthServiceABC, AuthService) services.add_transient(AuthServiceABC, AuthService)
services.add_transient(AuthController) services.add_transient(AuthController)
services.add_transient(GuiController) services.add_transient(GuiController)
# cpl-discord
self._dc.add_event(DiscordEventTypesEnum.on_ready.value, BotApiOnReadyEvent)

View File

@ -0,0 +1,13 @@
from cpl_discord.events import OnReadyABC
from bot_api.api_thread import ApiThread
class BotApiOnReadyEvent(OnReadyABC):
def __init__(self, api: ApiThread):
OnReadyABC.__init__(self)
self._api = api
async def on_ready(self):
self._api.start()

View File

@ -1,12 +1,12 @@
from datetime import datetime, timezone from datetime import datetime, timezone
from bot_api.abc.auth_user_transformer_abc import AuthUserTransformerABC from bot_api.abc.transformer_abc import TransformerABC
from bot_api.model.auth_user_dto import AuthUserDTO from bot_api.model.auth_user_dto import AuthUserDTO
from bot_data.model.auth_role_enum import AuthRoleEnum from bot_data.model.auth_role_enum import AuthRoleEnum
from bot_data.model.auth_user import AuthUser from bot_data.model.auth_user import AuthUser
class AuthUserTransformer(AuthUserTransformerABC): class AuthUserTransformer(TransformerABC):
@staticmethod @staticmethod
def to_db(dto: AuthUser) -> AuthUser: def to_db(dto: AuthUser) -> AuthUser: