Added support to set cached max_message by config #178
This commit is contained in:
parent
2a0e3d77b7
commit
3811cf7d74
@ -44,7 +44,8 @@ class Application(DiscordBotApplicationABC):
|
|||||||
try:
|
try:
|
||||||
self._logger.debug(__name__, f'Starting...')
|
self._logger.debug(__name__, f'Starting...')
|
||||||
|
|
||||||
if self._feature_flags.get_flag(FeatureFlagsEnum.api_module) and 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.start()
|
||||||
self._api.join()
|
self._api.join()
|
||||||
return
|
return
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
"LicenseName": "MIT",
|
"LicenseName": "MIT",
|
||||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core==2022.12.0",
|
"cpl-core==2022.12.1.post2",
|
||||||
"cpl-translation==2022.10.0.post2",
|
"cpl-translation==2022.12.1",
|
||||||
"cpl-query==2022.12.2",
|
"cpl-query==2022.12.2.post1",
|
||||||
"cpl-discord==2022.12.0",
|
"cpl-discord==2022.12.1.post1",
|
||||||
"Flask==2.2.2",
|
"Flask==2.2.2",
|
||||||
"Flask-Classful==0.14.2",
|
"Flask-Classful==0.14.2",
|
||||||
"Flask-Cors==3.0.10",
|
"Flask-Cors==3.0.10",
|
||||||
@ -31,7 +31,7 @@
|
|||||||
"icmplib==3.0.3"
|
"icmplib==3.0.3"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli==2022.12.0"
|
"cpl-cli==2022.12.1.post2"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {},
|
"PythonPath": {},
|
||||||
|
0
kdb-bot/src/bot/extension/__init__.py
Normal file
0
kdb-bot/src/bot/extension/__init__.py
Normal file
20
kdb-bot/src/bot/extension/init_bot_extension.py
Normal file
20
kdb-bot/src/bot/extension/init_bot_extension.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from cpl_core.application import ApplicationExtensionABC
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
|
from bot_core.configuration.bot_settings import BotSettings
|
||||||
|
|
||||||
|
|
||||||
|
class InitBotExtension(ApplicationExtensionABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
ApplicationExtensionABC.__init__(self)
|
||||||
|
|
||||||
|
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||||
|
settings = config.get_configuration(BotSettings)
|
||||||
|
|
||||||
|
bot: DiscordBotServiceABC = services.get_service(
|
||||||
|
DiscordBotServiceABC,
|
||||||
|
max_messages=settings.cache_max_messages
|
||||||
|
)
|
@ -6,6 +6,7 @@ from cpl_core.application import ApplicationBuilder
|
|||||||
from cpl_core.console import Console
|
from cpl_core.console import Console
|
||||||
|
|
||||||
from bot.application import Application
|
from bot.application import Application
|
||||||
|
from bot.extension.init_bot_extension import InitBotExtension
|
||||||
from bot.startup import Startup
|
from bot.startup import Startup
|
||||||
from bot.startup_discord_extension import StartupDiscordExtension
|
from bot.startup_discord_extension import StartupDiscordExtension
|
||||||
from bot.startup_migration_extension import StartupMigrationExtension
|
from bot.startup_migration_extension import StartupMigrationExtension
|
||||||
@ -29,6 +30,7 @@ class Program:
|
|||||||
.use_extension(StartupDiscordExtension) \
|
.use_extension(StartupDiscordExtension) \
|
||||||
.use_extension(StartupModuleExtension) \
|
.use_extension(StartupModuleExtension) \
|
||||||
.use_extension(StartupMigrationExtension) \
|
.use_extension(StartupMigrationExtension) \
|
||||||
|
.use_extension(InitBotExtension) \
|
||||||
.use_extension(BootLogExtension) \
|
.use_extension(BootLogExtension) \
|
||||||
.use_extension(DatabaseExtension) \
|
.use_extension(DatabaseExtension) \
|
||||||
.use_extension(AppApiExtension) \
|
.use_extension(AppApiExtension) \
|
||||||
|
@ -16,6 +16,7 @@ class BotSettings(ConfigurationModelABC):
|
|||||||
self._technicians: List[int] = List(int)
|
self._technicians: List[int] = List(int)
|
||||||
self._wait_for_restart = 2
|
self._wait_for_restart = 2
|
||||||
self._wait_for_shutdown = 2
|
self._wait_for_shutdown = 2
|
||||||
|
self._cache_max_messages = 1000
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def servers(self) -> List[ServerSettings]:
|
def servers(self) -> List[ServerSettings]:
|
||||||
@ -33,6 +34,10 @@ class BotSettings(ConfigurationModelABC):
|
|||||||
def wait_for_shutdown(self) -> int:
|
def wait_for_shutdown(self) -> int:
|
||||||
return self._wait_for_shutdown
|
return self._wait_for_shutdown
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cache_max_messages(self) -> int:
|
||||||
|
return self._cache_max_messages
|
||||||
|
|
||||||
def from_dict(self, settings: dict):
|
def from_dict(self, settings: dict):
|
||||||
try:
|
try:
|
||||||
self._technicians = settings["Technicians"]
|
self._technicians = settings["Technicians"]
|
||||||
@ -41,6 +46,11 @@ class BotSettings(ConfigurationModelABC):
|
|||||||
settings.pop("Technicians")
|
settings.pop("Technicians")
|
||||||
settings.pop("WaitForRestart")
|
settings.pop("WaitForRestart")
|
||||||
settings.pop("WaitForShutdown")
|
settings.pop("WaitForShutdown")
|
||||||
|
|
||||||
|
if 'CacheMaxMessages' in settings:
|
||||||
|
self._cache_max_messages = settings["CacheMaxMessages"]
|
||||||
|
settings.pop("CacheMaxMessages")
|
||||||
|
|
||||||
servers = List(ServerSettings)
|
servers = List(ServerSettings)
|
||||||
for s in settings:
|
for s in settings:
|
||||||
st = ServerSettings()
|
st = ServerSettings()
|
||||||
|
Loading…
Reference in New Issue
Block a user