forked from sh-edraft.de/sh_discord_bot
Improved feature-flags & fixed logging
This commit is contained in:
parent
1c3ec3c7e7
commit
04e8e64003
@ -37,14 +37,6 @@
|
|||||||
"de"
|
"de"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"FeatureFlags": {
|
|
||||||
"AdminModule": true,
|
|
||||||
"BaseModule": true,
|
|
||||||
"BootLogModule": true,
|
|
||||||
"DatabaseModule": true,
|
|
||||||
"ModeratorModule": true,
|
|
||||||
"PermissionModule": true
|
|
||||||
},
|
|
||||||
"DiscordBot": {
|
"DiscordBot": {
|
||||||
"Token": "OTk4MTU5NjczODkzMDYwNzM4.GN3QyA.yvWO6L7Eu36gXQ7ARDs0Jg2J1VqIDnHLou5lT4",
|
"Token": "OTk4MTU5NjczODkzMDYwNzM4.GN3QyA.yvWO6L7Eu36gXQ7ARDs0Jg2J1VqIDnHLou5lT4",
|
||||||
"Prefix": "!kd "
|
"Prefix": "!kd "
|
||||||
|
@ -39,14 +39,6 @@
|
|||||||
"Token": "OTk4MTYwNDI3Njg5MTgxMjM3.GI7h67.BqD6Lu1Tz0MuG8iktYrcLnHi1pNozyMiWFGTKI",
|
"Token": "OTk4MTYwNDI3Njg5MTgxMjM3.GI7h67.BqD6Lu1Tz0MuG8iktYrcLnHi1pNozyMiWFGTKI",
|
||||||
"Prefix": "!ke "
|
"Prefix": "!ke "
|
||||||
},
|
},
|
||||||
"FeatureFlags": {
|
|
||||||
"AdminModule": true,
|
|
||||||
"BaseModule": true,
|
|
||||||
"BootLogModule": true,
|
|
||||||
"DatabaseModule": true,
|
|
||||||
"ModeratorModule": true,
|
|
||||||
"PermissionModule": true
|
|
||||||
},
|
|
||||||
"Bot": {
|
"Bot": {
|
||||||
"910199451145076828": {
|
"910199451145076828": {
|
||||||
"MessageDeleteTimer": 2
|
"MessageDeleteTimer": 2
|
||||||
|
@ -48,14 +48,6 @@
|
|||||||
"Buffered": "true",
|
"Buffered": "true",
|
||||||
"AuthPlugin": "mysql_native_password"
|
"AuthPlugin": "mysql_native_password"
|
||||||
},
|
},
|
||||||
"FeatureFlags": {
|
|
||||||
"AdminModule": true,
|
|
||||||
"BaseModule": true,
|
|
||||||
"BootLogModule": true,
|
|
||||||
"DatabaseModule": true,
|
|
||||||
"ModeratorModule": true,
|
|
||||||
"PermissionModule": true
|
|
||||||
},
|
|
||||||
"Bot": {
|
"Bot": {
|
||||||
"650366049023295514": {
|
"650366049023295514": {
|
||||||
"MessageDeleteTimer": 2
|
"MessageDeleteTimer": 2
|
||||||
|
@ -48,14 +48,6 @@
|
|||||||
"Buffered": "true",
|
"Buffered": "true",
|
||||||
"AuthPlugin": "mysql_native_password"
|
"AuthPlugin": "mysql_native_password"
|
||||||
},
|
},
|
||||||
"FeatureFlags": {
|
|
||||||
"AdminModule": true,
|
|
||||||
"BaseModule": true,
|
|
||||||
"BootLogModule": true,
|
|
||||||
"DatabaseModule": true,
|
|
||||||
"ModeratorModule": true,
|
|
||||||
"PermissionModule": true
|
|
||||||
},
|
|
||||||
"Bot": {
|
"Bot": {
|
||||||
"910199451145076828": {
|
"910199451145076828": {
|
||||||
"MessageDeleteTimer": 4
|
"MessageDeleteTimer": 4
|
||||||
|
13
src/bot/config/feature-flags.json
Normal file
13
src/bot/config/feature-flags.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"FeatureFlags": {
|
||||||
|
"AdminModule": true,
|
||||||
|
"BaseModule": true,
|
||||||
|
"BootLogModule": true,
|
||||||
|
"CoreModule": true,
|
||||||
|
"CoreExtensionModule": true,
|
||||||
|
"DatabaseModule": true,
|
||||||
|
"ModeratorModule": true,
|
||||||
|
"PermissionModule": true,
|
||||||
|
"PresenceModule": true
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import traceback
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from cpl_core.application import ApplicationBuilder
|
from cpl_core.application import ApplicationBuilder
|
||||||
@ -45,12 +46,12 @@ def main():
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
asyncio.run(program.stop())
|
asyncio.run(program.stop())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Console.error(f'[ ERROR ] [ {__name__} ]: Cannot start the bot', str(e))
|
Console.error(f'[ ERROR ] [ {__name__} ]: Cannot start the bot', f'{e} -> {traceback.format_exc()}')
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
asyncio.run(program.stop())
|
asyncio.run(program.stop())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Console.error(f'[ ERROR ] [ {__name__} ]: Cannot stop the bot', str(e))
|
Console.error(f'[ ERROR ] [ {__name__} ]: Cannot stop the bot', f'{e} -> {traceback.format_exc()}')
|
||||||
|
|
||||||
if program.app is not None and program.app.is_restart():
|
if program.app is not None and program.app.is_restart():
|
||||||
del program
|
del program
|
||||||
|
@ -4,9 +4,17 @@ from typing import Optional
|
|||||||
from cpl_core.application import StartupABC
|
from cpl_core.application import StartupABC
|
||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_core.database import DatabaseSettings
|
from cpl_core.database import DatabaseSettings
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||||
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from cpl_core.environment import ApplicationEnvironment
|
from cpl_core.environment import ApplicationEnvironment
|
||||||
|
from cpl_core.logging import LoggerABC
|
||||||
|
|
||||||
|
from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
|
from bot_core.logging.command_logger import CommandLogger
|
||||||
|
from bot_core.logging.database_logger import DatabaseLogger
|
||||||
|
from bot_core.logging.message_logger import MessageLogger
|
||||||
from bot_data.db_context import DBContext
|
from bot_data.db_context import DBContext
|
||||||
|
|
||||||
|
|
||||||
@ -17,15 +25,32 @@ class Startup(StartupABC):
|
|||||||
self._start_time = datetime.now()
|
self._start_time = datetime.now()
|
||||||
|
|
||||||
self._config: Optional[ConfigurationABC] = None
|
self._config: Optional[ConfigurationABC] = None
|
||||||
|
self._feature_flags: Optional[FeatureFlagsSettings] = None
|
||||||
|
|
||||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||||
self._config = configuration
|
self._config = configuration
|
||||||
|
self._feature_flags = configuration.get_configuration(FeatureFlagsSettings)
|
||||||
return configuration
|
return configuration
|
||||||
|
|
||||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||||
services.add_logging()
|
services.add_logging()
|
||||||
|
if self._feature_flags.get_flag(FeatureFlagsEnum.core_module):
|
||||||
|
# custom logging
|
||||||
|
services.add_singleton(CustomFileLoggerABC, CommandLogger)
|
||||||
|
services.add_singleton(CustomFileLoggerABC, DatabaseLogger)
|
||||||
|
services.add_singleton(CustomFileLoggerABC, MessageLogger)
|
||||||
|
|
||||||
services.add_translation()
|
services.add_translation()
|
||||||
services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings))
|
services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings))
|
||||||
|
|
||||||
return services.build_service_provider()
|
provider = services.build_service_provider()
|
||||||
|
# instantiate custom logger
|
||||||
|
for c in CustomFileLoggerABC.__subclasses__():
|
||||||
|
i: LoggerABC = provider.get_service(c)
|
||||||
|
|
||||||
|
|
||||||
|
logger: LoggerABC = provider.get_service(LoggerABC)
|
||||||
|
for flag in [f for f in FeatureFlagsEnum]:
|
||||||
|
logger.debug(__name__, f'Loaded feature-flag: {flag} = {self._feature_flags.get_flag(flag)}')
|
||||||
|
|
||||||
|
return provider
|
||||||
|
@ -29,7 +29,7 @@ class StartupModuleExtension(StartupExtensionABC):
|
|||||||
|
|
||||||
for module_type in self._modules:
|
for module_type in self._modules:
|
||||||
module = module_type(dc_collection)
|
module = module_type(dc_collection)
|
||||||
if not module.feature_flag(self._feature_flags):
|
if not self._feature_flags.get_flag(module.feature_flag):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||||
|
@ -6,12 +6,9 @@ from cpl_core.application import StartupExtensionABC
|
|||||||
from cpl_core.configuration import ConfigurationABC
|
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.logging import LoggerABC
|
|
||||||
|
|
||||||
from bot_core.configuration.bot_logging_settings import BotLoggingSettings
|
from bot_core.configuration.bot_logging_settings import BotLoggingSettings
|
||||||
from bot_core.configuration.bot_settings import BotSettings
|
from bot_core.configuration.bot_settings import BotSettings
|
||||||
from bot_core.logging.command_logger import CommandLogger
|
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
|
||||||
from modules.base.configuration.base_settings import BaseSettings
|
from modules.base.configuration.base_settings import BaseSettings
|
||||||
from modules.boot_log.configuration.boot_log_settings import BootLogSettings
|
from modules.boot_log.configuration.boot_log_settings import BootLogSettings
|
||||||
from modules.permission.configuration.permission_settings import PermissionSettings
|
from modules.permission.configuration.permission_settings import PermissionSettings
|
||||||
@ -31,6 +28,8 @@ class StartupSettingsExtension(StartupExtensionABC):
|
|||||||
configuration.add_json_file(f'config/appsettings.json', optional=False)
|
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.environment_name}.json', optional=True)
|
||||||
configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True)
|
configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True)
|
||||||
|
# load feature-flags
|
||||||
|
configuration.add_json_file(f'config/feature-flags.json', optional=False)
|
||||||
|
|
||||||
configuration.add_configuration('Startup_StartTime', str(self._start_time))
|
configuration.add_configuration('Startup_StartTime', str(self._start_time))
|
||||||
self._configure_settings_with_sub_settings(configuration, BotSettings, lambda x: x.servers, lambda x: x.id)
|
self._configure_settings_with_sub_settings(configuration, BotSettings, lambda x: x.servers, lambda x: x.id)
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from cpl_core.application import StartupExtensionABC
|
from cpl_core.application import StartupExtensionABC
|
||||||
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
||||||
|
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
|
||||||
|
|
||||||
class ModuleABC(StartupExtensionABC):
|
class ModuleABC(StartupExtensionABC):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self, dc: DiscordCollectionABC, feature_flag: Callable = None):
|
def __init__(self, dc: DiscordCollectionABC, feature_flag: FeatureFlagsEnum):
|
||||||
StartupExtensionABC.__init__(self)
|
StartupExtensionABC.__init__(self)
|
||||||
|
|
||||||
self._dc = dc
|
self._dc = dc
|
||||||
self._feature_flag = feature_flag
|
self._feature_flag = feature_flag
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def feature_flag(self) -> Callable:
|
def feature_flag(self) -> FeatureFlagsEnum:
|
||||||
return self._feature_flag
|
return self._feature_flag
|
||||||
|
17
src/bot_core/configuration/feature_flags_enum.py
Normal file
17
src/bot_core/configuration/feature_flags_enum.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class FeatureFlagsEnum(Enum):
|
||||||
|
|
||||||
|
# modules
|
||||||
|
admin_module = 'AdminModule'
|
||||||
|
base_module = 'BaseModule'
|
||||||
|
boot_log_module = 'BootLogModule'
|
||||||
|
core_module = 'CoreModule'
|
||||||
|
core_extension_module = 'CoreExtensionModule'
|
||||||
|
data_module = 'DataModule',
|
||||||
|
database_module = 'DatabaseModule',
|
||||||
|
moderator_module = 'ModeratorModule'
|
||||||
|
permission_module = 'PermissionModule'
|
||||||
|
# features
|
||||||
|
presence = 'Presence'
|
@ -1,65 +1,47 @@
|
|||||||
import traceback
|
import traceback
|
||||||
from typing import Optional
|
from typing import Optional, Callable
|
||||||
|
|
||||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||||
from cpl_core.console import Console
|
from cpl_core.console import Console
|
||||||
|
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
|
||||||
|
|
||||||
class FeatureFlagsSettings(ConfigurationModelABC):
|
class FeatureFlagsSettings(ConfigurationModelABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ConfigurationModelABC.__init__(self)
|
ConfigurationModelABC.__init__(self)
|
||||||
|
|
||||||
self._admin_module = False # 02.10.2022 #48
|
self._flags = {
|
||||||
self._base_module = True # 02.10.2022 #48
|
# modules
|
||||||
self._boot_log_module = True # 02.10.2022 #48
|
FeatureFlagsEnum.admin_module.value: False, # 02.10.2022 #48
|
||||||
self._database_module = True # 02.10.2022 #48
|
FeatureFlagsEnum.base_module.value: True, # 02.10.2022 #48
|
||||||
self._moderator_module = False # 02.10.2022 #48
|
FeatureFlagsEnum.boot_log_module.value: True, # 02.10.2022 #48
|
||||||
self._permission_module = True # 02.10.2022 #48
|
FeatureFlagsEnum.core_module.value: True, # 03.10.2022 #56
|
||||||
|
FeatureFlagsEnum.core_extension_module.value: True, # 03.10.2022 #56
|
||||||
|
FeatureFlagsEnum.data_module.value: True, # 03.10.2022 #56
|
||||||
|
FeatureFlagsEnum.database_module.value: True, # 02.10.2022 #48
|
||||||
|
FeatureFlagsEnum.moderator_module.value: False, # 02.10.2022 #48
|
||||||
|
FeatureFlagsEnum.permission_module.value: True, # 02.10.2022 #48
|
||||||
|
# features
|
||||||
|
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
def get_flag(self, key: FeatureFlagsEnum) -> bool:
|
||||||
def admin_module(self) -> bool:
|
if key.value not in self._flags:
|
||||||
return self._admin_module
|
return False
|
||||||
|
return self._flags[key.value]
|
||||||
|
|
||||||
@property
|
def _load_flag(self, settings: dict, key: FeatureFlagsEnum):
|
||||||
def base_module(self) -> bool:
|
if key.value not in settings:
|
||||||
return self._base_module
|
return
|
||||||
|
|
||||||
@property
|
self._flags[key.value] = bool(settings[key.value])
|
||||||
def boot_log_module(self) -> bool:
|
|
||||||
return self._boot_log_module
|
|
||||||
|
|
||||||
@property
|
|
||||||
def database_module(self) -> bool:
|
|
||||||
return self._database_module
|
|
||||||
|
|
||||||
@property
|
|
||||||
def moderator_module(self) -> bool:
|
|
||||||
return self._moderator_module
|
|
||||||
|
|
||||||
@property
|
|
||||||
def permission_module(self) -> bool:
|
|
||||||
return self._permission_module
|
|
||||||
|
|
||||||
def from_dict(self, settings: dict):
|
def from_dict(self, settings: dict):
|
||||||
try:
|
try:
|
||||||
if 'AdminModule' in settings:
|
for flag in [f.value for f in FeatureFlagsEnum]:
|
||||||
self._admin_module = settings['AdminModule']
|
self._load_flag(settings, FeatureFlagsEnum(flag))
|
||||||
|
|
||||||
if 'BaseModule' in settings:
|
|
||||||
self._base_module = settings['BaseModule']
|
|
||||||
|
|
||||||
if 'BootLogModule' in settings:
|
|
||||||
self._boot_log_module = settings['BootLogModule']
|
|
||||||
|
|
||||||
if 'DatabaseModule' in settings:
|
|
||||||
self._database_module = settings['DatabaseModule']
|
|
||||||
|
|
||||||
if 'ModeratorModule' in settings:
|
|
||||||
self._moderator_module = settings['ModeratorModule']
|
|
||||||
|
|
||||||
if 'PermissionModule' in settings:
|
|
||||||
self._permission_module = settings['PermissionModule']
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
|
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
|
||||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||||
|
@ -5,13 +5,14 @@ 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 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.core_extension.core_extension_on_ready_event import CoreExtensionOnReadyEvent
|
from bot_core.core_extension.core_extension_on_ready_event import CoreExtensionOnReadyEvent
|
||||||
|
|
||||||
|
|
||||||
class CoreExtensionModule(ModuleABC):
|
class CoreExtensionModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.base_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.core_extension_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
from cpl_core.configuration import ConfigurationABC
|
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.logging import LoggerABC
|
|
||||||
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
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 bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||||
from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC
|
|
||||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||||
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.events.core_on_ready_event import CoreOnReadyEvent
|
from bot_core.events.core_on_ready_event import CoreOnReadyEvent
|
||||||
from bot_core.logging.command_logger import CommandLogger
|
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
|
||||||
from bot_core.logging.message_logger import MessageLogger
|
|
||||||
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
|
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
|
||||||
from bot_core.service.client_utils_service import ClientUtilsService
|
from bot_core.service.client_utils_service import ClientUtilsService
|
||||||
from bot_core.service.message_service import MessageService
|
from bot_core.service.message_service import MessageService
|
||||||
@ -21,17 +17,12 @@ from bot_core.service.message_service import MessageService
|
|||||||
class CoreModule(ModuleABC):
|
class CoreModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.base_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.core_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||||
# custom logging
|
|
||||||
services.add_singleton(CustomFileLoggerABC, CommandLogger)
|
|
||||||
services.add_singleton(CustomFileLoggerABC, DatabaseLogger)
|
|
||||||
services.add_singleton(CustomFileLoggerABC, MessageLogger)
|
|
||||||
|
|
||||||
services.add_transient(MessageServiceABC, MessageService)
|
services.add_transient(MessageServiceABC, MessageService)
|
||||||
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
|
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
|
||||||
|
|
||||||
@ -39,8 +30,3 @@ class CoreModule(ModuleABC):
|
|||||||
services.add_transient(DateTimeOffsetPipe)
|
services.add_transient(DateTimeOffsetPipe)
|
||||||
|
|
||||||
self._dc.add_event(DiscordEventTypesEnum.on_ready.value, CoreOnReadyEvent)
|
self._dc.add_event(DiscordEventTypesEnum.on_ready.value, CoreOnReadyEvent)
|
||||||
|
|
||||||
provider = services.build_service_provider()
|
|
||||||
# instantiate custom logger
|
|
||||||
for c in CustomFileLoggerABC.__subclasses__():
|
|
||||||
i: LoggerABC = provider.get_service(c)
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
from cpl_core.logging import LoggerABC
|
from cpl_core.logging import LoggerABC
|
||||||
from cpl_discord.events import OnReadyABC
|
from cpl_discord.events import OnReadyABC
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
@ -15,7 +13,7 @@ class CoreOnReadyEvent(OnReadyABC):
|
|||||||
logger: LoggerABC,
|
logger: LoggerABC,
|
||||||
bot: DiscordBotServiceABC,
|
bot: DiscordBotServiceABC,
|
||||||
client_utils: ClientUtilsServiceABC,
|
client_utils: ClientUtilsServiceABC,
|
||||||
t: TranslatePipe
|
t: TranslatePipe,
|
||||||
):
|
):
|
||||||
OnReadyABC.__init__(self)
|
OnReadyABC.__init__(self)
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ from discord.ext.commands import Context
|
|||||||
|
|
||||||
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
|
||||||
@ -24,7 +26,8 @@ class ClientUtilsService(ClientUtilsServiceABC):
|
|||||||
clients: ClientRepositoryABC,
|
clients: ClientRepositoryABC,
|
||||||
message_service: MessageServiceABC,
|
message_service: MessageServiceABC,
|
||||||
db: DatabaseContextABC,
|
db: DatabaseContextABC,
|
||||||
t: TranslatePipe
|
t: TranslatePipe,
|
||||||
|
feature_flags: FeatureFlagsSettings
|
||||||
):
|
):
|
||||||
ClientUtilsServiceABC.__init__(self)
|
ClientUtilsServiceABC.__init__(self)
|
||||||
self._config = config
|
self._config = config
|
||||||
@ -35,6 +38,7 @@ class ClientUtilsService(ClientUtilsServiceABC):
|
|||||||
self._message_service = message_service
|
self._message_service = message_service
|
||||||
self._db = db
|
self._db = db
|
||||||
self._t = t
|
self._t = t
|
||||||
|
self._feature_flags = feature_flags
|
||||||
|
|
||||||
def received_command(self, guild_id: int):
|
def received_command(self, guild_id: int):
|
||||||
server = self._servers.get_server_by_discord_id(guild_id)
|
server = self._servers.get_server_by_discord_id(guild_id)
|
||||||
@ -64,6 +68,9 @@ class ClientUtilsService(ClientUtilsServiceABC):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
async def presence_game(self, t_key: str):
|
async def presence_game(self, t_key: str):
|
||||||
|
if not self._feature_flags.get_flag(FeatureFlagsEnum.presence):
|
||||||
|
return
|
||||||
|
|
||||||
import bot
|
import bot
|
||||||
name = self._t.transform(t_key).format(bot.__version__)
|
name = self._t.transform(t_key).format(bot.__version__)
|
||||||
await self._bot.change_presence(activity=discord.Game(name=name))
|
await self._bot.change_presence(activity=discord.Game(name=name))
|
||||||
|
@ -4,6 +4,7 @@ from cpl_core.environment import ApplicationEnvironmentABC
|
|||||||
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
||||||
|
|
||||||
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_data.abc.client_repository_abc import ClientRepositoryABC
|
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
@ -21,7 +22,7 @@ from bot_data.service.user_repository_service import UserRepositoryService
|
|||||||
class DataModule(ModuleABC):
|
class DataModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.base_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.data_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
@ -4,6 +4,7 @@ from cpl_core.environment import ApplicationEnvironmentABC
|
|||||||
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
||||||
|
|
||||||
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 modules.admin.command.restart_command import RestartCommand
|
from modules.admin.command.restart_command import RestartCommand
|
||||||
from modules.admin.command.shutdown_command import ShutdownCommand
|
from modules.admin.command.shutdown_command import ShutdownCommand
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ from modules.admin.command.shutdown_command import ShutdownCommand
|
|||||||
class AdminModule(ModuleABC):
|
class AdminModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.admin_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.admin_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
@ -5,6 +5,7 @@ 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 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 modules.base.abc.base_helper_abc import BaseHelperABC
|
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||||
from modules.base.command.afk_command import AFKCommand
|
from modules.base.command.afk_command import AFKCommand
|
||||||
from modules.base.command.help_command import HelpCommand
|
from modules.base.command.help_command import HelpCommand
|
||||||
@ -23,7 +24,7 @@ from modules.base.service.base_helper_service import BaseHelperService
|
|||||||
class BaseModule(ModuleABC):
|
class BaseModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.base_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.base_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
@ -5,6 +5,7 @@ from cpl_core.configuration import ConfigurationABC
|
|||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from cpl_core.logging import LoggerABC
|
from cpl_core.logging import LoggerABC
|
||||||
|
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
|
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ class BootLogExtension(ApplicationExtensionABC):
|
|||||||
|
|
||||||
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||||
feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings)
|
feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings)
|
||||||
if not feature_flags.boot_log_module:
|
if not feature_flags.get_flag(FeatureFlagsEnum.boot_log_module):
|
||||||
return
|
return
|
||||||
logger: LoggerABC = services.get_service(LoggerABC)
|
logger: LoggerABC = services.get_service(LoggerABC)
|
||||||
logger.debug(__name__, 'BootLog extension started')
|
logger.debug(__name__, 'BootLog extension started')
|
||||||
|
@ -5,13 +5,14 @@ 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 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 modules.boot_log.boot_log_on_ready_event import BootLogOnReadyEvent
|
from modules.boot_log.boot_log_on_ready_event import BootLogOnReadyEvent
|
||||||
|
|
||||||
|
|
||||||
class BootLogModule(ModuleABC):
|
class BootLogModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.boot_log_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.boot_log_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
@ -5,6 +5,7 @@ from cpl_core.configuration import ConfigurationABC
|
|||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from cpl_core.logging import LoggerABC
|
from cpl_core.logging import LoggerABC
|
||||||
|
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
from bot_core.logging.database_logger import DatabaseLogger
|
||||||
from bot_data.service.migration_service import MigrationService
|
from bot_data.service.migration_service import MigrationService
|
||||||
@ -17,7 +18,7 @@ class DatabaseExtension(ApplicationExtensionABC):
|
|||||||
|
|
||||||
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||||
feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings)
|
feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings)
|
||||||
if not feature_flags.database_module:
|
if not feature_flags.get_flag(FeatureFlagsEnum.data_module):
|
||||||
return
|
return
|
||||||
logger: LoggerABC = services.get_service(DatabaseLogger)
|
logger: LoggerABC = services.get_service(DatabaseLogger)
|
||||||
logger.debug(__name__, 'Database extension started')
|
logger.debug(__name__, 'Database extension started')
|
||||||
|
@ -5,13 +5,14 @@ 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 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 modules.database.database_on_ready_event import DatabaseOnReadyEvent
|
from modules.database.database_on_ready_event import DatabaseOnReadyEvent
|
||||||
|
|
||||||
|
|
||||||
class DatabaseModule(ModuleABC):
|
class DatabaseModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.database_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.database_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
@ -4,13 +4,14 @@ from cpl_core.environment import ApplicationEnvironmentABC
|
|||||||
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
||||||
|
|
||||||
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 modules.moderator.command.purge_command import PurgeCommand
|
from modules.moderator.command.purge_command import PurgeCommand
|
||||||
|
|
||||||
|
|
||||||
class ModeratorModule(ModuleABC):
|
class ModeratorModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.moderator_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.moderator_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
@ -5,6 +5,7 @@ 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 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 modules.permission.abc.permission_service_abc import PermissionServiceABC
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||||
from modules.permission.events.permission_on_member_update_event import PermissionOnMemberUpdateEvent
|
from modules.permission.events.permission_on_member_update_event import PermissionOnMemberUpdateEvent
|
||||||
from modules.permission.events.permission_on_ready_event import PermissionOnReadyEvent
|
from modules.permission.events.permission_on_ready_event import PermissionOnReadyEvent
|
||||||
@ -14,7 +15,7 @@ from modules.permission.service.permission_service import PermissionService
|
|||||||
class PermissionModule(ModuleABC):
|
class PermissionModule(ModuleABC):
|
||||||
|
|
||||||
def __init__(self, dc: DiscordCollectionABC):
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
ModuleABC.__init__(self, dc, lambda x: x.permission_module)
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.permission_module)
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user