Compare commits
No commits in common. "59f1183a50d32ab1074d64e05274e750a7fa7a55" and "efbe6efc20e9e7661d5c92e764bd571e392e18c2" have entirely different histories.
59f1183a50
...
efbe6efc20
@ -10,6 +10,7 @@
|
|||||||
"auto-role": "src/modules/auto_role/auto-role.json",
|
"auto-role": "src/modules/auto_role/auto-role.json",
|
||||||
"base": "src/modules/base/base.json",
|
"base": "src/modules/base/base.json",
|
||||||
"boot-log": "src/modules/boot_log/boot-log.json",
|
"boot-log": "src/modules/boot_log/boot-log.json",
|
||||||
|
"database": "src/modules/database/database.json",
|
||||||
"level": "src/modules/level/level.json",
|
"level": "src/modules/level/level.json",
|
||||||
"permission": "src/modules/permission/permission.json",
|
"permission": "src/modules/permission/permission.json",
|
||||||
"stats": "src/modules/stats/stats.json",
|
"stats": "src/modules/stats/stats.json",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "0",
|
"Major": "0",
|
||||||
"Minor": "3",
|
"Minor": "3",
|
||||||
"Micro": "dev127"
|
"Micro": "1"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
@ -32,8 +32,7 @@
|
|||||||
"cpl-discord==2022.12.2"
|
"cpl-discord==2022.12.2"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli==2022.12.1.post3",
|
"cpl-cli==2022.12.1.post3"
|
||||||
"pygount==1.5.1"
|
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {},
|
"PythonPath": {},
|
||||||
@ -61,6 +60,7 @@
|
|||||||
"../modules/auto_role/auto-role.json",
|
"../modules/auto_role/auto-role.json",
|
||||||
"../modules/base/base.json",
|
"../modules/base/base.json",
|
||||||
"../modules/boot_log/boot-log.json",
|
"../modules/boot_log/boot-log.json",
|
||||||
|
"../modules/database/database.json",
|
||||||
"../modules/level/level.json",
|
"../modules/level/level.json",
|
||||||
"../modules/permission/permission.json",
|
"../modules/permission/permission.json",
|
||||||
"../modules/stats/stats.json",
|
"../modules/stats/stats.json",
|
||||||
|
@ -3,7 +3,7 @@ from cpl_core.configuration import ConfigurationABC
|
|||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
from bot_core.configuration.bot_startup_settings import BotStartupSettings
|
from bot_core.configuration.bot_settings import BotSettings
|
||||||
|
|
||||||
|
|
||||||
class InitBotExtension(ApplicationExtensionABC):
|
class InitBotExtension(ApplicationExtensionABC):
|
||||||
@ -11,6 +11,6 @@ class InitBotExtension(ApplicationExtensionABC):
|
|||||||
ApplicationExtensionABC.__init__(self)
|
ApplicationExtensionABC.__init__(self)
|
||||||
|
|
||||||
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||||
settings: BotStartupSettings = config.get_configuration(BotStartupSettings)
|
settings = config.get_configuration(BotSettings)
|
||||||
|
|
||||||
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC, max_messages=settings.cache_max_messages)
|
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC, max_messages=settings.cache_max_messages)
|
||||||
|
@ -14,8 +14,8 @@ from bot.startup_module_extension import StartupModuleExtension
|
|||||||
from bot.startup_settings_extension import StartupSettingsExtension
|
from bot.startup_settings_extension import StartupSettingsExtension
|
||||||
from bot_api.app_api_extension import AppApiExtension
|
from bot_api.app_api_extension import AppApiExtension
|
||||||
from bot_core.core_extension.core_extension import CoreExtension
|
from bot_core.core_extension.core_extension import CoreExtension
|
||||||
from bot_data.data_extension.database_extension import DatabaseExtension
|
|
||||||
from modules.boot_log.boot_log_extension import BootLogExtension
|
from modules.boot_log.boot_log_extension import BootLogExtension
|
||||||
|
from modules.database.database_extension import DatabaseExtension
|
||||||
|
|
||||||
|
|
||||||
class Program:
|
class Program:
|
||||||
|
@ -8,6 +8,7 @@ from bot_graphql.graphql_module import GraphQLModule
|
|||||||
from modules.auto_role.auto_role_module import AutoRoleModule
|
from modules.auto_role.auto_role_module import AutoRoleModule
|
||||||
from modules.base.base_module import BaseModule
|
from modules.base.base_module import BaseModule
|
||||||
from modules.boot_log.boot_log_module import BootLogModule
|
from modules.boot_log.boot_log_module import BootLogModule
|
||||||
|
from modules.database.database_module import DatabaseModule
|
||||||
from modules.level.level_module import LevelModule
|
from modules.level.level_module import LevelModule
|
||||||
from modules.permission.permission_module import PermissionModule
|
from modules.permission.permission_module import PermissionModule
|
||||||
from modules.stats.stats_module import StatsModule
|
from modules.stats.stats_module import StatsModule
|
||||||
@ -25,6 +26,7 @@ class ModuleList:
|
|||||||
DataModule,
|
DataModule,
|
||||||
GraphQLModule,
|
GraphQLModule,
|
||||||
PermissionModule,
|
PermissionModule,
|
||||||
|
DatabaseModule,
|
||||||
AutoRoleModule,
|
AutoRoleModule,
|
||||||
BaseModule,
|
BaseModule,
|
||||||
LevelModule,
|
LevelModule,
|
||||||
|
@ -8,7 +8,6 @@ from bot_data.migration.api_key_migration import ApiKeyMigration
|
|||||||
from bot_data.migration.api_migration import ApiMigration
|
from bot_data.migration.api_migration import ApiMigration
|
||||||
from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration
|
from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration
|
||||||
from bot_data.migration.auto_role_migration import AutoRoleMigration
|
from bot_data.migration.auto_role_migration import AutoRoleMigration
|
||||||
from bot_data.migration.config_migration import ConfigMigration
|
|
||||||
from bot_data.migration.initial_migration import InitialMigration
|
from bot_data.migration.initial_migration import InitialMigration
|
||||||
from bot_data.migration.level_migration import LevelMigration
|
from bot_data.migration.level_migration import LevelMigration
|
||||||
from bot_data.migration.stats_migration import StatsMigration
|
from bot_data.migration.stats_migration import StatsMigration
|
||||||
@ -37,4 +36,3 @@ class StartupMigrationExtension(StartupExtensionABC):
|
|||||||
services.add_transient(MigrationABC, UserMessageCountPerHourMigration) # 11.01.2023 #168 - 0.3.1
|
services.add_transient(MigrationABC, UserMessageCountPerHourMigration) # 11.01.2023 #168 - 0.3.1
|
||||||
services.add_transient(MigrationABC, ApiKeyMigration) # 09.02.2023 #162 - 1.0.0
|
services.add_transient(MigrationABC, ApiKeyMigration) # 09.02.2023 #162 - 1.0.0
|
||||||
services.add_transient(MigrationABC, UserJoinedGameServerMigration) # 12.02.2023 #181 - 1.0.0
|
services.add_transient(MigrationABC, UserJoinedGameServerMigration) # 12.02.2023 #181 - 1.0.0
|
||||||
services.add_transient(MigrationABC, ConfigMigration) # 18.02.2023 #127 - 1.0.0
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Callable, Type, Optional
|
||||||
|
|
||||||
from cpl_core.application import StartupExtensionABC
|
from cpl_core.application import StartupExtensionABC
|
||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
@ -7,7 +8,11 @@ from cpl_core.dependency_injection import ServiceCollectionABC
|
|||||||
from cpl_core.environment import ApplicationEnvironmentABC
|
from cpl_core.environment import ApplicationEnvironmentABC
|
||||||
|
|
||||||
from bot_core.configuration.bot_logging_settings import BotLoggingSettings
|
from bot_core.configuration.bot_logging_settings import BotLoggingSettings
|
||||||
from bot_core.helper.settings_helper import SettingsHelper
|
from bot_core.configuration.bot_settings import BotSettings
|
||||||
|
from modules.base.configuration.base_settings import BaseSettings
|
||||||
|
from modules.boot_log.configuration.boot_log_settings import BootLogSettings
|
||||||
|
from modules.level.configuration.level_settings import LevelSettings
|
||||||
|
from modules.permission.configuration.permission_settings import PermissionSettings
|
||||||
|
|
||||||
|
|
||||||
class StartupSettingsExtension(StartupExtensionABC):
|
class StartupSettingsExtension(StartupExtensionABC):
|
||||||
@ -29,9 +34,27 @@ class StartupSettingsExtension(StartupExtensionABC):
|
|||||||
configuration.add_json_file(f"config/feature-flags.{environment.host_name}.json", optional=True)
|
configuration.add_json_file(f"config/feature-flags.{environment.host_name}.json", optional=True)
|
||||||
|
|
||||||
configuration.add_configuration("Startup_StartTime", str(self._start_time))
|
configuration.add_configuration("Startup_StartTime", str(self._start_time))
|
||||||
SettingsHelper.configure_settings_with_sub_settings(
|
self._configure_settings_with_sub_settings(configuration, BotSettings, lambda x: x.servers, lambda x: x.id)
|
||||||
|
self._configure_settings_with_sub_settings(configuration, BaseSettings, lambda x: x.servers, lambda x: x.id)
|
||||||
|
self._configure_settings_with_sub_settings(configuration, BootLogSettings, lambda x: x.servers, lambda x: x.id)
|
||||||
|
self._configure_settings_with_sub_settings(configuration, LevelSettings, lambda x: x.servers, lambda x: x.id)
|
||||||
|
self._configure_settings_with_sub_settings(
|
||||||
|
configuration, PermissionSettings, lambda x: x.servers, lambda x: x.id
|
||||||
|
)
|
||||||
|
self._configure_settings_with_sub_settings(
|
||||||
configuration, BotLoggingSettings, lambda x: x.files, lambda x: x.key
|
configuration, BotLoggingSettings, lambda x: x.files, lambda x: x.key
|
||||||
)
|
)
|
||||||
|
|
||||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _configure_settings_with_sub_settings(
|
||||||
|
config: ConfigurationABC, settings: Type, list_atr: Callable, atr: Callable
|
||||||
|
):
|
||||||
|
settings: Optional[settings] = config.get_configuration(settings)
|
||||||
|
if settings is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
for sub_settings in list_atr(settings):
|
||||||
|
config.add_configuration(f"{type(sub_settings).__name__}_{atr(sub_settings)}", sub_settings)
|
||||||
|
@ -12,13 +12,19 @@ class BotSettings(ConfigurationModelABC):
|
|||||||
ConfigurationModelABC.__init__(self)
|
ConfigurationModelABC.__init__(self)
|
||||||
|
|
||||||
self._servers: List[ServerSettings] = List(ServerSettings)
|
self._servers: List[ServerSettings] = List(ServerSettings)
|
||||||
|
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]:
|
||||||
return self._servers
|
return self._servers
|
||||||
|
|
||||||
|
@property
|
||||||
|
def technicians(self) -> List[int]:
|
||||||
|
return self._technicians
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait_for_restart(self) -> int:
|
def wait_for_restart(self) -> int:
|
||||||
return self._wait_for_restart
|
return self._wait_for_restart
|
||||||
@ -27,13 +33,23 @@ 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._wait_for_restart = settings["WaitForRestart"]
|
self._wait_for_restart = settings["WaitForRestart"]
|
||||||
self._wait_for_shutdown = settings["WaitForShutdown"]
|
self._wait_for_shutdown = settings["WaitForShutdown"]
|
||||||
|
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()
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
import traceback
|
|
||||||
|
|
||||||
from cpl_core.configuration import ConfigurationModelABC
|
|
||||||
from cpl_core.console import Console
|
|
||||||
from cpl_query.extension import List
|
|
||||||
|
|
||||||
|
|
||||||
class BotStartupSettings(ConfigurationModelABC):
|
|
||||||
def __init__(self):
|
|
||||||
ConfigurationModelABC.__init__(self)
|
|
||||||
|
|
||||||
self._cache_max_messages = 1000
|
|
||||||
self._technicians: List[int] = List(int)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def cache_max_messages(self) -> int:
|
|
||||||
return self._cache_max_messages
|
|
||||||
|
|
||||||
@property
|
|
||||||
def technicians(self) -> List[int]:
|
|
||||||
return self._technicians
|
|
||||||
|
|
||||||
def from_dict(self, settings: dict):
|
|
||||||
try:
|
|
||||||
self._cache_max_messages = int(settings["CacheMaxMessages"])
|
|
||||||
self._technicians = settings["Technicians"]
|
|
||||||
except Exception as e:
|
|
||||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
|
|
||||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
|
@ -1,17 +0,0 @@
|
|||||||
from typing import Type, Callable, Optional
|
|
||||||
|
|
||||||
from cpl_core.configuration import ConfigurationABC
|
|
||||||
from cpl_core.type import T
|
|
||||||
|
|
||||||
|
|
||||||
class SettingsHelper:
|
|
||||||
@staticmethod
|
|
||||||
def configure_settings_with_sub_settings(
|
|
||||||
config: ConfigurationABC, settings: Type[T], list_atr: Callable, atr: Callable
|
|
||||||
):
|
|
||||||
settings: Optional[settings] = config.get_configuration(settings)
|
|
||||||
if settings is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
for sub_settings in list_atr(settings):
|
|
||||||
config.add_configuration(f"{type(sub_settings).__name__}_{atr(sub_settings)}", sub_settings)
|
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "0",
|
"Major": "0",
|
||||||
"Minor": "3",
|
"Minor": "3",
|
||||||
"Micro": "dev127"
|
"Micro": "1"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
from cpl_core.configuration import ConfigurationABC
|
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
|
||||||
|
|
||||||
from bot_core.configuration.bot_settings import BotSettings
|
|
||||||
from bot_core.helper.settings_helper import SettingsHelper
|
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
|
||||||
from bot_data.abc.data_seeder_abc import DataSeederABC
|
|
||||||
from bot_data.service.db_config import DBConfigService
|
|
||||||
from bot_data.service.seeder_service import SeederService
|
|
||||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
|
||||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
|
||||||
from modules.base.configuration.base_settings import BaseSettings
|
|
||||||
from modules.boot_log.configuration.boot_log_settings import BootLogSettings
|
|
||||||
from modules.level.configuration.level_settings import LevelSettings
|
|
||||||
from modules.permission.configuration.permission_settings import PermissionSettings
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigSeeder(DataSeederABC):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
config: ConfigurationABC,
|
|
||||||
logger: DatabaseLogger,
|
|
||||||
seeder: SeederService,
|
|
||||||
bot: DiscordBotServiceABC,
|
|
||||||
db_context: DatabaseContextABC,
|
|
||||||
db_config: DBConfigService,
|
|
||||||
base_helper: BaseHelperABC,
|
|
||||||
):
|
|
||||||
DataSeederABC.__init__(self)
|
|
||||||
self._config = config
|
|
||||||
|
|
||||||
self._logger = logger
|
|
||||||
self._seeder = seeder
|
|
||||||
self._bot = bot
|
|
||||||
self._db_context = db_context
|
|
||||||
self._db_config = db_config
|
|
||||||
self._base_helper = base_helper
|
|
||||||
|
|
||||||
async def seed(self):
|
|
||||||
self._logger.debug(__name__, f"Load config from database")
|
|
||||||
try:
|
|
||||||
cfg = self._db_config.get_st_bot()
|
|
||||||
|
|
||||||
bot_settings = BotSettings()
|
|
||||||
bot_settings.from_dict(cfg)
|
|
||||||
|
|
||||||
base_settings = BaseSettings()
|
|
||||||
base_settings.from_dict(cfg)
|
|
||||||
|
|
||||||
boot_log_settings = BootLogSettings()
|
|
||||||
boot_log_settings.from_dict(cfg)
|
|
||||||
|
|
||||||
level_settings = LevelSettings()
|
|
||||||
level_settings.from_dict(cfg)
|
|
||||||
|
|
||||||
permission_settings = PermissionSettings()
|
|
||||||
permission_settings.from_dict(cfg)
|
|
||||||
|
|
||||||
SettingsHelper.configure_settings_with_sub_settings(
|
|
||||||
self._config, BotSettings, lambda x: x.servers, lambda x: x.id
|
|
||||||
)
|
|
||||||
SettingsHelper.configure_settings_with_sub_settings(
|
|
||||||
self._config, BaseSettings, lambda x: x.servers, lambda x: x.id
|
|
||||||
)
|
|
||||||
SettingsHelper.configure_settings_with_sub_settings(
|
|
||||||
self._config, BootLogSettings, lambda x: x.servers, lambda x: x.id
|
|
||||||
)
|
|
||||||
SettingsHelper.configure_settings_with_sub_settings(
|
|
||||||
self._config, LevelSettings, lambda x: x.servers, lambda x: x.id
|
|
||||||
)
|
|
||||||
SettingsHelper.configure_settings_with_sub_settings(
|
|
||||||
self._config, PermissionSettings, lambda x: x.servers, lambda x: x.id
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
self._logger.fatal(__name__, "Cannot load config from db", e)
|
|
||||||
|
|
||||||
try:
|
|
||||||
for guild in self._bot.guilds:
|
|
||||||
settings: BaseServerSettings = self._base_helper.get_config(guild.id)
|
|
||||||
if settings is None:
|
|
||||||
self._db_config.create_config_for_guild(guild.id)
|
|
||||||
except Exception as e:
|
|
||||||
self._logger.fatal(__name__, "Cannot load or create guild config from db", e)
|
|
||||||
|
|
||||||
self._logger.info(__name__, f"Loaded config from database")
|
|
@ -1,26 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
bot Keksdose bot
|
|
||||||
~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Discord bot for the Keksdose discord Server
|
|
||||||
|
|
||||||
:copyright: (c) 2022 - 2023 sh-edraft.de
|
|
||||||
:license: MIT, see LICENSE for more details.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
__title__ = "bot_data.data_extension"
|
|
||||||
__author__ = "Sven Heidemann"
|
|
||||||
__license__ = "MIT"
|
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
|
||||||
__version__ = "0.3.dev127"
|
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
|
|
||||||
|
|
||||||
# imports:
|
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
|
||||||
version_info = VersionInfo(major="0", minor="3", micro="dev127")
|
|
@ -1,7 +1,6 @@
|
|||||||
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_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
|
||||||
@ -10,7 +9,6 @@ from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
|||||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||||
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||||
from bot_data.abc.data_seeder_abc import DataSeederABC
|
|
||||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
@ -24,13 +22,10 @@ from bot_data.abc.user_message_count_per_hour_repository_abc import (
|
|||||||
UserMessageCountPerHourRepositoryABC,
|
UserMessageCountPerHourRepositoryABC,
|
||||||
)
|
)
|
||||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
from bot_data.config_seeder import ConfigSeeder
|
|
||||||
from bot_data.events.database_on_ready_event import DatabaseOnReadyEvent
|
|
||||||
from bot_data.service.api_key_repository_service import ApiKeyRepositoryService
|
from bot_data.service.api_key_repository_service import ApiKeyRepositoryService
|
||||||
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
||||||
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||||
from bot_data.service.client_repository_service import ClientRepositoryService
|
from bot_data.service.client_repository_service import ClientRepositoryService
|
||||||
from bot_data.service.db_config import DBConfigService
|
|
||||||
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
||||||
from bot_data.service.level_repository_service import LevelRepositoryService
|
from bot_data.service.level_repository_service import LevelRepositoryService
|
||||||
from bot_data.service.seeder_service import SeederService
|
from bot_data.service.seeder_service import SeederService
|
||||||
@ -74,8 +69,4 @@ class DataModule(ModuleABC):
|
|||||||
UserMessageCountPerHourRepositoryService,
|
UserMessageCountPerHourRepositoryService,
|
||||||
)
|
)
|
||||||
|
|
||||||
services.add_transient(DBConfigService)
|
|
||||||
services.add_transient(DataSeederABC, ConfigSeeder)
|
|
||||||
services.add_transient(SeederService)
|
services.add_transient(SeederService)
|
||||||
|
|
||||||
self._dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent)
|
|
||||||
|
@ -1,119 +0,0 @@
|
|||||||
from bot_core.logging.database_logger import DatabaseLogger
|
|
||||||
from bot_data.abc.migration_abc import MigrationABC
|
|
||||||
from bot_data.db_context import DBContext
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigMigration(MigrationABC):
|
|
||||||
name = "1.0_ConfigMigration"
|
|
||||||
|
|
||||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
|
||||||
MigrationABC.__init__(self)
|
|
||||||
self._logger = logger
|
|
||||||
self._db = db
|
|
||||||
self._cursor = db.cursor
|
|
||||||
|
|
||||||
def upgrade(self):
|
|
||||||
self._logger.debug(__name__, "Running upgrade")
|
|
||||||
|
|
||||||
self._cursor.execute(
|
|
||||||
f"""
|
|
||||||
CREATE TABLE IF NOT EXISTS `ST_Bot` (
|
|
||||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
|
||||||
`WaitForRestart` BIGINT NOT NULL DEFAULT 8,
|
|
||||||
`WaitForShutdown` BIGINT NOT NULL DEFAULT 8,
|
|
||||||
PRIMARY KEY(`Id`)
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
self._cursor.execute(
|
|
||||||
f"""
|
|
||||||
CREATE TABLE IF NOT EXISTS `ST_Servers` (
|
|
||||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
|
||||||
`ServerId` BIGINT NOT NULL,
|
|
||||||
`MessageDeleteTimer` BIGINT NOT NULL DEFAULT 4,
|
|
||||||
-- base
|
|
||||||
`MaxVoiceStateHours` BIGINT NOT NULL DEFAULT 6,
|
|
||||||
`XpPerMessage` BIGINT NOT NULL DEFAULT 1,
|
|
||||||
`XpPerReaction` BIGINT NOT NULL DEFAULT 1,
|
|
||||||
`MaxMessageXpPerHour` BIGINT NOT NULL DEFAULT 40,
|
|
||||||
`XpPerOntimeHour` BIGINT NOT NULL DEFAULT 20,
|
|
||||||
`XpPerEventParticipation` BIGINT NOT NULL DEFAULT 20,
|
|
||||||
`AFKCommandChannelId` BIGINT NOT NULL DEFAULT 1,
|
|
||||||
`HelpCommandReferenceUrl` VARCHAR(512) NOT NULL DEFAULT 'https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle',
|
|
||||||
`HelpVoiceChannelId` BIGINT NOT NULL DEFAULT 1,
|
|
||||||
-- boot log
|
|
||||||
`LoginMessageChannelId` BIGINT NOT NULL,
|
|
||||||
-- level
|
|
||||||
`ChangedLevelNotificationChannelId` BIGINT NOT NULL,
|
|
||||||
PRIMARY KEY(`Id`),
|
|
||||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
self._cursor.execute(
|
|
||||||
f"""
|
|
||||||
CREATE TABLE IF NOT EXISTS `ST_Servers_AFKChannelIds` (
|
|
||||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
|
||||||
`ST_Server` BIGINT NOT NULL,
|
|
||||||
`ChannelId` BIGINT NOT NULL,
|
|
||||||
PRIMARY KEY(`Id`),
|
|
||||||
FOREIGN KEY (`ST_Server`) REFERENCES `ST_Servers`(`Id`)
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
self._cursor.execute(
|
|
||||||
f"""
|
|
||||||
CREATE TABLE IF NOT EXISTS `ST_Servers_PingURLs` (
|
|
||||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
|
||||||
`ST_Server` BIGINT NOT NULL,
|
|
||||||
`URL` VARCHAR(512) NOT NULL,
|
|
||||||
PRIMARY KEY(`Id`),
|
|
||||||
FOREIGN KEY (`ST_Server`) REFERENCES `ST_Servers`(`Id`)
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
self._cursor.execute(
|
|
||||||
f"""
|
|
||||||
CREATE TABLE IF NOT EXISTS `ST_Servers_Permissions` (
|
|
||||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
|
||||||
`ST_Server` BIGINT NOT NULL,
|
|
||||||
`RoleId` BIGINT NOT NULL,
|
|
||||||
`RoleType` BIGINT NOT NULL DEFAULT 1,
|
|
||||||
PRIMARY KEY(`Id`),
|
|
||||||
FOREIGN KEY (`ST_Server`) REFERENCES `ST_Servers`(`Id`)
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
self._cursor.execute(
|
|
||||||
f"""
|
|
||||||
CREATE TABLE IF NOT EXISTS `ST_RoleTypes` (
|
|
||||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
|
||||||
`Name` VARCHAR(10) NOT NULL,
|
|
||||||
PRIMARY KEY(`Id`)
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
self._cursor.execute(
|
|
||||||
f"""
|
|
||||||
INSERT INTO `ST_RoleTypes`
|
|
||||||
(`Id`, `Name`)
|
|
||||||
VALUES
|
|
||||||
(1, 'Moderator'),
|
|
||||||
(2, 'Admin');
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
def downgrade(self):
|
|
||||||
self._logger.debug(__name__, "Running downgrade")
|
|
||||||
self._cursor.execute("DROP TABLE `ST_Bot`;")
|
|
||||||
self._cursor.execute("DROP TABLE `ST_Servers`;")
|
|
||||||
self._cursor.execute("DROP TABLE `ST_Servers_AFKChannelIds`;")
|
|
||||||
self._cursor.execute("DROP TABLE `ST_Servers_PingURLs`;")
|
|
||||||
self._cursor.execute("DROP TABLE `ST_Servers_Permissions`;")
|
|
||||||
self._cursor.execute("DROP TABLE `ST_RoleTypes`;")
|
|
@ -229,7 +229,7 @@ class AuthUser(TableABC):
|
|||||||
'{self._last_name}',
|
'{self._last_name}',
|
||||||
'{self._email}',
|
'{self._email}',
|
||||||
'{self._password}',
|
'{self._password}',
|
||||||
'{self._password_salt}',
|
'{self._password_salt}',
|
||||||
'{"NULL" if self._refresh_token is None else self._refresh_token}',
|
'{"NULL" if self._refresh_token is None else self._refresh_token}',
|
||||||
'{"NULL" if self._confirmation_id is None else self._confirmation_id}',
|
'{"NULL" if self._confirmation_id is None else self._confirmation_id}',
|
||||||
'{"NULL" if self._forgot_password_id is None else self._forgot_password_id}',
|
'{"NULL" if self._forgot_password_id is None else self._forgot_password_id}',
|
||||||
@ -252,10 +252,10 @@ class AuthUser(TableABC):
|
|||||||
`EMail` = '{self._email}',
|
`EMail` = '{self._email}',
|
||||||
`Password` = '{self._password}',
|
`Password` = '{self._password}',
|
||||||
`PasswordSalt` = '{self._password_salt}',
|
`PasswordSalt` = '{self._password_salt}',
|
||||||
{f"`RefreshToken` = ''," if self._refresh_token is not None else ''}
|
`RefreshToken` = '{'null' if self._refresh_token is None else f'{self._refresh_token}'}',
|
||||||
{f"`ConfirmationId` = ''," if self._confirmation_id is not None else ''}
|
`ConfirmationId` = '{'null' if self._confirmation_id is None else f'{self._confirmation_id}'}',
|
||||||
{f"`ForgotPasswordId` = ''," if self._forgot_password_id is not None else ''}
|
`ForgotPasswordId` = '{'null' if self._forgot_password_id is None else f'{self._forgot_password_id}'}',
|
||||||
{f"`OAuthId` = ''," if self._oauth_id is not None else ''}
|
`OAuthId` = '{'null' if self._oauth_id is None else f'{self._oauth_id}'}',
|
||||||
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
||||||
`AuthRole` = {self._auth_role_id.value},
|
`AuthRole` = {self._auth_role_id.value},
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
|
@ -168,7 +168,7 @@ class User(TableABC):
|
|||||||
f"""
|
f"""
|
||||||
UPDATE `Users`
|
UPDATE `Users`
|
||||||
SET `XP` = {self._xp},
|
SET `XP` = {self._xp},
|
||||||
{f"`MinecraftId` = '{self._minecraft_id}'," if self._minecraft_id is not None else ''}
|
`MinecraftId` = {'null' if self.minecraft_id is None else f'{self._minecraft_id}'},
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
WHERE `UserId` = {self._user_id};
|
WHERE `UserId` = {self._user_id};
|
||||||
"""
|
"""
|
||||||
|
@ -1,164 +0,0 @@
|
|||||||
from typing import Optional
|
|
||||||
|
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
|
||||||
|
|
||||||
from bot_core.configuration.bot_settings import BotSettings
|
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
|
||||||
|
|
||||||
|
|
||||||
class DBConfigService:
|
|
||||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC):
|
|
||||||
self._logger = logger
|
|
||||||
self._context = db_context
|
|
||||||
|
|
||||||
def get_st_bot(self) -> Optional[dict]:
|
|
||||||
result = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT `Id`, `WaitForRestart`, `WaitForShutdown`
|
|
||||||
FROM ST_Bot
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(result) == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# get first element
|
|
||||||
result = result[0]
|
|
||||||
|
|
||||||
result_as_dict = {
|
|
||||||
"WaitForRestart": result[1],
|
|
||||||
"WaitForShutdown": result[2],
|
|
||||||
}
|
|
||||||
|
|
||||||
servers = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT
|
|
||||||
Servers.`ServerId`,
|
|
||||||
`DiscordServerId`,
|
|
||||||
`MessageDeleteTimer`,
|
|
||||||
`MaxVoiceStateHours`,
|
|
||||||
`XpPerMessage`,
|
|
||||||
`XpPerReaction`,
|
|
||||||
`MaxMessageXpPerHour`,
|
|
||||||
`XpPerOntimeHour`,
|
|
||||||
`XpPerEventParticipation`,
|
|
||||||
`AFKCommandChannelId`,
|
|
||||||
`HelpCommandReferenceUrl`,
|
|
||||||
`HelpVoiceChannelId`,
|
|
||||||
`LoginMessageChannelId`,
|
|
||||||
`ChangedLevelNotificationChannelId`
|
|
||||||
FROM ST_Servers
|
|
||||||
INNER JOIN Servers ON
|
|
||||||
ST_Servers.ServerId = Servers.ServerId;
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
for server in servers:
|
|
||||||
afk_channels = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT `ChannelId`
|
|
||||||
FROM ST_Servers_AFKChannelIds
|
|
||||||
WHERE ST_Server = {server[0]};
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
afk_channel_ids = []
|
|
||||||
for afk_channel in afk_channels:
|
|
||||||
afk_channel_ids.append(afk_channel[0])
|
|
||||||
|
|
||||||
ping_urls_result = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT `URL`
|
|
||||||
FROM ST_Servers_PingURLs
|
|
||||||
WHERE ST_Server = {server[0]};
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
ping_urls = []
|
|
||||||
for url in ping_urls_result:
|
|
||||||
ping_urls.append(url[0])
|
|
||||||
|
|
||||||
admin_roles = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT `RoleId`
|
|
||||||
FROM ST_Servers_Permissions
|
|
||||||
WHERE ST_Server = {server[0]}
|
|
||||||
AND RoleType = 2;
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
admin_role_ids = []
|
|
||||||
for role in admin_roles:
|
|
||||||
admin_role_ids.append(role[0])
|
|
||||||
|
|
||||||
moderator_roles = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT `RoleId`
|
|
||||||
FROM ST_Servers_Permissions
|
|
||||||
WHERE ST_Server = {server[0]}
|
|
||||||
AND RoleType = 1;
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
moderator_role_ids = []
|
|
||||||
for role in moderator_roles:
|
|
||||||
moderator_role_ids.append(role[0])
|
|
||||||
|
|
||||||
result_as_dict[server[1]] = {
|
|
||||||
"MessageDeleteTimer": server[2],
|
|
||||||
"MaxVoiceStateHours": server[3],
|
|
||||||
"XpPerMessage": server[4],
|
|
||||||
"XpPerReaction": server[5],
|
|
||||||
"MaxMessageXpPerHour": server[6],
|
|
||||||
"XpPerOntimeHour": server[7],
|
|
||||||
"XpPerEventParticipation": server[8],
|
|
||||||
"AFKCommandChannelId": server[9],
|
|
||||||
"HelpCommandReferenceUrl": server[10],
|
|
||||||
"HelpVoiceChannelId": server[11],
|
|
||||||
"LoginMessageChannelId": server[12],
|
|
||||||
"ChangedLevelNotificationChannelId": server[13],
|
|
||||||
"AFKChannelIds": afk_channel_ids,
|
|
||||||
"PingURLs": ping_urls,
|
|
||||||
"AdminRoleIds": admin_role_ids,
|
|
||||||
"ModeratorRoleIds": moderator_role_ids,
|
|
||||||
}
|
|
||||||
|
|
||||||
return result_as_dict
|
|
||||||
|
|
||||||
def get_bot_settings(self) -> BotSettings:
|
|
||||||
settings = BotSettings()
|
|
||||||
settings.from_dict({})
|
|
||||||
return settings
|
|
||||||
|
|
||||||
def create_config_for_guild(self, guild_id: int):
|
|
||||||
server = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT `ServerId`
|
|
||||||
FROM Servers
|
|
||||||
WHERE `DiscordServerId` = {guild_id};
|
|
||||||
"""
|
|
||||||
)[0]
|
|
||||||
|
|
||||||
servers = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT *
|
|
||||||
FROM ST_Servers
|
|
||||||
WHERE `ServerId` = {server[0]}
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(servers) > 0:
|
|
||||||
self._logger.fatal(__name__, f"Config for guild {guild_id} already exists")
|
|
||||||
return
|
|
||||||
|
|
||||||
self._context.cursor.execute(
|
|
||||||
f"""
|
|
||||||
INSERT INTO `ST_Servers` (`ServerId`)
|
|
||||||
VALUES
|
|
||||||
({server[0]});
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
st_server = self._context.select(
|
|
||||||
f"""
|
|
||||||
SELECT `Id`
|
|
||||||
FROM ST_Servers
|
|
||||||
WHERE `ServerId` = {server[0]};
|
|
||||||
"""
|
|
||||||
)[0]
|
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "bot-data",
|
"Name": "bot-data",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "0",
|
"Major": "0",
|
||||||
"Minor": "3",
|
"Minor": "1",
|
||||||
"Micro": "dev127"
|
"Micro": "0"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
@ -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>=0.3.dev127"
|
"cpl-core>=2022.12.1"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=0.3.dev127"
|
"cpl-cli>=2022.12.1"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {},
|
"PythonPath": {},
|
||||||
|
@ -11,11 +11,11 @@ Discord bot for the Keksdose discord Server
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__title__ = "bot_data.events"
|
__title__ = "modules.database"
|
||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "0.3.dev127"
|
__version__ = "0.3.1"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="0", minor="3", micro="dev127")
|
version_info = VersionInfo(major="0", minor="3", micro="1")
|
44
kdb-bot/src/modules/database/database.json
Normal file
44
kdb-bot/src/modules/database/database.json
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"ProjectSettings": {
|
||||||
|
"Name": "database",
|
||||||
|
"Version": {
|
||||||
|
"Major": "0",
|
||||||
|
"Minor": "3",
|
||||||
|
"Micro": "1"
|
||||||
|
},
|
||||||
|
"Author": "Sven Heidemann",
|
||||||
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
"Description": "Keksdose bot - db module",
|
||||||
|
"LongDescription": "Discord bot for the Keksdose discord Server - database module",
|
||||||
|
"URL": "https://www.sh-edraft.de",
|
||||||
|
"CopyrightDate": "2022",
|
||||||
|
"CopyrightName": "sh-edraft.de",
|
||||||
|
"LicenseName": "MIT",
|
||||||
|
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||||
|
"Dependencies": [
|
||||||
|
"cpl-core==2022.12.0"
|
||||||
|
],
|
||||||
|
"DevDependencies": [
|
||||||
|
"cpl-cli==2022.12.0"
|
||||||
|
],
|
||||||
|
"PythonVersion": ">=3.10.4",
|
||||||
|
"PythonPath": {},
|
||||||
|
"Classifiers": []
|
||||||
|
},
|
||||||
|
"BuildSettings": {
|
||||||
|
"ProjectType": "library",
|
||||||
|
"SourcePath": "",
|
||||||
|
"OutputPath": "../../dist",
|
||||||
|
"Main": "database.main",
|
||||||
|
"EntryPoint": "database",
|
||||||
|
"IncludePackageData": false,
|
||||||
|
"Included": [],
|
||||||
|
"Excluded": [
|
||||||
|
"*/__pycache__",
|
||||||
|
"*/logs",
|
||||||
|
"*/tests"
|
||||||
|
],
|
||||||
|
"PackageData": {},
|
||||||
|
"ProjectReferences": []
|
||||||
|
}
|
||||||
|
}
|
22
kdb-bot/src/modules/database/database_module.py
Normal file
22
kdb-bot/src/modules/database/database_module.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||||
|
from cpl_core.environment import ApplicationEnvironmentABC
|
||||||
|
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
||||||
|
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseModule(ModuleABC):
|
||||||
|
def __init__(self, dc: DiscordCollectionABC):
|
||||||
|
ModuleABC.__init__(self, dc, FeatureFlagsEnum.database_module)
|
||||||
|
|
||||||
|
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||||
|
# commands
|
||||||
|
# events
|
||||||
|
self._dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent)
|
@ -300,9 +300,6 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
|||||||
)
|
)
|
||||||
join.leaved_on = datetime.now()
|
join.leaved_on = datetime.now()
|
||||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
|
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
|
||||||
if settings is None:
|
|
||||||
self._logger.error(__name__, f"BaseServer settings for server {guild.id} not found!")
|
|
||||||
return
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(join.leaved_on - join.joined_on).total_seconds() / 60 / 60
|
(join.leaved_on - join.joined_on).total_seconds() / 60 / 60
|
@ -1,9 +1,9 @@
|
|||||||
import discord
|
import discord
|
||||||
from cpl_core.configuration import ConfigurationABC
|
|
||||||
from cpl_core.logging import LoggerABC
|
from cpl_core.logging import LoggerABC
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
from bot_core.configuration.bot_startup_settings import BotStartupSettings
|
from bot_core.configuration.bot_settings import BotSettings
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||||
from modules.permission.configuration.permission_server_settings import (
|
from modules.permission.configuration.permission_server_settings import (
|
||||||
PermissionServerSettings,
|
PermissionServerSettings,
|
||||||
@ -16,7 +16,7 @@ class PermissionService(PermissionServiceABC):
|
|||||||
logger: LoggerABC,
|
logger: LoggerABC,
|
||||||
bot: DiscordBotServiceABC,
|
bot: DiscordBotServiceABC,
|
||||||
config: ConfigurationABC,
|
config: ConfigurationABC,
|
||||||
bot_settings: BotStartupSettings,
|
bot_settings: BotSettings,
|
||||||
):
|
):
|
||||||
PermissionServiceABC.__init__(self)
|
PermissionServiceABC.__init__(self)
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
|
Loading…
Reference in New Issue
Block a user