#127_config_in_wi #327
100
kdb-bot/.cpl/schematic_db_table.py
Normal file
100
kdb-bot/.cpl/schematic_db_table.py
Normal file
@ -0,0 +1,100 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class DBTable(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
self._name = self._name.replace("_db_table", "")
|
||||
self._class_name = self._class_name.split("Db_table")[0]
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
code = textwrap.dedent(
|
||||
"""\
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class $ClassName(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
value: str,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._value = value
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value: str):
|
||||
self._value = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f\"""
|
||||
SELECT * FROM `$TableName`;
|
||||
\"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f\"""
|
||||
SELECT * FROM `$TableName`
|
||||
WHERE `Id` = {id};
|
||||
\"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f\"""
|
||||
INSERT INTO `$TableName` (
|
||||
`Value`
|
||||
) VALUES (
|
||||
{self._value}
|
||||
);
|
||||
\"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f\"""
|
||||
UPDATE `$TableName`
|
||||
SET `Value` = {self._value}
|
||||
WHERE `Id` = {self._id};
|
||||
\"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f\"""
|
||||
DELETE FROM `$TableName`
|
||||
WHERE `Id` = {self._id};
|
||||
\"""
|
||||
)
|
||||
"""
|
||||
)
|
||||
return self.build_code_str(
|
||||
code,
|
||||
ClassName=self._class_name,
|
||||
TableName=self._class_name,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "db-table", [])
|
55
kdb-bot/.cpl/schematic_migration.py
Normal file
55
kdb-bot/.cpl/schematic_migration.py
Normal file
@ -0,0 +1,55 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Migration(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
code = textwrap.dedent(
|
||||
"""\
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class $ClassName(MigrationABC):
|
||||
name = "1.0_$ClassName"
|
||||
|
||||
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(
|
||||
str(
|
||||
f\"""
|
||||
CREATE TABLE IF NOT EXISTS `$TableName` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
\"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `$TableName`;")
|
||||
"""
|
||||
)
|
||||
return self.build_code_str(
|
||||
code,
|
||||
ClassName=self._class_name,
|
||||
TableName=self._class_name.split("Migration")[0],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "migration", [])
|
@ -1,7 +1,7 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class query(GenerateSchematicABC):
|
||||
class Query(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
"auto-role": "src/modules/auto_role/auto-role.json",
|
||||
"base": "src/modules/base/base.json",
|
||||
"boot-log": "src/modules/boot_log/boot-log.json",
|
||||
"config": "src/modules/config/modules/config.json",
|
||||
"database": "src/modules/database/database.json",
|
||||
"level": "src/modules/level/level.json",
|
||||
"permission": "src/modules/permission/permission.json",
|
||||
|
@ -16,24 +16,25 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core==2023.4.0.post2",
|
||||
"cpl-core==2023.4.0.post5",
|
||||
"cpl-translation==2023.4.0.post1",
|
||||
"cpl-query==2023.4.0.post1",
|
||||
"cpl-discord==2023.4.0.post3",
|
||||
"Flask==2.3.2",
|
||||
"Flask-Classful==0.14.2",
|
||||
"Flask-Cors==3.0.10",
|
||||
"PyJWT==2.7.0",
|
||||
"Flask-Cors==4.0.0",
|
||||
"PyJWT==2.8.0",
|
||||
"waitress==2.1.2",
|
||||
"Flask-SocketIO==5.3.4",
|
||||
"eventlet==0.33.3",
|
||||
"requests-oauthlib==1.3.1",
|
||||
"icmplib==3.0.3",
|
||||
"ariadne==0.19.1"
|
||||
"ariadne==0.20.1",
|
||||
"cryptography==41.0.2"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2023.4.0.post3",
|
||||
"pygount==1.5.1"
|
||||
"pygount==1.6.1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 440fb3bd353dce31a2408c977a3168e3cfc32f9a
|
||||
Subproject commit 359f9c38c3ec825a89f3bf289a65ec035cfcb693
|
@ -3,7 +3,7 @@ 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
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
|
||||
|
||||
class InitBotExtension(ApplicationExtensionABC):
|
||||
@ -11,6 +11,6 @@ class InitBotExtension(ApplicationExtensionABC):
|
||||
ApplicationExtensionABC.__init__(self)
|
||||
|
||||
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
settings = config.get_configuration(BotSettings)
|
||||
settings = config.get_configuration(TechnicianConfig)
|
||||
|
||||
bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC, max_messages=settings.cache_max_messages)
|
||||
|
@ -15,6 +15,7 @@ from bot.startup_settings_extension import StartupSettingsExtension
|
||||
from bot_api.app_api_extension import AppApiExtension
|
||||
from bot_core.core_extension.core_extension import CoreExtension
|
||||
from modules.boot_log.boot_log_extension import BootLogExtension
|
||||
from modules.config.config_extension import ConfigExtension
|
||||
from modules.database.database_extension import DatabaseExtension
|
||||
|
||||
|
||||
@ -30,6 +31,7 @@ class Program:
|
||||
.use_extension(StartupDiscordExtension)
|
||||
.use_extension(StartupModuleExtension)
|
||||
.use_extension(StartupMigrationExtension)
|
||||
.use_extension(ConfigExtension)
|
||||
.use_extension(InitBotExtension)
|
||||
.use_extension(BootLogExtension)
|
||||
.use_extension(DatabaseExtension)
|
||||
|
@ -9,6 +9,7 @@ from modules.achievements.achievements_module import AchievementsModule
|
||||
from modules.auto_role.auto_role_module import AutoRoleModule
|
||||
from modules.base.base_module import BaseModule
|
||||
from modules.boot_log.boot_log_module import BootLogModule
|
||||
from modules.config.config_module import ConfigModule
|
||||
from modules.database.database_module import DatabaseModule
|
||||
from modules.level.level_module import LevelModule
|
||||
from modules.permission.permission_module import PermissionModule
|
||||
@ -24,9 +25,10 @@ class ModuleList:
|
||||
[
|
||||
CoreModule, # has to be first!
|
||||
DataModule,
|
||||
DatabaseModule,
|
||||
ConfigModule, # has be to after db check
|
||||
GraphQLModule,
|
||||
PermissionModule,
|
||||
DatabaseModule,
|
||||
AutoRoleModule,
|
||||
BaseModule,
|
||||
LevelModule,
|
||||
|
@ -9,6 +9,7 @@ from bot_data.migration.api_key_migration import ApiKeyMigration
|
||||
from bot_data.migration.api_migration import ApiMigration
|
||||
from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration
|
||||
from bot_data.migration.auto_role_migration import AutoRoleMigration
|
||||
from bot_data.migration.config_migration import ConfigMigration
|
||||
from bot_data.migration.db_history_migration import DBHistoryMigration
|
||||
from bot_data.migration.initial_migration import InitialMigration
|
||||
from bot_data.migration.level_migration import LevelMigration
|
||||
@ -44,3 +45,4 @@ class StartupMigrationExtension(StartupExtensionABC):
|
||||
services.add_transient(MigrationABC, UserWarningMigration) # 21.02.2023 #35 - 1.0.0
|
||||
services.add_transient(MigrationABC, DBHistoryMigration) # 06.03.2023 #246 - 1.0.0
|
||||
services.add_transient(MigrationABC, AchievementsMigration) # 14.06.2023 #268 - 1.1.0
|
||||
services.add_transient(MigrationABC, ConfigMigration) # 19.07.2023 #127 - 1.1.0
|
||||
|
@ -1,6 +1,6 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from typing import Callable, Type, Optional
|
||||
from typing import Optional, Type, Callable
|
||||
|
||||
from cpl_core.application import StartupExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
@ -8,10 +8,6 @@ from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
from bot_core.configuration.bot_logging_settings import BotLoggingSettings
|
||||
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.permission.configuration.permission_settings import PermissionSettings
|
||||
|
||||
|
||||
class StartupSettingsExtension(StartupExtensionABC):
|
||||
@ -33,12 +29,6 @@ class StartupSettingsExtension(StartupExtensionABC):
|
||||
configuration.add_json_file(f"config/feature-flags.{environment.host_name}.json", optional=True)
|
||||
|
||||
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, 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, 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
|
||||
)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit c712f856ebe30c71ac0b144045599ed2f91a1cba
|
||||
Subproject commit 6d3f253f4121191308b4b0d5f01fa1c61b61406a
|
@ -1,16 +1,13 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class ApiSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, port: int = None, host: str = None, redirect_uri: bool = None):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._port = 80
|
||||
self._host = ""
|
||||
self._redirect_to_https = False
|
||||
self._port = 80 if port is None else port
|
||||
self._host = "" if host is None else host
|
||||
self._redirect_to_https = False if redirect_uri is None else redirect_uri
|
||||
|
||||
@property
|
||||
def port(self) -> int:
|
||||
@ -23,12 +20,3 @@ class ApiSettings(ConfigurationModelABC):
|
||||
@property
|
||||
def redirect_to_https(self) -> bool:
|
||||
return self._redirect_to_https
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._port = int(settings["Port"])
|
||||
self._host = settings["Host"]
|
||||
self._redirect_to_https = bool(settings["RedirectToHTTPS"])
|
||||
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,19 +1,22 @@
|
||||
import traceback
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class AuthenticationSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(
|
||||
self,
|
||||
secret_key: str = None,
|
||||
issuer: str = None,
|
||||
audience: str = None,
|
||||
token_expire_time: int = None,
|
||||
refresh_token_expire_time: int = None,
|
||||
):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._secret_key = ""
|
||||
self._issuer = ""
|
||||
self._audience = ""
|
||||
self._token_expire_time = 0
|
||||
self._refresh_token_expire_time = 0
|
||||
self._secret_key = "" if secret_key is None else secret_key
|
||||
self._issuer = "" if issuer is None else issuer
|
||||
self._audience = "" if audience is None else audience
|
||||
self._token_expire_time = 0 if token_expire_time is None else token_expire_time
|
||||
self._refresh_token_expire_time = 0 if refresh_token_expire_time is None else refresh_token_expire_time
|
||||
|
||||
@property
|
||||
def secret_key(self) -> str:
|
||||
@ -34,14 +37,3 @@ class AuthenticationSettings(ConfigurationModelABC):
|
||||
@property
|
||||
def refresh_token_expire_time(self) -> int:
|
||||
return self._refresh_token_expire_time
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._secret_key = settings["SecretKey"]
|
||||
self._issuer = settings["Issuer"]
|
||||
self._audience = settings["Audience"]
|
||||
self._token_expire_time = int(settings["TokenExpireTime"])
|
||||
self._refresh_token_expire_time = int(settings["RefreshTokenExpireTime"])
|
||||
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,19 +1,23 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class DiscordAuthenticationSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(
|
||||
self,
|
||||
client_secret: str = None,
|
||||
redirect_uri: str = None,
|
||||
scope: list = None,
|
||||
token_url: str = None,
|
||||
auth_url: str = None,
|
||||
):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._client_secret = ""
|
||||
self._redirect_url = ""
|
||||
self._scope = List()
|
||||
self._token_url = ""
|
||||
self._auth_url = ""
|
||||
self._client_secret = "" if client_secret is None else client_secret
|
||||
self._redirect_url = "" if redirect_uri is None else redirect_uri
|
||||
self._scope = List() if scope is None else List(str, scope)
|
||||
self._token_url = "" if token_url is None else token_url
|
||||
self._auth_url = "" if auth_url is None else auth_url
|
||||
|
||||
@property
|
||||
def client_secret(self) -> str:
|
||||
@ -34,14 +38,3 @@ class DiscordAuthenticationSettings(ConfigurationModelABC):
|
||||
@property
|
||||
def auth_url(self) -> str:
|
||||
return self._auth_url
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._client_secret = settings["ClientSecret"]
|
||||
self._redirect_url = settings["RedirectURL"]
|
||||
self._scope = List(str, settings["Scope"])
|
||||
self._token_url = settings["TokenURL"]
|
||||
self._auth_url = settings["AuthURL"]
|
||||
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,22 +1,12 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class FrontendSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, url: str = None):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._url = ""
|
||||
self._url = "" if url is None else url
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return self._url
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._url = settings["URL"]
|
||||
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,49 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_cli.configuration.version_settings_name_enum import VersionSettingsNameEnum
|
||||
|
||||
|
||||
class VersionSettings(ConfigurationModelABC):
|
||||
def __init__(self, major: str = None, minor: str = None, micro: str = None):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._major: Optional[str] = major
|
||||
self._minor: Optional[str] = minor
|
||||
self._micro: Optional[str] = micro
|
||||
|
||||
@property
|
||||
def major(self) -> str:
|
||||
return self._major
|
||||
|
||||
@property
|
||||
def minor(self) -> str:
|
||||
return self._minor
|
||||
|
||||
@property
|
||||
def micro(self) -> str:
|
||||
return self._micro
|
||||
|
||||
def to_str(self) -> str:
|
||||
if self._micro is None:
|
||||
return f"{self._major}.{self._minor}"
|
||||
else:
|
||||
return f"{self._major}.{self._minor}.{self._micro}"
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
self._major = settings[VersionSettingsNameEnum.major.value]
|
||||
self._minor = settings[VersionSettingsNameEnum.minor.value]
|
||||
micro = settings[VersionSettingsNameEnum.micro.value]
|
||||
if micro != "":
|
||||
self._micro = micro
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
version = {
|
||||
VersionSettingsNameEnum.major.value: self._major,
|
||||
VersionSettingsNameEnum.minor.value: self._minor,
|
||||
}
|
||||
|
||||
if self._micro is not None:
|
||||
version[VersionSettingsNameEnum.micro.value] = self._micro
|
||||
|
||||
return version
|
@ -7,8 +7,8 @@ from cpl_query.extension import List
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from bot_data.model.auto_role_rule import AutoRoleRule
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.user import User
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class ClientUtilsABC(ABC):
|
||||
@ -53,7 +53,7 @@ class ClientUtilsABC(ABC):
|
||||
self,
|
||||
created_at: datetime,
|
||||
user: User,
|
||||
settings: BaseServerSettings,
|
||||
settings: ServerConfig,
|
||||
is_reaction: bool = False,
|
||||
) -> bool:
|
||||
pass
|
||||
|
@ -6,12 +6,12 @@ from bot_core.configuration.file_logging_settings import FileLoggingSettings
|
||||
|
||||
|
||||
class BotLoggingSettings(ConfigurationModelABC):
|
||||
def __init__(self, custom_logs: dict = None):
|
||||
def __init__(self, **kwargs: dict):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
self._files: List[FileLoggingSettings] = List(FileLoggingSettings)
|
||||
|
||||
if custom_logs is not None:
|
||||
self._files_from_dict(custom_logs)
|
||||
if kwargs is not None:
|
||||
self._files_from_dict(kwargs)
|
||||
|
||||
@property
|
||||
def files(self) -> List[FileLoggingSettings]:
|
||||
@ -21,6 +21,5 @@ class BotLoggingSettings(ConfigurationModelABC):
|
||||
files = List(FileLoggingSettings)
|
||||
for s in settings:
|
||||
settings[s]["Key"] = s
|
||||
st = JSONProcessor.process(FileLoggingSettings, settings[s])
|
||||
files.append(st)
|
||||
files.append(JSONProcessor.process(FileLoggingSettings, settings[s]))
|
||||
self._files = files
|
||||
|
@ -1,79 +0,0 @@
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.json_processor import JSONProcessor
|
||||
from bot_core.configuration.server_settings import ServerSettings
|
||||
|
||||
|
||||
class BotSettings(ConfigurationModelABC):
|
||||
def __init__(
|
||||
self,
|
||||
technicians: list = None,
|
||||
wait_for_restart: int = 2,
|
||||
wait_for_shutdown: int = 2,
|
||||
cache_max_messages: int = 1000,
|
||||
server_settings: dict = None,
|
||||
):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._technicians: List[int] = List(int) if technicians is None else technicians
|
||||
self._wait_for_restart = wait_for_restart
|
||||
self._wait_for_shutdown = wait_for_shutdown
|
||||
self._cache_max_messages = cache_max_messages
|
||||
|
||||
self._servers: List[ServerSettings] = List(ServerSettings)
|
||||
|
||||
if server_settings is not None:
|
||||
self._servers_from_dict(server_settings)
|
||||
|
||||
@property
|
||||
def servers(self) -> List[ServerSettings]:
|
||||
return self._servers
|
||||
|
||||
@property
|
||||
def technicians(self) -> List[int]:
|
||||
return self._technicians
|
||||
|
||||
@property
|
||||
def wait_for_restart(self) -> int:
|
||||
return self._wait_for_restart
|
||||
|
||||
@property
|
||||
def wait_for_shutdown(self) -> int:
|
||||
return self._wait_for_shutdown
|
||||
|
||||
@property
|
||||
def cache_max_messages(self) -> int:
|
||||
return self._cache_max_messages
|
||||
|
||||
def _servers_from_dict(self, settings: dict):
|
||||
servers = List(ServerSettings)
|
||||
for s in settings:
|
||||
settings[s]["id"] = int(s)
|
||||
st = JSONProcessor.process(ServerSettings, settings[s])
|
||||
servers.append(st)
|
||||
self._servers = servers
|
||||
|
||||
# def from_dict(self, settings: dict):
|
||||
# try:
|
||||
# self._technicians = settings["Technicians"]
|
||||
# self._wait_for_restart = settings["WaitForRestart"]
|
||||
# self._wait_for_shutdown = settings["WaitForShutdown"]
|
||||
# settings.pop("Technicians")
|
||||
# settings.pop("WaitForRestart")
|
||||
# settings.pop("WaitForShutdown")
|
||||
#
|
||||
# if "CacheMaxMessages" in settings:
|
||||
# self._cache_max_messages = settings["CacheMaxMessages"]
|
||||
# settings.pop("CacheMaxMessages")
|
||||
#
|
||||
# servers = List(ServerSettings)
|
||||
# for s in settings:
|
||||
# st = ServerSettings()
|
||||
# settings[s]["Id"] = s
|
||||
# st.from_dict(settings[s])
|
||||
# servers.append(st)
|
||||
# self._servers = servers
|
||||
# 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()}")
|
@ -16,6 +16,7 @@ class FeatureFlagsEnum(Enum):
|
||||
level_module = "LevelModule"
|
||||
moderator_module = "ModeratorModule"
|
||||
permission_module = "PermissionModule"
|
||||
config_module = "ConfigModule"
|
||||
# features
|
||||
api_only = "ApiOnly"
|
||||
presence = "Presence"
|
||||
|
@ -1,34 +1,38 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
|
||||
|
||||
class FeatureFlagsSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
_flags = {
|
||||
# modules
|
||||
FeatureFlagsEnum.achievements_module.value: False, # 14.06.2023 #268
|
||||
FeatureFlagsEnum.api_module.value: False, # 13.10.2022 #70
|
||||
FeatureFlagsEnum.admin_module.value: False, # 02.10.2022 #48
|
||||
FeatureFlagsEnum.auto_role_module.value: True, # 03.10.2022 #54
|
||||
FeatureFlagsEnum.base_module.value: True, # 02.10.2022 #48
|
||||
FeatureFlagsEnum.boot_log_module.value: 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
|
||||
FeatureFlagsEnum.config_module.value: True, # 19.07.2023 #127
|
||||
# features
|
||||
FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70
|
||||
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
|
||||
FeatureFlagsEnum.version_in_presence.value: False, # 21.03.2023 #253
|
||||
}
|
||||
|
||||
def __init__(self, **kwargs: dict):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._flags = {
|
||||
# modules
|
||||
FeatureFlagsEnum.achievements_module.value: False, # 14.06.2023 #268
|
||||
FeatureFlagsEnum.api_module.value: False, # 13.10.2022 #70
|
||||
FeatureFlagsEnum.admin_module.value: False, # 02.10.2022 #48
|
||||
FeatureFlagsEnum.auto_role_module.value: True, # 03.10.2022 #54
|
||||
FeatureFlagsEnum.base_module.value: True, # 02.10.2022 #48
|
||||
FeatureFlagsEnum.boot_log_module.value: 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.api_only.value: False, # 13.10.2022 #70
|
||||
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
|
||||
FeatureFlagsEnum.version_in_presence.value: False, # 21.03.2023 #253
|
||||
}
|
||||
if len(kwargs.keys()) == 0:
|
||||
return
|
||||
|
||||
for flag in [f.value for f in FeatureFlagsEnum]:
|
||||
self._load_flag(kwargs, FeatureFlagsEnum(flag))
|
||||
|
||||
def get_flag(self, key: FeatureFlagsEnum) -> bool:
|
||||
if key.value not in self._flags:
|
||||
@ -40,11 +44,3 @@ class FeatureFlagsSettings(ConfigurationModelABC):
|
||||
return
|
||||
|
||||
self._flags[key.value] = bool(settings[key.value])
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
for flag in [f.value for f in FeatureFlagsEnum]:
|
||||
self._load_flag(settings, FeatureFlagsEnum(flag))
|
||||
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()}")
|
||||
|
@ -17,11 +17,3 @@ class FileLoggingSettings(LoggingSettings):
|
||||
@property
|
||||
def key(self) -> str:
|
||||
return self._key
|
||||
|
||||
# def from_dict(self, settings: dict):
|
||||
# try:
|
||||
# self._key = settings["Key"]
|
||||
# super().from_dict(settings)
|
||||
# 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,36 +0,0 @@
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
|
||||
|
||||
class ServerSettings(ConfigurationModelABC):
|
||||
def __init__(
|
||||
self,
|
||||
id: int = None,
|
||||
message_delete_timer: int = None,
|
||||
notification_chat_id: int = None,
|
||||
):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._id: int = id
|
||||
self._message_delete_timer: int = message_delete_timer
|
||||
self._notification_chat_id: int = notification_chat_id
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def message_delete_timer(self) -> int:
|
||||
return self._message_delete_timer
|
||||
|
||||
@property
|
||||
def notification_chat_id(self) -> int:
|
||||
return self._notification_chat_id
|
||||
|
||||
# def from_dict(self, settings: dict):
|
||||
# try:
|
||||
# self._id = int(settings["Id"])
|
||||
# self._message_delete_timer = int(settings["MessageDeleteTimer"])
|
||||
# self._notification_chat_id = int(settings["NotificationChatId"])
|
||||
# except Exception as e:
|
||||
# Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in settings")
|
||||
# Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
@ -25,9 +25,9 @@ from bot_data.abc.user_message_count_per_hour_repository_abc import (
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
)
|
||||
from bot_data.model.auto_role_rule import AutoRoleRule
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_message_count_per_hour import UserMessageCountPerHour
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class ClientUtilsService(ClientUtilsABC):
|
||||
@ -139,7 +139,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
self,
|
||||
created_at: datetime,
|
||||
user: User,
|
||||
settings: BaseServerSettings,
|
||||
settings: ServerConfig,
|
||||
is_reaction: bool = False,
|
||||
) -> bool:
|
||||
umcph = None
|
||||
|
@ -19,13 +19,13 @@ from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.client import Client
|
||||
from bot_data.model.known_user import KnownUser
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_joined_server import UserJoinedServer
|
||||
from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
||||
from bot_data.service.seeder_service import SeederService
|
||||
from bot_data.service.user_repository_service import ServerRepositoryABC
|
||||
from modules.achievements.achievement_service import AchievementService
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class DataIntegrityService:
|
||||
@ -174,7 +174,7 @@ class DataIntegrityService:
|
||||
|
||||
self._logger.warn(__name__, f"User not found in database: {u.id}")
|
||||
self._logger.debug(__name__, f"Add user: {u.id}")
|
||||
self._users.add_user(User(u.id, 0, server))
|
||||
self._users.add_user(User(u.id, 0, 0, 0, server))
|
||||
self._db_context.save_changes()
|
||||
|
||||
self._logger.debug(__name__, f"Added User: {u.id}")
|
||||
@ -255,7 +255,7 @@ class DataIntegrityService:
|
||||
self._logger.debug(__name__, f"Start checking UserJoinedVoiceChannel table")
|
||||
for guild in self._bot.guilds:
|
||||
guild: discord.Guild = guild
|
||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}")
|
||||
|
||||
server = self._servers.find_server_by_discord_id(guild.id)
|
||||
if server is None:
|
||||
@ -347,7 +347,7 @@ class DataIntegrityService:
|
||||
f"Active UserJoinedGameServer found in database: {guild.id}:{member.id}@{join.joined_on}",
|
||||
)
|
||||
join.leaved_on = datetime.now()
|
||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}")
|
||||
|
||||
if (
|
||||
(join.leaved_on - join.joined_on).total_seconds() / 60 / 60
|
||||
|
@ -10,10 +10,10 @@ from discord import Interaction
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.server_settings import ServerSettings
|
||||
from bot_core.helper.log_message_helper import LogMessageHelper
|
||||
from bot_core.logging.message_logger import MessageLogger
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
|
||||
|
||||
class MessageService(MessageServiceABC):
|
||||
@ -33,7 +33,7 @@ class MessageService(MessageServiceABC):
|
||||
|
||||
async def delete_messages(self, messages: List[discord.Message], guild_id: int, without_tracking=False):
|
||||
self._logger.debug(__name__, f"Try to delete {messages.count()} messages")
|
||||
server_st: ServerSettings = self._config.get_configuration(f"ServerSettings_{guild_id}")
|
||||
server_st: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild_id}")
|
||||
await asyncio.sleep(server_st.message_delete_timer)
|
||||
for message in messages:
|
||||
await self.delete_message(message, mass_delete=True, without_tracking=without_tracking)
|
||||
@ -50,7 +50,7 @@ class MessageService(MessageServiceABC):
|
||||
else None
|
||||
)
|
||||
|
||||
server_st: ServerSettings = self._config.get_configuration(f"ServerSettings_{guild_id}")
|
||||
server_st: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild_id}")
|
||||
if not mass_delete:
|
||||
await asyncio.sleep(server_st.message_delete_timer)
|
||||
self._logger.debug(
|
||||
|
@ -7,5 +7,5 @@ class DataSeederABC(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def seed(self):
|
||||
async def seed(self):
|
||||
pass
|
||||
|
59
kdb-bot/src/bot_data/abc/server_config_repository_abc.py
Normal file
59
kdb-bot/src/bot_data/abc/server_config_repository_abc.py
Normal file
@ -0,0 +1,59 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from bot_data.model.server_afk_channel_ids_config import ServerAFKChannelIdsConfig
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
||||
|
||||
|
||||
class ServerConfigRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def does_server_config_exists(self, server_id: int) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_config_by_server(self, server_id: int) -> ServerConfig:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_config_by_id(self, config_id: int) -> ServerConfig:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_server_config(self, server_config: ServerConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_server_config(self, server_config: ServerConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_server_config(self, server_config: ServerConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_server_team_role_id_config(self, server_team_role_id: ServerTeamRoleIdsConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_server_team_role_id_config(self, server_team_role_id: ServerTeamRoleIdsConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_server_team_role_id_config(self, server_team_role_id: ServerTeamRoleIdsConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_server_afk_channel_config(self, server_afk_channel: ServerAFKChannelIdsConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_server_afk_channel_config(self, server_afk_channel: ServerAFKChannelIdsConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_server_afk_channel_config(self, server_afk_channel: ServerAFKChannelIdsConfig):
|
||||
pass
|
55
kdb-bot/src/bot_data/abc/technician_config_repository_abc.py
Normal file
55
kdb-bot/src/bot_data/abc/technician_config_repository_abc.py
Normal file
@ -0,0 +1,55 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from bot_data.model.technician_id_config import TechnicianIdConfig
|
||||
from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig
|
||||
|
||||
|
||||
class TechnicianConfigRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def does_technician_config_exists(self) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_technician_config(self) -> TechnicianConfig:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_technician_config(self, technician_config: TechnicianConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_technician_config(self, technician_config: TechnicianConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_technician_config(self, technician_config: TechnicianConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_technician_id_config(self, technician_id: TechnicianIdConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_technician_id_config(self, technician_id: TechnicianIdConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_technician_id_config(self, technician_id: TechnicianIdConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_technician_ping_url_config(self, technician_ping_url: TechnicianPingUrlConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_technician_ping_url_config(self, technician_ping_url: TechnicianPingUrlConfig):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_technician_ping_url_config(self, technician_ping_url: TechnicianPingUrlConfig):
|
||||
pass
|
@ -10,10 +10,13 @@ from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.data_seeder_abc import DataSeederABC
|
||||
from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC
|
||||
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
@ -35,7 +38,11 @@ from bot_data.service.game_server_repository_service import GameServerRepository
|
||||
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
||||
from bot_data.service.level_repository_service import LevelRepositoryService
|
||||
from bot_data.service.seeder_service import SeederService
|
||||
from bot_data.service.server_config_repository_service import ServerConfigRepositoryService
|
||||
from bot_data.service.server_config_seeder import ServerConfigSeeder
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
from bot_data.service.technician_config_repository_service import TechnicianConfigRepositoryService
|
||||
from bot_data.service.technician_config_seeder import TechnicianConfigSeeder
|
||||
from bot_data.service.user_game_ident_repository_service import UserGameIdentRepositoryService
|
||||
from bot_data.service.user_joined_game_server_repository_service import UserJoinedGameServerRepositoryService
|
||||
from bot_data.service.user_joined_server_repository_service import (
|
||||
@ -80,5 +87,9 @@ class DataModule(ModuleABC):
|
||||
services.add_transient(GameServerRepositoryABC, GameServerRepositoryService)
|
||||
services.add_transient(UserGameIdentRepositoryABC, UserGameIdentRepositoryService)
|
||||
services.add_transient(AchievementRepositoryABC, AchievementRepositoryService)
|
||||
services.add_transient(TechnicianConfigRepositoryABC, TechnicianConfigRepositoryService)
|
||||
services.add_transient(ServerConfigRepositoryABC, ServerConfigRepositoryService)
|
||||
|
||||
services.add_transient(SeederService)
|
||||
services.add_transient(DataSeederABC, TechnicianConfigSeeder)
|
||||
services.add_transient(DataSeederABC, ServerConfigSeeder)
|
||||
|
153
kdb-bot/src/bot_data/migration/config_migration.py
Normal file
153
kdb-bot/src/bot_data/migration/config_migration.py
Normal file
@ -0,0 +1,153 @@
|
||||
import os
|
||||
|
||||
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.1.0_ConfigMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
def _exec(self, file: str):
|
||||
path = f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts"
|
||||
sql = open(f"{path}/{file}").read()
|
||||
|
||||
for statement in sql.split("\n\n"):
|
||||
self._cursor.execute(statement + ";")
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
self._server_upgrade()
|
||||
self._technician_upgrade()
|
||||
|
||||
self._exec("config/server.sql")
|
||||
self._exec("config/server_afk_channels.sql")
|
||||
self._exec("config/server_team_roles.sql")
|
||||
self._exec("config/technician.sql")
|
||||
self._exec("config/technician_ids.sql")
|
||||
self._exec("config/technician_ping_urls.sql")
|
||||
|
||||
def _server_upgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `CFG_Server` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`MessageDeleteTimer` BIGINT NOT NULL DEFAULT 6,
|
||||
`NotificationChatId` BIGINT NOT NULL,
|
||||
`MaxVoiceStateHours` BIGINT NOT NULL DEFAULT 6,
|
||||
`XpPerMessage` BIGINT NOT NULL DEFAULT 1,
|
||||
`XpPerReaction` BIGINT NOT NULL DEFAULT 1,
|
||||
`MaxMessageXpPerHour` BIGINT NOT NULL DEFAULT 20,
|
||||
`XpPerOntimeHour` BIGINT NOT NULL DEFAULT 10,
|
||||
`XpPerEventParticipation` BIGINT NOT NULL DEFAULT 10,
|
||||
`XpPerAchievement` BIGINT NOT NULL DEFAULT 10,
|
||||
`AFKCommandChannelId` BIGINT NOT NULL,
|
||||
`HelpVoiceChannelId` BIGINT NOT NULL,
|
||||
`TeamChannelId` BIGINT NOT NULL,
|
||||
`LoginMessageChannelId` BIGINT NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `CFG_ServerAFKChannelIds` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`ChannelId` BIGINT NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `CFG_ServerTeamRoleIds` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`RoleId` BIGINT NOT NULL,
|
||||
`TeamMemberType` ENUM('Moderator', 'Admin') NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def _technician_upgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `CFG_Technician` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`HelpCommandReferenceUrl` VARCHAR(255) NOT NULL,
|
||||
`WaitForRestart` BIGINT NOT NULL DEFAULT 8,
|
||||
`WaitForShutdown` BIGINT NOT NULL DEFAULT 8,
|
||||
`CacheMaxMessages` BIGINT NOT NULL DEFAULT 1000000,
|
||||
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `CFG_TechnicianPingUrls` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`URL` VARCHAR(255) NOT NULL,
|
||||
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `CFG_TechnicianIds` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`TechnicianId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._logger.debug(__name__, "Running downgrade")
|
||||
|
||||
def _server_downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `CFG_Server`;")
|
||||
|
||||
def _technician_downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `CFG_Technician`;")
|
||||
self._cursor.execute("DROP TABLE `CFG_TechnicianPingUrls`;")
|
||||
self._cursor.execute("DROP TABLE `CFG_TechnicianIds`;")
|
@ -0,0 +1,117 @@
|
||||
CREATE TABLE IF NOT EXISTS `CFG_ServerHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`MessageDeleteTimer` BIGINT NOT NULL DEFAULT 6,
|
||||
`NotificationChatId` BIGINT NOT NULL,
|
||||
`MaxVoiceStateHours` BIGINT NOT NULL DEFAULT 6,
|
||||
`XpPerMessage` BIGINT NOT NULL DEFAULT 1,
|
||||
`XpPerReaction` BIGINT NOT NULL DEFAULT 1,
|
||||
`MaxMessageXpPerHour` BIGINT NOT NULL DEFAULT 20,
|
||||
`XpPerOntimeHour` BIGINT NOT NULL DEFAULT 10,
|
||||
`XpPerEventParticipation` BIGINT NOT NULL DEFAULT 10,
|
||||
`XpPerAchievement` BIGINT NOT NULL DEFAULT 10,
|
||||
`AFKCommandChannelId` BIGINT NOT NULL,
|
||||
`HelpVoiceChannelId` BIGINT NOT NULL,
|
||||
`TeamChannelId` BIGINT NOT NULL,
|
||||
`LoginMessageChannelId` BIGINT NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_ServerUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_ServerUpdate`
|
||||
AFTER UPDATE
|
||||
ON `CFG_Server`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_ServerHistory` (
|
||||
`Id`,
|
||||
`MessageDeleteTimer`,
|
||||
`NotificationChatId`,
|
||||
`MaxVoiceStateHours`,
|
||||
`XpPerMessage`,
|
||||
`XpPerReaction`,
|
||||
`MaxMessageXpPerHour`,
|
||||
`XpPerOntimeHour`,
|
||||
`XpPerEventParticipation`,
|
||||
`XpPerAchievement`,
|
||||
`AFKCommandChannelId`,
|
||||
`HelpVoiceChannelId`,
|
||||
`TeamChannelId`,
|
||||
`LoginMessageChannelId`,
|
||||
`ServerId`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.MessageDeleteTimer,
|
||||
OLD.NotificationChatId,
|
||||
OLD.MaxVoiceStateHours,
|
||||
OLD.XpPerMessage,
|
||||
OLD.XpPerReaction,
|
||||
OLD.MaxMessageXpPerHour,
|
||||
OLD.XpPerOntimeHour,
|
||||
OLD.XpPerEventParticipation,
|
||||
OLD.XpPerAchievement,
|
||||
OLD.AFKCommandChannelId,
|
||||
OLD.HelpVoiceChannelId,
|
||||
OLD.TeamChannelId,
|
||||
OLD.LoginMessageChannelId,
|
||||
OLD.ServerId,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_ServerDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_ServerDelete`
|
||||
AFTER DELETE
|
||||
ON `CFG_Server`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_ServerHistory` (
|
||||
`Id`,
|
||||
`MessageDeleteTimer`,
|
||||
`NotificationChatId`,
|
||||
`MaxVoiceStateHours`,
|
||||
`XpPerMessage`,
|
||||
`XpPerReaction`,
|
||||
`MaxMessageXpPerHour`,
|
||||
`XpPerOntimeHour`,
|
||||
`XpPerEventParticipation`,
|
||||
`XpPerAchievement`,
|
||||
`AFKCommandChannelId`,
|
||||
`HelpVoiceChannelId`,
|
||||
`TeamChannelId`,
|
||||
`LoginMessageChannelId`,
|
||||
`ServerId`,
|
||||
`Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.MessageDeleteTimer,
|
||||
OLD.NotificationChatId,
|
||||
OLD.MaxVoiceStateHours,
|
||||
OLD.XpPerMessage,
|
||||
OLD.XpPerReaction,
|
||||
OLD.MaxMessageXpPerHour,
|
||||
OLD.XpPerOntimeHour,
|
||||
OLD.XpPerEventParticipation,
|
||||
OLD.XpPerAchievement,
|
||||
OLD.AFKCommandChannelId,
|
||||
OLD.HelpVoiceChannelId,
|
||||
OLD.TeamChannelId,
|
||||
OLD.LoginMessageChannelId,
|
||||
OLD.ServerId,
|
||||
TRUE,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,57 @@
|
||||
CREATE TABLE IF NOT EXISTS `CFG_ServerAFKChannelIdsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`ChannelId` BIGINT NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_ServerAFKChannelIdsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_ServerAFKChannelIdsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `CFG_ServerAFKChannelIds`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_ServerAFKChannelIdsHistory` (
|
||||
`Id`,
|
||||
`ChannelId`,
|
||||
`ServerId`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.ChannelId,
|
||||
OLD.ServerId,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_ServerAFKChannelIdsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_ServerAFKChannelIdsDelete`
|
||||
AFTER DELETE
|
||||
ON `CFG_ServerAFKChannelIds`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_ServerAFKChannelIdsHistory` (
|
||||
`Id`,
|
||||
`ChannelId`,
|
||||
`ServerId`,
|
||||
`Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.ChannelId,
|
||||
OLD.ServerId,
|
||||
TRUE,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,62 @@
|
||||
CREATE TABLE IF NOT EXISTS `CFG_ServerTeamRoleIdsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`RoleId` BIGINT NOT NULL,
|
||||
`TeamMemberType` ENUM('Moderator', 'Admin') NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_ServerTeamRoleIdsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_ServerTeamRoleIdsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `CFG_ServerTeamRoleIds`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_ServerTeamRoleIdsHistory` (
|
||||
`Id`,
|
||||
`RoleId`,
|
||||
`TeamMemberType`,
|
||||
`ServerId`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.RoleId,
|
||||
OLD.TeamMemberType,
|
||||
OLD.ServerId,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_ServerTeamRoleIdsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_ServerTeamRoleIdsDelete`
|
||||
AFTER DELETE
|
||||
ON `CFG_ServerTeamRoleIds`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_ServerTeamRoleIdsHistory` (
|
||||
`Id`,
|
||||
`RoleId`,
|
||||
`TeamMemberType`,
|
||||
`ServerId`,
|
||||
`Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.RoleId,
|
||||
OLD.TeamMemberType,
|
||||
OLD.ServerId,
|
||||
TRUE,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,67 @@
|
||||
CREATE TABLE IF NOT EXISTS `CFG_TechnicianHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`HelpCommandReferenceUrl` VARCHAR(255) NOT NULL,
|
||||
`WaitForRestart` BIGINT NOT NULL DEFAULT 8,
|
||||
`WaitForShutdown` BIGINT NOT NULL DEFAULT 8,
|
||||
`CacheMaxMessages` BIGINT NOT NULL DEFAULT 1000000,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_TechnicianUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_TechnicianUpdate`
|
||||
AFTER UPDATE
|
||||
ON `CFG_Technician`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_TechnicianHistory` (
|
||||
`Id`,
|
||||
`HelpCommandReferenceUrl`,
|
||||
`WaitForRestart`,
|
||||
`WaitForShutdown`,
|
||||
`CacheMaxMessages`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.HelpCommandReferenceUrl,
|
||||
OLD.WaitForRestart,
|
||||
OLD.WaitForShutdown,
|
||||
OLD.CacheMaxMessages,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_TechnicianDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_TechnicianDelete`
|
||||
AFTER DELETE
|
||||
ON `CFG_Technician`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_TechnicianHistory` (
|
||||
`Id`,
|
||||
`HelpCommandReferenceUrl`,
|
||||
`WaitForRestart`,
|
||||
`WaitForShutdown`,
|
||||
`CacheMaxMessages`,
|
||||
`Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.HelpCommandReferenceUrl,
|
||||
OLD.WaitForRestart,
|
||||
OLD.WaitForShutdown,
|
||||
OLD.CacheMaxMessages,
|
||||
TRUE,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,52 @@
|
||||
CREATE TABLE IF NOT EXISTS `CFG_TechnicianIdsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`TechnicianId` BIGINT NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_TechnicianIdsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_TechnicianIdsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `CFG_TechnicianIds`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_TechnicianIdsHistory` (
|
||||
`Id`,
|
||||
`TechnicianId`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.TechnicianId,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_TechnicianIdsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_TechnicianIdsDelete`
|
||||
AFTER DELETE
|
||||
ON `CFG_TechnicianIds`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_TechnicianIdsHistory` (
|
||||
`Id`,
|
||||
`TechnicianId`,
|
||||
`Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.TechnicianId,
|
||||
TRUE,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,52 @@
|
||||
CREATE TABLE IF NOT EXISTS `CFG_TechnicianPingUrlsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`URL` VARCHAR(255) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_TechnicianPingUrlsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_TechnicianPingUrlsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `CFG_TechnicianPingUrls`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_TechnicianPingUrlsHistory` (
|
||||
`Id`,
|
||||
`URL`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.URL,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_CFG_TechnicianPingUrlsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_CFG_TechnicianPingUrlsDelete`
|
||||
AFTER DELETE
|
||||
ON `CFG_TechnicianPingUrls`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `CFG_TechnicianPingUrlsHistory` (
|
||||
`Id`,
|
||||
`URL`,
|
||||
`Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id,
|
||||
OLD.URL,
|
||||
TRUE,
|
||||
OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
85
kdb-bot/src/bot_data/model/server_afk_channel_ids_config.py
Normal file
85
kdb-bot/src/bot_data/model/server_afk_channel_ids_config.py
Normal file
@ -0,0 +1,85 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class ServerAFKChannelIdsConfig(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
channel_id: int,
|
||||
server_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._channel_id = channel_id
|
||||
self._server_id = server_id
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def channel_id(self) -> int:
|
||||
return self._channel_id
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_ServerAFKChannelIds`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_ServerAFKChannelIds`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(server_id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_ServerAFKChannelIds`
|
||||
WHERE `ServerId` = {server_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `CFG_ServerAFKChannelIds` (
|
||||
`ChannelId`,
|
||||
`ServerId`
|
||||
) VALUES (
|
||||
{self._channel_id},
|
||||
{self._server_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `CFG_ServerAFKChannelIds`
|
||||
SET `ChannelId` = {self._channel_id},
|
||||
`ServerId` = {self._server_id}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `CFG_ServerAFKChannelIds`
|
||||
WHERE `ChannelId` = {self._channel_id};
|
||||
"""
|
||||
)
|
278
kdb-bot/src/bot_data/model/server_config.py
Normal file
278
kdb-bot/src/bot_data/model/server_config.py
Normal file
@ -0,0 +1,278 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
||||
|
||||
|
||||
class ServerConfig(TableABC, ConfigurationModelABC):
|
||||
def __init__(
|
||||
self,
|
||||
message_delete_timer: int,
|
||||
notification_chat_id: int,
|
||||
max_voice_state_hours: int,
|
||||
xp_per_message: int,
|
||||
xp_per_reaction: int,
|
||||
max_message_xp_per_hour: int,
|
||||
xp_per_ontime_hour: int,
|
||||
xp_per_event_participation: int,
|
||||
xp_per_achievement: int,
|
||||
afk_command_channel_id: int,
|
||||
help_voice_channel_id: int,
|
||||
team_channel_id: int,
|
||||
login_message_channel_id: int,
|
||||
server: Server,
|
||||
afk_channel_ids: List[int],
|
||||
team_role_ids: List[ServerTeamRoleIdsConfig],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._message_delete_timer = message_delete_timer
|
||||
self._notification_chat_id = notification_chat_id
|
||||
self._max_voice_state_hours = max_voice_state_hours
|
||||
self._xp_per_message = xp_per_message
|
||||
self._xp_per_reaction = xp_per_reaction
|
||||
self._max_message_xp_per_hour = max_message_xp_per_hour
|
||||
self._xp_per_ontime_hour = xp_per_ontime_hour
|
||||
self._xp_per_event_participation = xp_per_event_participation
|
||||
self._xp_per_achievement = xp_per_achievement
|
||||
self._afk_command_channel_id = afk_command_channel_id
|
||||
self._help_voice_channel_id = help_voice_channel_id
|
||||
self._team_channel_id = team_channel_id
|
||||
self._login_message_channel_id = login_message_channel_id
|
||||
self._server = server
|
||||
self._afk_channel_ids = afk_channel_ids
|
||||
self._team_role_ids = team_role_ids
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def message_delete_timer(self) -> int:
|
||||
return self._message_delete_timer
|
||||
|
||||
@message_delete_timer.setter
|
||||
def message_delete_timer(self, value: int):
|
||||
self._message_delete_timer = value
|
||||
|
||||
@property
|
||||
def notification_chat_id(self) -> int:
|
||||
return self._notification_chat_id
|
||||
|
||||
@notification_chat_id.setter
|
||||
def notification_chat_id(self, value: int):
|
||||
self._notification_chat_id = value
|
||||
|
||||
@property
|
||||
def max_voice_state_hours(self) -> int:
|
||||
return self._max_voice_state_hours
|
||||
|
||||
@max_voice_state_hours.setter
|
||||
def max_voice_state_hours(self, value: int):
|
||||
self._max_voice_state_hours = value
|
||||
|
||||
@property
|
||||
def xp_per_message(self) -> int:
|
||||
return self._xp_per_message
|
||||
|
||||
@xp_per_message.setter
|
||||
def xp_per_message(self, value: int):
|
||||
self._xp_per_message = value
|
||||
|
||||
@property
|
||||
def xp_per_reaction(self) -> int:
|
||||
return self._xp_per_reaction
|
||||
|
||||
@xp_per_reaction.setter
|
||||
def xp_per_reaction(self, value: int):
|
||||
self._xp_per_reaction = value
|
||||
|
||||
@property
|
||||
def max_message_xp_per_hour(self) -> int:
|
||||
return self._max_message_xp_per_hour
|
||||
|
||||
@max_message_xp_per_hour.setter
|
||||
def max_message_xp_per_hour(self, value: int):
|
||||
self._max_message_xp_per_hour = value
|
||||
|
||||
@property
|
||||
def xp_per_ontime_hour(self) -> int:
|
||||
return self._xp_per_ontime_hour
|
||||
|
||||
@xp_per_ontime_hour.setter
|
||||
def xp_per_ontime_hour(self, value: int):
|
||||
self._xp_per_ontime_hour = value
|
||||
|
||||
@property
|
||||
def xp_per_event_participation(self) -> int:
|
||||
return self._xp_per_event_participation
|
||||
|
||||
@xp_per_event_participation.setter
|
||||
def xp_per_event_participation(self, value: int):
|
||||
self._xp_per_event_participation = value
|
||||
|
||||
@property
|
||||
def xp_per_achievement(self) -> int:
|
||||
return self._xp_per_achievement
|
||||
|
||||
@xp_per_achievement.setter
|
||||
def xp_per_achievement(self, value: int):
|
||||
self._xp_per_achievement = value
|
||||
|
||||
@property
|
||||
def afk_command_channel_id(self) -> int:
|
||||
return self._afk_command_channel_id
|
||||
|
||||
@afk_command_channel_id.setter
|
||||
def afk_command_channel_id(self, value: int):
|
||||
self._afk_command_channel_id = value
|
||||
|
||||
@property
|
||||
def help_voice_channel_id(self) -> int:
|
||||
return self._help_voice_channel_id
|
||||
|
||||
@help_voice_channel_id.setter
|
||||
def help_voice_channel_id(self, value: int):
|
||||
self._help_voice_channel_id = value
|
||||
|
||||
@property
|
||||
def team_channel_id(self) -> int:
|
||||
return self._team_channel_id
|
||||
|
||||
@team_channel_id.setter
|
||||
def team_channel_id(self, value: int):
|
||||
self._team_channel_id = value
|
||||
|
||||
@property
|
||||
def login_message_channel_id(self) -> int:
|
||||
return self._login_message_channel_id
|
||||
|
||||
@login_message_channel_id.setter
|
||||
def login_message_channel_id(self, value: int):
|
||||
self._login_message_channel_id = value
|
||||
|
||||
@property
|
||||
def afk_channel_ids(self) -> List[int]:
|
||||
return self._afk_channel_ids
|
||||
|
||||
@afk_channel_ids.setter
|
||||
def afk_channel_ids(self, value: List[int]):
|
||||
self._afk_channel_ids = value
|
||||
|
||||
@property
|
||||
def team_role_ids(self) -> List[ServerTeamRoleIdsConfig]:
|
||||
return self._team_role_ids
|
||||
|
||||
@team_role_ids.setter
|
||||
def team_role_ids(self, value: List[ServerTeamRoleIdsConfig]):
|
||||
self._team_role_ids = value
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_Server`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_Server`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(server_id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_Server`
|
||||
WHERE `ServerId` = {server_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `CFG_Server` (
|
||||
`MessageDeleteTimer`,
|
||||
`NotificationChatId`,
|
||||
`MaxVoiceStateHours`,
|
||||
`XpPerMessage`,
|
||||
`XpPerReaction`,
|
||||
`MaxMessageXpPerHour`,
|
||||
`XpPerOntimeHour`,
|
||||
`XpPerEventParticipation`,
|
||||
`XpPerAchievement`,
|
||||
`AFKCommandChannelId`,
|
||||
`HelpVoiceChannelId`,
|
||||
`TeamChannelId`,
|
||||
`LoginMessageChannelId`,
|
||||
`ServerId`
|
||||
) VALUES (
|
||||
{self._message_delete_timer},
|
||||
{self._notification_chat_id},
|
||||
{self._max_voice_state_hours},
|
||||
{self._xp_per_message},
|
||||
{self._xp_per_reaction},
|
||||
{self._max_message_xp_per_hour},
|
||||
{self._xp_per_ontime_hour},
|
||||
{self._xp_per_event_participation},
|
||||
{self._xp_per_achievement},
|
||||
{self._afk_command_channel_id},
|
||||
{self._help_voice_channel_id},
|
||||
{self._team_channel_id},
|
||||
{self._login_message_channel_id},
|
||||
{self._server.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `CFG_Server`
|
||||
SET `MessageDeleteTimer` = {self._message_delete_timer},
|
||||
`NotificationChatId` = {self._notification_chat_id},
|
||||
`MaxVoiceStateHours` = {self._max_voice_state_hours},
|
||||
`XpPerMessage` = {self._xp_per_message},
|
||||
`XpPerReaction` = {self._xp_per_reaction},
|
||||
`MaxMessageXpPerHour` = {self._max_message_xp_per_hour},
|
||||
`XpPerOntimeHour` = {self._xp_per_ontime_hour},
|
||||
`XpPerEventParticipation` = {self._xp_per_event_participation},
|
||||
`XpPerAchievement` = {self._xp_per_achievement},
|
||||
`AFKCommandChannelId` = {self._afk_command_channel_id},
|
||||
`HelpVoiceChannelId` = {self._help_voice_channel_id},
|
||||
`TeamChannelId` = {self._team_channel_id},
|
||||
`LoginMessageChannelId` = {self._login_message_channel_id},
|
||||
`ServerId` = {self._server.id}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `CFG_Server`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
102
kdb-bot/src/bot_data/model/server_config_history.py
Normal file
102
kdb-bot/src/bot_data/model/server_config_history.py
Normal file
@ -0,0 +1,102 @@
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class ServerConfigHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
message_delete_timer: int,
|
||||
notification_chat_id: int,
|
||||
max_voice_state_hours: int,
|
||||
xp_per_message: int,
|
||||
xp_per_reaction: int,
|
||||
max_message_xp_per_hour: int,
|
||||
xp_per_ontime_hour: int,
|
||||
xp_per_event_participation: int,
|
||||
xp_per_achievement: int,
|
||||
afk_command_channel_id: int,
|
||||
help_voice_channel_id: int,
|
||||
team_channel_id: int,
|
||||
login_message_channel_id: int,
|
||||
server_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._id = id
|
||||
self._message_delete_timer = message_delete_timer
|
||||
self._notification_chat_id = notification_chat_id
|
||||
self._max_voice_state_hours = max_voice_state_hours
|
||||
self._xp_per_message = xp_per_message
|
||||
self._xp_per_reaction = xp_per_reaction
|
||||
self._max_message_xp_per_hour = max_message_xp_per_hour
|
||||
self._xp_per_ontime_hour = xp_per_ontime_hour
|
||||
self._xp_per_event_participation = xp_per_event_participation
|
||||
self._xp_per_achievement = xp_per_achievement
|
||||
self._afk_command_channel_id = afk_command_channel_id
|
||||
self._help_voice_channel_id = help_voice_channel_id
|
||||
self._team_channel_id = team_channel_id
|
||||
self._login_message_channel_id = login_message_channel_id
|
||||
self._server_id = server_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def message_delete_timer(self) -> int:
|
||||
return self._message_delete_timer
|
||||
|
||||
@property
|
||||
def notification_chat_id(self) -> int:
|
||||
return self._notification_chat_id
|
||||
|
||||
@property
|
||||
def max_voice_state_hours(self) -> int:
|
||||
return self._max_voice_state_hours
|
||||
|
||||
@property
|
||||
def xp_per_message(self) -> int:
|
||||
return self._xp_per_message
|
||||
|
||||
@property
|
||||
def xp_per_reaction(self) -> int:
|
||||
return self._xp_per_reaction
|
||||
|
||||
@property
|
||||
def max_message_xp_per_hour(self) -> int:
|
||||
return self._max_message_xp_per_hour
|
||||
|
||||
@property
|
||||
def xp_per_ontime_hour(self) -> int:
|
||||
return self._xp_per_ontime_hour
|
||||
|
||||
@property
|
||||
def xp_per_event_participation(self) -> int:
|
||||
return self._xp_per_event_participation
|
||||
|
||||
@property
|
||||
def xp_per_achievement(self) -> int:
|
||||
return self._xp_per_achievement
|
||||
|
||||
@property
|
||||
def afk_command_channel_id(self) -> int:
|
||||
return self._afk_command_channel_id
|
||||
|
||||
@property
|
||||
def help_voice_channel_id(self) -> int:
|
||||
return self._help_voice_channel_id
|
||||
|
||||
@property
|
||||
def team_channel_id(self) -> int:
|
||||
return self._team_channel_id
|
||||
|
||||
@property
|
||||
def login_message_channel_id(self) -> int:
|
||||
return self._login_message_channel_id
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
return self._server_id
|
100
kdb-bot/src/bot_data/model/server_team_role_ids_config.py
Normal file
100
kdb-bot/src/bot_data/model/server_team_role_ids_config.py
Normal file
@ -0,0 +1,100 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
|
||||
|
||||
class ServerTeamRoleIdsConfig(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
role_id: int,
|
||||
team_member_type: TeamMemberTypeEnum,
|
||||
server_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._role_id = role_id
|
||||
self._team_member_type = team_member_type
|
||||
self._server_id = server_id
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def role_id(self) -> int:
|
||||
return self._role_id
|
||||
|
||||
@property
|
||||
def team_member_type(self) -> TeamMemberTypeEnum:
|
||||
return self._team_member_type
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_ServerTeamRoleIds`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_ServerTeamRoleIds`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(server_id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_ServerTeamRoleIds`
|
||||
WHERE `ServerId` = {server_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `CFG_ServerTeamRoleIds` (
|
||||
`RoleId`,
|
||||
`TeamMemberType`,
|
||||
`ServerId`
|
||||
) VALUES (
|
||||
{self._role_id},
|
||||
'{self._team_member_type.value}',
|
||||
{self._server_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `CFG_ServerTeamRoleIds`
|
||||
SET `RoleId` = {self._role_id},
|
||||
`TeamMemberType` = '{self._team_member_type.value}',
|
||||
`ServerId` = {self._server_id}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `CFG_ServerTeamRoleIds`
|
||||
WHERE `RoleId` = {self._role_id};
|
||||
"""
|
||||
)
|
6
kdb-bot/src/bot_data/model/team_member_type_enum.py
Normal file
6
kdb-bot/src/bot_data/model/team_member_type_enum.py
Normal file
@ -0,0 +1,6 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class TeamMemberTypeEnum(Enum):
|
||||
moderator = "Moderator"
|
||||
admin = "Admin"
|
137
kdb-bot/src/bot_data/model/technician_config.py
Normal file
137
kdb-bot/src/bot_data/model/technician_config.py
Normal file
@ -0,0 +1,137 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class TechnicianConfig(TableABC, ConfigurationModelABC):
|
||||
def __init__(
|
||||
self,
|
||||
help_command_reference_url: str,
|
||||
wait_for_restart: int,
|
||||
wait_for_shutdown: int,
|
||||
cache_max_messages: int,
|
||||
technician_ids: List[int],
|
||||
ping_urls: List[str],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._help_command_reference_url = help_command_reference_url
|
||||
self._wait_for_restart = wait_for_restart
|
||||
self._wait_for_shutdown = wait_for_shutdown
|
||||
self._cache_max_messages = cache_max_messages
|
||||
self._technician_ids = technician_ids
|
||||
self._ping_urls = ping_urls
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def help_command_reference_url(self) -> str:
|
||||
return self._help_command_reference_url
|
||||
|
||||
@help_command_reference_url.setter
|
||||
def help_command_reference_url(self, value: str):
|
||||
self._help_command_reference_url = value
|
||||
|
||||
@property
|
||||
def wait_for_restart(self) -> int:
|
||||
return self._wait_for_restart
|
||||
|
||||
@wait_for_restart.setter
|
||||
def wait_for_restart(self, value: int):
|
||||
self._wait_for_restart = value
|
||||
|
||||
@property
|
||||
def wait_for_shutdown(self) -> int:
|
||||
return self._wait_for_shutdown
|
||||
|
||||
@wait_for_shutdown.setter
|
||||
def wait_for_shutdown(self, value: int):
|
||||
self._wait_for_shutdown = value
|
||||
|
||||
@property
|
||||
def cache_max_messages(self) -> int:
|
||||
return self._cache_max_messages
|
||||
|
||||
@cache_max_messages.setter
|
||||
def cache_max_messages(self, value: int):
|
||||
self._cache_max_messages = value
|
||||
|
||||
@property
|
||||
def technician_ids(self) -> List[int]:
|
||||
return self._technician_ids
|
||||
|
||||
@technician_ids.setter
|
||||
def technician_ids(self, value: List[int]):
|
||||
self._technician_ids = value
|
||||
|
||||
@property
|
||||
def ping_urls(self) -> List[str]:
|
||||
return self._ping_urls
|
||||
|
||||
@ping_urls.setter
|
||||
def ping_urls(self, value: List[str]):
|
||||
self._ping_urls = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_Technician`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_Technician`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `CFG_Technician` (
|
||||
`HelpCommandReferenceUrl`, `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`
|
||||
) VALUES (
|
||||
'{self._help_command_reference_url}',
|
||||
{self._wait_for_restart},
|
||||
{self._wait_for_shutdown},
|
||||
{self._cache_max_messages}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `CFG_Technician`
|
||||
SET `HelpCommandReferenceUrl` = '{self._help_command_reference_url}',
|
||||
`WaitForRestart` = {self._wait_for_restart},
|
||||
`WaitForShutdown` = {self._wait_for_shutdown},
|
||||
`CacheMaxMessages` = {self._cache_max_messages}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `CFG_Technician`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
58
kdb-bot/src/bot_data/model/technician_config_history.py
Normal file
58
kdb-bot/src/bot_data/model/technician_config_history.py
Normal file
@ -0,0 +1,58 @@
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class TechnicianConfigHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
help_command_reference_url: str,
|
||||
wait_for_restart: int,
|
||||
wait_for_shutdown: int,
|
||||
cache_max_messages: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._id = id
|
||||
self._help_command_reference_url = help_command_reference_url
|
||||
self._wait_for_restart = wait_for_restart
|
||||
self._wait_for_shutdown = wait_for_shutdown
|
||||
self._cache_max_messages = cache_max_messages
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def help_command_reference_url(self) -> str:
|
||||
return self._help_command_reference_url
|
||||
|
||||
@help_command_reference_url.setter
|
||||
def help_command_reference_url(self, value: str):
|
||||
self._help_command_reference_url = value
|
||||
|
||||
@property
|
||||
def wait_for_restart(self) -> int:
|
||||
return self._wait_for_restart
|
||||
|
||||
@wait_for_restart.setter
|
||||
def wait_for_restart(self, value: int):
|
||||
self._wait_for_restart = value
|
||||
|
||||
@property
|
||||
def wait_for_shutdown(self) -> int:
|
||||
return self._wait_for_shutdown
|
||||
|
||||
@wait_for_shutdown.setter
|
||||
def wait_for_shutdown(self, value: int):
|
||||
self._wait_for_shutdown = value
|
||||
|
||||
@property
|
||||
def cache_max_messages(self) -> int:
|
||||
return self._cache_max_messages
|
||||
|
||||
@cache_max_messages.setter
|
||||
def cache_max_messages(self, value: int):
|
||||
self._cache_max_messages = value
|
79
kdb-bot/src/bot_data/model/technician_id_config.py
Normal file
79
kdb-bot/src/bot_data/model/technician_id_config.py
Normal file
@ -0,0 +1,79 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class TechnicianIdConfig(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
technician_id: str,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._technician_id = technician_id
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def technician_id(self) -> str:
|
||||
return self._technician_id
|
||||
|
||||
@technician_id.setter
|
||||
def technician_id(self, value: str):
|
||||
self._technician_id = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_TechnicianIds`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_TechnicianIds`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `CFG_TechnicianIds` (
|
||||
`TechnicianId`
|
||||
) VALUES (
|
||||
'{self._technician_id}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `CFG_TechnicianIds`
|
||||
SET `TechnicianId` = '{self._technician_id}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `CFG_TechnicianIds`
|
||||
WHERE `TechnicianId` = {self._technician_id};
|
||||
"""
|
||||
)
|
28
kdb-bot/src/bot_data/model/technician_id_config_history.py
Normal file
28
kdb-bot/src/bot_data/model/technician_id_config_history.py
Normal file
@ -0,0 +1,28 @@
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class TechnicianIdConfigHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
technician_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._id = id
|
||||
self._technician_id = technician_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def technician_id(self) -> int:
|
||||
return self._technician_id
|
||||
|
||||
@technician_id.setter
|
||||
def technician_id(self, value: int):
|
||||
self._technician_id = value
|
79
kdb-bot/src/bot_data/model/technician_ping_url_config.py
Normal file
79
kdb-bot/src/bot_data/model/technician_ping_url_config.py
Normal file
@ -0,0 +1,79 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class TechnicianPingUrlConfig(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
ping_url: str,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._ping_url = ping_url
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def ping_url(self) -> str:
|
||||
return self._ping_url
|
||||
|
||||
@ping_url.setter
|
||||
def ping_url(self, value: str):
|
||||
self._ping_url = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_TechnicianPingUrls`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `CFG_TechnicianPingUrls`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `CFG_TechnicianPingUrls` (
|
||||
`URL`
|
||||
) VALUES (
|
||||
'{self._ping_url}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `CFG_TechnicianPingUrls`
|
||||
SET `URL` = '{self._ping_url}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `CFG_TechnicianPingUrls`
|
||||
WHERE `URL` = '{self._ping_url}';
|
||||
"""
|
||||
)
|
@ -0,0 +1,28 @@
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class TechnicianPingUrlConfigHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
url: str,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._id = id
|
||||
self._url = url
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return self._url
|
||||
|
||||
@url.setter
|
||||
def url(self, value: str):
|
||||
self._url = value
|
125
kdb-bot/src/bot_data/service/server_config_repository_service.py
Normal file
125
kdb-bot/src/bot_data/service/server_config_repository_service.py
Normal file
@ -0,0 +1,125 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.model.server_afk_channel_ids_config import ServerAFKChannelIdsConfig
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
|
||||
|
||||
class ServerConfigRepositoryService(ServerConfigRepositoryABC):
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC):
|
||||
ServerConfigRepositoryABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
self._servers = servers
|
||||
|
||||
def _get_team_role_ids(self, server_id: int) -> List[ServerTeamRoleIdsConfig]:
|
||||
ids = List(ServerTeamRoleIdsConfig)
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {ServerTeamRoleIdsConfig.get_select_by_server_id_string(server_id)}"
|
||||
)
|
||||
results = self._context.select(ServerTeamRoleIdsConfig.get_select_by_server_id_string(server_id))
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f"Got ServerTeamRoleIdsConfig with id {result[0]}")
|
||||
ids.append(
|
||||
ServerTeamRoleIdsConfig(
|
||||
result[1], TeamMemberTypeEnum(result[2]), result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
)
|
||||
|
||||
return ids
|
||||
|
||||
def _get_afk_channel_ids(self, server_id: int) -> List[int]:
|
||||
urls = List(int)
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {ServerAFKChannelIdsConfig.get_select_by_server_id_string(server_id)}",
|
||||
)
|
||||
results = self._context.select(ServerAFKChannelIdsConfig.get_select_by_server_id_string(server_id))
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f"Got ServerAFKChannelIdsConfig with id {result[0]}")
|
||||
urls.append(result[1])
|
||||
|
||||
return urls
|
||||
|
||||
def _from_result(self, result: tuple) -> ServerConfig:
|
||||
return ServerConfig(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
result[6],
|
||||
result[7],
|
||||
result[8],
|
||||
result[9],
|
||||
result[10],
|
||||
result[11],
|
||||
result[12],
|
||||
result[13],
|
||||
self._servers.get_server_by_id(result[14]),
|
||||
self._get_afk_channel_ids(result[14]),
|
||||
self._get_team_role_ids(result[14]),
|
||||
result[15],
|
||||
result[16],
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def does_server_config_exists(self, server_id: int) -> bool:
|
||||
self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_id_string(server_id)}")
|
||||
result = self._context.select(ServerConfig.get_select_by_id_string(server_id))
|
||||
|
||||
return len(result) > 0
|
||||
|
||||
def get_server_config_by_server(self, server_id: int) -> ServerConfig:
|
||||
self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_id_string(server_id)}")
|
||||
result = self._context.select(ServerConfig.get_select_by_id_string(server_id))[0]
|
||||
|
||||
return self._from_result(result)
|
||||
|
||||
def get_server_config_by_id(self, config_id: int) -> ServerConfig:
|
||||
self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_id_string(config_id)}")
|
||||
result = self._context.select(ServerConfig.get_select_by_id_string(config_id))[0]
|
||||
|
||||
return self._from_result(result)
|
||||
|
||||
def add_server_config(self, server_config: ServerConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_config.insert_string}")
|
||||
self._context.cursor.execute(server_config.insert_string)
|
||||
|
||||
def update_server_config(self, server_config: ServerConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_config.udpate_string}")
|
||||
self._context.cursor.execute(server_config.udpate_string)
|
||||
|
||||
def delete_server_config(self, server_config: ServerConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_config.delete_string}")
|
||||
self._context.cursor.execute(server_config.delete_string)
|
||||
|
||||
def add_server_team_role_id_config(self, server_team_role_id: ServerTeamRoleIdsConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_team_role_id.insert_string}")
|
||||
self._context.cursor.execute(server_team_role_id.insert_string)
|
||||
|
||||
def update_server_team_role_id_config(self, server_team_role_id: ServerTeamRoleIdsConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_team_role_id.udpate_string}")
|
||||
self._context.cursor.execute(server_team_role_id.udpate_string)
|
||||
|
||||
def delete_server_team_role_id_config(self, server_team_role_id: ServerTeamRoleIdsConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_team_role_id.delete_string}")
|
||||
self._context.cursor.execute(server_team_role_id.delete_string)
|
||||
|
||||
def add_server_afk_channel_config(self, server_afk_channel: ServerAFKChannelIdsConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_afk_channel.insert_string}")
|
||||
self._context.cursor.execute(server_afk_channel.insert_string)
|
||||
|
||||
def update_server_afk_channel_config(self, server_afk_channel: ServerAFKChannelIdsConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_afk_channel.udpate_string}")
|
||||
self._context.cursor.execute(server_afk_channel.udpate_string)
|
||||
|
||||
def delete_server_afk_channel_config(self, server_afk_channel: ServerAFKChannelIdsConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server_afk_channel.delete_string}")
|
||||
self._context.cursor.execute(server_afk_channel.delete_string)
|
62
kdb-bot/src/bot_data/service/server_config_seeder.py
Normal file
62
kdb-bot/src/bot_data/service/server_config_seeder.py
Normal file
@ -0,0 +1,62 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.container import Guild
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.data_seeder_abc import DataSeederABC
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
|
||||
|
||||
class ServerConfigSeeder(DataSeederABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
server_config: ServerConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
DataSeederABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._servers = servers
|
||||
self._server_config = server_config
|
||||
self._db = db
|
||||
|
||||
async def seed(self):
|
||||
try:
|
||||
for guild in self._bot.guilds:
|
||||
guild: Guild = guild
|
||||
server = self._servers.get_server_by_discord_id(guild.id)
|
||||
if self._server_config.does_server_config_exists(server.id):
|
||||
continue
|
||||
|
||||
config = ServerConfig(
|
||||
6,
|
||||
guild.system_channel.id,
|
||||
6,
|
||||
1,
|
||||
1,
|
||||
20,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
server,
|
||||
[],
|
||||
[],
|
||||
)
|
||||
|
||||
self._server_config.add_server_config(config)
|
||||
|
||||
self._db.save_changes()
|
||||
self._logger.debug(__name__, "Seeded technician config")
|
||||
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Seeding technician config failed", e)
|
@ -0,0 +1,97 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from bot_data.model.technician_id_config import TechnicianIdConfig
|
||||
from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig
|
||||
|
||||
|
||||
class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC):
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC):
|
||||
TechnicianConfigRepositoryABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
def _get_technician_ids(self) -> List[int]:
|
||||
ids = List(int)
|
||||
self._logger.trace(__name__, f"Send SQL command: {TechnicianIdConfig.get_select_all_string()}")
|
||||
results = self._context.select(TechnicianIdConfig.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f"Got TechnicianId with id {result[0]}")
|
||||
ids.append(result[1])
|
||||
|
||||
return ids
|
||||
|
||||
def _get_technician_ping_urls(self) -> List[str]:
|
||||
urls = List(str)
|
||||
self._logger.trace(__name__, f"Send SQL command: {TechnicianPingUrlConfig.get_select_all_string()}")
|
||||
results = self._context.select(TechnicianPingUrlConfig.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f"Got TechnicianPingUrl with id {result[0]}")
|
||||
urls.append(result[1])
|
||||
|
||||
return urls
|
||||
|
||||
def _from_result(self, result: tuple) -> TechnicianConfig:
|
||||
return TechnicianConfig(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
self._get_technician_ids(),
|
||||
self._get_technician_ping_urls(),
|
||||
result[5],
|
||||
result[6],
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def does_technician_config_exists(self) -> bool:
|
||||
self._logger.trace(__name__, f"Send SQL command: {TechnicianConfig.get_select_all_string()}")
|
||||
result = self._context.select(TechnicianConfig.get_select_all_string())
|
||||
|
||||
return len(result) > 0
|
||||
|
||||
def get_technician_config(self) -> TechnicianConfig:
|
||||
self._logger.trace(__name__, f"Send SQL command: {TechnicianConfig.get_select_all_string()}")
|
||||
result = self._context.select(TechnicianConfig.get_select_all_string())[0]
|
||||
|
||||
return self._from_result(result)
|
||||
|
||||
def add_technician_config(self, technician_config: TechnicianConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_config.insert_string}")
|
||||
self._context.cursor.execute(technician_config.insert_string)
|
||||
|
||||
def update_technician_config(self, technician_config: TechnicianConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_config.udpate_string}")
|
||||
self._context.cursor.execute(technician_config.udpate_string)
|
||||
|
||||
def delete_technician_config(self, technician_config: TechnicianConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_config.delete_string}")
|
||||
self._context.cursor.execute(technician_config.delete_string)
|
||||
|
||||
def add_technician_id_config(self, technician_id: TechnicianIdConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_id.insert_string}")
|
||||
self._context.cursor.execute(technician_id.insert_string)
|
||||
|
||||
def update_technician_id_config(self, technician_id: TechnicianIdConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_id.udpate_string}")
|
||||
self._context.cursor.execute(technician_id.udpate_string)
|
||||
|
||||
def delete_technician_id_config(self, technician_id: TechnicianIdConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_id.delete_string}")
|
||||
self._context.cursor.execute(technician_id.delete_string)
|
||||
|
||||
def add_technician_ping_url_config(self, technician_ping_url: TechnicianPingUrlConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_ping_url.insert_string}")
|
||||
self._context.cursor.execute(technician_ping_url.insert_string)
|
||||
|
||||
def update_technician_ping_url_config(self, technician_ping_url: TechnicianPingUrlConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_ping_url.udpate_string}")
|
||||
self._context.cursor.execute(technician_ping_url.udpate_string)
|
||||
|
||||
def delete_technician_ping_url_config(self, technician_ping_url: TechnicianPingUrlConfig):
|
||||
self._logger.trace(__name__, f"Send SQL command: {technician_ping_url.delete_string}")
|
||||
self._context.cursor.execute(technician_ping_url.delete_string)
|
49
kdb-bot/src/bot_data/service/technician_config_seeder.py
Normal file
49
kdb-bot/src/bot_data/service/technician_config_seeder.py
Normal file
@ -0,0 +1,49 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.data_seeder_abc import DataSeederABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from bot_data.model.technician_id_config import TechnicianIdConfig
|
||||
from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig
|
||||
|
||||
|
||||
class TechnicianConfigSeeder(DataSeederABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
technician_config: TechnicianConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
DataSeederABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._technician_config = technician_config
|
||||
self._db = db
|
||||
|
||||
async def seed(self):
|
||||
try:
|
||||
if self._technician_config.does_technician_config_exists():
|
||||
return
|
||||
|
||||
config = TechnicianConfig(
|
||||
"https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle",
|
||||
8,
|
||||
8,
|
||||
1000000,
|
||||
List(int, [240160344557879316]),
|
||||
List(str, ["www.google.com", "www.sh-edraft.de", "www.keksdose-gaming.de"]),
|
||||
)
|
||||
|
||||
self._technician_config.add_technician_config(config)
|
||||
for technician in config.technician_ids:
|
||||
self._technician_config.add_technician_id_config(TechnicianIdConfig(technician))
|
||||
|
||||
for url in config.ping_urls:
|
||||
self._technician_config.add_technician_ping_url_config(TechnicianPingUrlConfig(url))
|
||||
|
||||
self._db.save_changes()
|
||||
self._logger.debug(__name__, "Seeded technician config")
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Seeding technician config failed", e)
|
@ -24,6 +24,8 @@ from bot_graphql.mutations.achievement_mutation import AchievementMutation
|
||||
from bot_graphql.mutations.auto_role_mutation import AutoRoleMutation
|
||||
from bot_graphql.mutations.auto_role_rule_mutation import AutoRoleRuleMutation
|
||||
from bot_graphql.mutations.level_mutation import LevelMutation
|
||||
from bot_graphql.mutations.server_config_mutation import ServerConfigMutation
|
||||
from bot_graphql.mutations.technician_config_mutation import TechnicianConfigMutation
|
||||
from bot_graphql.mutations.user_joined_game_server_mutation import UserJoinedGameServerMutation
|
||||
from bot_graphql.mutations.user_mutation import UserMutation
|
||||
from bot_graphql.queries.achievement_attribute_query import AchievementAttributeQuery
|
||||
@ -40,8 +42,13 @@ from bot_graphql.queries.known_user_history_query import KnownUserHistoryQuery
|
||||
from bot_graphql.queries.known_user_query import KnownUserQuery
|
||||
from bot_graphql.queries.level_history_query import LevelHistoryQuery
|
||||
from bot_graphql.queries.level_query import LevelQuery
|
||||
from bot_graphql.queries.server_config_query import ServerConfigQuery
|
||||
from bot_graphql.queries.server_history_query import ServerHistoryQuery
|
||||
from bot_graphql.queries.server_query import ServerQuery
|
||||
from bot_graphql.queries.technician_config_history_query import TechnicianConfigHistoryQuery
|
||||
from bot_graphql.queries.technician_config_query import TechnicianConfigQuery
|
||||
from bot_graphql.queries.technician_id_config_history_query import TechnicianIdConfigHistoryQuery
|
||||
from bot_graphql.queries.technician_ping_url_config_history_query import TechnicianPingUrlConfigHistoryQuery
|
||||
from bot_graphql.queries.user_history_query import UserHistoryQuery
|
||||
from bot_graphql.queries.user_joined_game_server_history_query import UserJoinedGameServerHistoryQuery
|
||||
from bot_graphql.queries.user_joined_game_server_query import UserJoinedGameServerQuery
|
||||
@ -81,8 +88,13 @@ class GraphQLModule(ModuleABC):
|
||||
services.add_transient(QueryABC, KnownUserQuery)
|
||||
services.add_transient(QueryABC, LevelHistoryQuery)
|
||||
services.add_transient(QueryABC, LevelQuery)
|
||||
services.add_transient(QueryABC, ServerConfigQuery)
|
||||
services.add_transient(QueryABC, ServerHistoryQuery)
|
||||
services.add_transient(QueryABC, ServerQuery)
|
||||
services.add_transient(QueryABC, TechnicianConfigQuery)
|
||||
services.add_transient(QueryABC, TechnicianConfigHistoryQuery)
|
||||
services.add_transient(QueryABC, TechnicianPingUrlConfigHistoryQuery)
|
||||
services.add_transient(QueryABC, TechnicianIdConfigHistoryQuery)
|
||||
services.add_transient(QueryABC, GameServerQuery)
|
||||
services.add_transient(QueryABC, UserHistoryQuery)
|
||||
services.add_transient(QueryABC, UserQuery)
|
||||
@ -112,5 +124,7 @@ class GraphQLModule(ModuleABC):
|
||||
services.add_transient(QueryABC, UserMutation)
|
||||
services.add_transient(QueryABC, AchievementMutation)
|
||||
services.add_transient(QueryABC, UserJoinedGameServerMutation)
|
||||
services.add_transient(QueryABC, TechnicianConfigMutation)
|
||||
services.add_transient(QueryABC, ServerConfigMutation)
|
||||
|
||||
services.add_transient(SeederService)
|
||||
|
@ -5,4 +5,6 @@ type Mutation {
|
||||
user: UserMutation
|
||||
userJoinedGameServer: UserJoinedGameServerMutation
|
||||
achievement: AchievementMutation
|
||||
technicianConfig: TechnicianConfigMutation
|
||||
serverConfig: ServerConfigMutation
|
||||
}
|
@ -37,5 +37,7 @@ type Query {
|
||||
achievementAttributes: [AchievementAttribute]
|
||||
achievementOperators: [String]
|
||||
|
||||
technicianConfig: TechnicianConfig
|
||||
|
||||
guilds(filter: GuildFilter): [Guild]
|
||||
}
|
@ -31,6 +31,8 @@ type Server implements TableWithHistoryQuery {
|
||||
achievementCount: Int
|
||||
achievements(filter: AchievementFilter, page: Page, sort: Sort): [Achievement]
|
||||
|
||||
config: ServerConfig
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
|
||||
|
94
kdb-bot/src/bot_graphql/model/serverConfig.gql
Normal file
94
kdb-bot/src/bot_graphql/model/serverConfig.gql
Normal file
@ -0,0 +1,94 @@
|
||||
type ServerConfig implements TableWithHistoryQuery {
|
||||
id: ID
|
||||
messageDeleteTimer: Int
|
||||
notificationChatId: String
|
||||
maxVoiceStateHours: Int
|
||||
xpPerMessage: Int
|
||||
xpPerReaction: Int
|
||||
maxMessageXpPerHour: Int
|
||||
xpPerOntimeHour: Int
|
||||
xpPerEventParticipation: Int
|
||||
xpPerAchievement: Int
|
||||
afkCommandChannelId: String
|
||||
helpVoiceChannelId: String
|
||||
teamChannelId: String
|
||||
loginMessageChannelId: String
|
||||
|
||||
afkChannelIds: [String]
|
||||
moderatorRoleIds: [String]
|
||||
adminRoleIds: [String]
|
||||
|
||||
server: Server
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
|
||||
history: [ServerConfigHistory]
|
||||
}
|
||||
|
||||
type ServerConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
messageDeleteTimer: Int
|
||||
notificationChatId: String
|
||||
maxVoiceStateHours: Int
|
||||
xpPerMessage: Int
|
||||
xpPerReaction: Int
|
||||
maxMessageXpPerHour: Int
|
||||
xpPerOntimeHour: Int
|
||||
xpPerEventParticipation: Int
|
||||
xpPerAchievement: Int
|
||||
afkCommandChannelId: String
|
||||
helpVoiceChannelId: String
|
||||
teamChannelId: String
|
||||
loginMessageChannelId: String
|
||||
|
||||
serverId: ID
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type ServerAFKChannelIdsConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
channelId: String
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type ServerTeamRoleIdsConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
roleId: String
|
||||
teamMemberType: String
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type ServerConfigMutation {
|
||||
updateServerConfig(input: ServerConfigInput!): ServerConfig
|
||||
}
|
||||
|
||||
input ServerConfigInput {
|
||||
id: ID
|
||||
messageDeleteTimer: Int
|
||||
notificationChatId: String
|
||||
maxVoiceStateHours: Int
|
||||
xpPerMessage: Int
|
||||
xpPerReaction: Int
|
||||
maxMessageXpPerHour: Int
|
||||
xpPerOntimeHour: Int
|
||||
xpPerEventParticipation: Int
|
||||
xpPerAchievement: Int
|
||||
afkCommandChannelId: String
|
||||
helpVoiceChannelId: String
|
||||
teamChannelId: String
|
||||
loginMessageChannelId: String
|
||||
|
||||
afkChannelIds: [String]
|
||||
moderatorRoleIds: [String]
|
||||
adminRoleIds: [String]
|
||||
}
|
60
kdb-bot/src/bot_graphql/model/technicianConfig.gql
Normal file
60
kdb-bot/src/bot_graphql/model/technicianConfig.gql
Normal file
@ -0,0 +1,60 @@
|
||||
type TechnicianConfig implements TableWithHistoryQuery {
|
||||
id: ID
|
||||
helpCommandReferenceUrl: String
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
pingURLs: [String]
|
||||
technicianIds: [String]
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
|
||||
history: [TechnicianConfigHistory]
|
||||
pingURLHistory: [TechnicianPingUrlConfigHistory]
|
||||
technicianIdHistory: [TechnicianIdConfigHistory]
|
||||
}
|
||||
|
||||
type TechnicianConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
helpCommandReferenceUrl: String
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type TechnicianPingUrlConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
url: String
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type TechnicianIdConfigHistory implements HistoryTableQuery {
|
||||
id: ID
|
||||
technicianId: String
|
||||
|
||||
deleted: Boolean
|
||||
dateFrom: String
|
||||
dateTo: String
|
||||
}
|
||||
|
||||
type TechnicianConfigMutation {
|
||||
updateTechnicianConfig(input: TechnicianConfigInput!): TechnicianConfig
|
||||
}
|
||||
|
||||
input TechnicianConfigInput {
|
||||
id: ID
|
||||
helpCommandReferenceUrl: String
|
||||
waitForRestart: Int
|
||||
waitForShutdown: Int
|
||||
cacheMaxMessages: Int
|
||||
pingURLs: [String]
|
||||
technicianIds: [String]
|
||||
}
|
@ -4,6 +4,8 @@ from bot_graphql.mutations.achievement_mutation import AchievementMutation
|
||||
from bot_graphql.mutations.auto_role_mutation import AutoRoleMutation
|
||||
from bot_graphql.mutations.auto_role_rule_mutation import AutoRoleRuleMutation
|
||||
from bot_graphql.mutations.level_mutation import LevelMutation
|
||||
from bot_graphql.mutations.server_config_mutation import ServerConfigMutation
|
||||
from bot_graphql.mutations.technician_config_mutation import TechnicianConfigMutation
|
||||
from bot_graphql.mutations.user_joined_game_server_mutation import UserJoinedGameServerMutation
|
||||
from bot_graphql.mutations.user_mutation import UserMutation
|
||||
|
||||
@ -17,6 +19,8 @@ class Mutation(MutationType):
|
||||
user_mutation: UserMutation,
|
||||
achievement_mutation: AchievementMutation,
|
||||
user_joined_game_server: UserJoinedGameServerMutation,
|
||||
technician_config: TechnicianConfigMutation,
|
||||
server_config: ServerConfigMutation,
|
||||
):
|
||||
MutationType.__init__(self)
|
||||
|
||||
@ -26,3 +30,5 @@ class Mutation(MutationType):
|
||||
self.set_field("user", lambda *_: user_mutation)
|
||||
self.set_field("achievement", lambda *_: achievement_mutation)
|
||||
self.set_field("userJoinedGameServer", lambda *_: user_joined_game_server)
|
||||
self.set_field("technicianConfig", lambda *_: technician_config)
|
||||
self.set_field("serverConfig", lambda *_: server_config)
|
||||
|
163
kdb-bot/src/bot_graphql/mutations/server_config_mutation.py
Normal file
163
kdb-bot/src/bot_graphql/mutations/server_config_mutation.py
Normal file
@ -0,0 +1,163 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.model.server_afk_channel_ids_config import ServerAFKChannelIdsConfig
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
|
||||
|
||||
class ServerConfigMutation(QueryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: ApiLogger,
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
server_configs: ServerConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
QueryABC.__init__(self, "ServerConfigMutation")
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._servers = servers
|
||||
self._server_configs = server_configs
|
||||
self._db = db
|
||||
|
||||
self.set_field("updateServerConfig", self.resolve_update_server_config)
|
||||
|
||||
def resolve_update_server_config(self, *_, input: dict):
|
||||
if "id" not in input:
|
||||
raise ValueError("Id not set")
|
||||
|
||||
server_config = self._server_configs.get_server_config_by_server(input["id"])
|
||||
self._can_user_mutate_data(server_config, UserRoleEnum.admin)
|
||||
|
||||
server_config.message_delete_timer = (
|
||||
input["messageDeleteTimer"] if "messageDeleteTimer" in input else server_config.message_delete_timer
|
||||
)
|
||||
server_config.notification_chat_id = (
|
||||
input["notificationChatId"] if "notificationChatId" in input else server_config.notification_chat_id
|
||||
)
|
||||
server_config.max_voice_state_hours = (
|
||||
input["maxVoiceStateHours"] if "maxVoiceStateHours" in input else server_config.max_voice_state_hours
|
||||
)
|
||||
server_config.xp_per_message = (
|
||||
input["xpPerMessage"] if "xpPerMessage" in input else server_config.xp_per_message
|
||||
)
|
||||
server_config.xp_per_reaction = (
|
||||
input["xpPerReaction"] if "xpPerReaction" in input else server_config.xp_per_reaction
|
||||
)
|
||||
server_config.max_message_xp_per_hour = (
|
||||
input["maxMessageXpPerHour"] if "maxMessageXpPerHour" in input else server_config.max_message_xp_per_hour
|
||||
)
|
||||
server_config.xp_per_ontime_hour = (
|
||||
input["xpPerOntimeHour"] if "xpPerOntimeHour" in input else server_config.xp_per_ontime_hour
|
||||
)
|
||||
server_config.xp_per_event_participation = (
|
||||
input["xpPerEventParticipation"]
|
||||
if "xpPerEventParticipation" in input
|
||||
else server_config.xp_per_event_participation
|
||||
)
|
||||
server_config.xp_per_achievement = (
|
||||
input["xpPerAchievement"] if "xpPerAchievement" in input else server_config.xp_per_achievement
|
||||
)
|
||||
server_config.afk_command_channel_id = (
|
||||
input["afkCommandChannelId"] if "afkCommandChannelId" in input else server_config.afk_command_channel_id
|
||||
)
|
||||
server_config.help_voice_channel_id = (
|
||||
input["helpVoiceChannelId"] if "helpVoiceChannelId" in input else server_config.help_voice_channel_id
|
||||
)
|
||||
server_config.team_channel_id = (
|
||||
input["teamChannelId"] if "teamChannelId" in input else server_config.team_channel_id
|
||||
)
|
||||
server_config.login_message_channel_id = (
|
||||
input["loginMessageChannelId"]
|
||||
if "loginMessageChannelId" in input
|
||||
else server_config.login_message_channel_id
|
||||
)
|
||||
server_config.afk_channel_ids = (
|
||||
List(int).extend([int(x) for x in input["afkChannelIds"]])
|
||||
if "afkChannelIds" in input
|
||||
else server_config.afk_channel_ids
|
||||
)
|
||||
|
||||
team_role_ids = List(ServerTeamRoleIdsConfig)
|
||||
if "moderatorRoleIds" in input:
|
||||
team_role_ids.extend(
|
||||
[
|
||||
ServerTeamRoleIdsConfig(x, TeamMemberTypeEnum.moderator, server_config.server.id)
|
||||
for x in input["moderatorRoleIds"]
|
||||
]
|
||||
)
|
||||
else:
|
||||
team_role_ids.extend(
|
||||
server_config.team_role_ids.where(lambda x: x.team_member_type == TeamMemberTypeEnum.moderator)
|
||||
)
|
||||
|
||||
if "adminRoleIds" in input:
|
||||
team_role_ids.extend(
|
||||
[
|
||||
ServerTeamRoleIdsConfig(x, TeamMemberTypeEnum.admin, server_config.server.id)
|
||||
for x in input["adminRoleIds"]
|
||||
]
|
||||
)
|
||||
else:
|
||||
team_role_ids.extend(
|
||||
server_config.team_role_ids.where(lambda x: x.team_member_type == TeamMemberTypeEnum.admin)
|
||||
)
|
||||
|
||||
self._server_configs.update_server_config(server_config)
|
||||
if "afkChannelIds" in input:
|
||||
self._update_afk_channel_ids(server_config)
|
||||
|
||||
if "moderatorRoleIds" in input or "adminRoleIds" in input:
|
||||
server_config.team_role_ids = team_role_ids
|
||||
self._update_team_role_ids(server_config)
|
||||
|
||||
self._db.save_changes()
|
||||
return server_config
|
||||
|
||||
def _update_afk_channel_ids(self, new_config: ServerConfig):
|
||||
old_config = self._server_configs.get_server_config_by_id(new_config.server.id)
|
||||
for channel_id in old_config.afk_channel_ids:
|
||||
if channel_id in new_config.afk_channel_ids:
|
||||
continue
|
||||
|
||||
self._server_configs.delete_server_afk_channel_config(
|
||||
ServerAFKChannelIdsConfig(channel_id, new_config.server.id)
|
||||
)
|
||||
|
||||
for channel_id in new_config.afk_channel_ids:
|
||||
if channel_id in old_config.afk_channel_ids:
|
||||
continue
|
||||
|
||||
self._server_configs.add_server_afk_channel_config(
|
||||
ServerAFKChannelIdsConfig(channel_id, new_config.server.id)
|
||||
)
|
||||
|
||||
def _update_team_role_ids(self, new_config: ServerConfig):
|
||||
old_config = self._server_configs.get_server_config_by_id(new_config.server.id)
|
||||
for role_id in old_config.team_role_ids:
|
||||
if role_id.role_id in new_config.team_role_ids.select(lambda x: int(x.role_id)):
|
||||
continue
|
||||
|
||||
self._server_configs.delete_server_team_role_id_config(role_id)
|
||||
|
||||
for role_id in new_config.team_role_ids:
|
||||
guild = self._bot.get_guild(new_config.server.discord_id)
|
||||
role = guild.get_role(int(role_id.role_id))
|
||||
if role is None:
|
||||
raise ValueError(f"Invalid roleId")
|
||||
|
||||
for role_id in new_config.team_role_ids:
|
||||
if role_id.role_id in old_config.team_role_ids.select(lambda x: str(x.role_id)):
|
||||
continue
|
||||
|
||||
self._server_configs.add_server_team_role_id_config(role_id)
|
102
kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py
Normal file
102
kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py
Normal file
@ -0,0 +1,102 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from bot_data.model.technician_id_config import TechnicianIdConfig
|
||||
from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
|
||||
|
||||
class TechnicianConfigMutation(QueryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: ApiLogger,
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
technician_configs: TechnicianConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
QueryABC.__init__(self, "TechnicianConfigMutation")
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._servers = servers
|
||||
self._technician_configs = technician_configs
|
||||
self._db = db
|
||||
|
||||
self.set_field("updateTechnicianConfig", self.resolve_update_technician_config)
|
||||
|
||||
def resolve_update_technician_config(self, *_, input: dict):
|
||||
technician_config = self._technician_configs.get_technician_config()
|
||||
self._can_user_mutate_data(technician_config, UserRoleEnum.admin)
|
||||
|
||||
technician_config.help_command_reference_url = (
|
||||
input["helpCommandReferenceUrl"]
|
||||
if "helpCommandReferenceUrl" in input
|
||||
else technician_config.help_command_reference_url
|
||||
)
|
||||
technician_config.wait_for_restart = (
|
||||
input["waitForRestart"] if "waitForRestart" in input else technician_config.wait_for_restart
|
||||
)
|
||||
technician_config.wait_for_shutdown = (
|
||||
input["waitForShutdown"] if "waitForShutdown" in input else technician_config.wait_for_shutdown
|
||||
)
|
||||
technician_config.cache_max_messages = (
|
||||
input["cacheMaxMessages"] if "cacheMaxMessages" in input else technician_config.cache_max_messages
|
||||
)
|
||||
technician_config.ping_urls = (
|
||||
List(str, input["pingURLs"]) if "pingURLs" in input else technician_config.ping_urls
|
||||
)
|
||||
technician_config.technician_ids = (
|
||||
List(int).extend([int(x) for x in input["technicianIds"]])
|
||||
if "technicianIds" in input
|
||||
else technician_config.technician_ids
|
||||
)
|
||||
|
||||
self._technician_configs.update_technician_config(technician_config)
|
||||
if "pingURLs" in input:
|
||||
self._update_ping_urls(technician_config)
|
||||
|
||||
if "technicianIds" in input:
|
||||
self._update_technician_ids(technician_config)
|
||||
|
||||
self._db.save_changes()
|
||||
return technician_config
|
||||
|
||||
def _update_ping_urls(self, new_config: TechnicianConfig):
|
||||
old_config = self._technician_configs.get_technician_config()
|
||||
for url in old_config.ping_urls:
|
||||
if url in new_config.ping_urls:
|
||||
continue
|
||||
|
||||
self._technician_configs.delete_technician_ping_url_config(TechnicianPingUrlConfig(url))
|
||||
|
||||
for url in new_config.ping_urls:
|
||||
if url in old_config.ping_urls:
|
||||
continue
|
||||
|
||||
self._technician_configs.add_technician_ping_url_config(TechnicianPingUrlConfig(url))
|
||||
|
||||
def _update_technician_ids(self, new_config: TechnicianConfig):
|
||||
old_config = self._technician_configs.get_technician_config()
|
||||
for technician_id in old_config.technician_ids:
|
||||
if technician_id in new_config.technician_ids:
|
||||
continue
|
||||
|
||||
self._technician_configs.delete_technician_id_config(TechnicianIdConfig(technician_id))
|
||||
|
||||
for technician_id in new_config.technician_ids:
|
||||
user = self._bot.get_user(technician_id)
|
||||
if user is None:
|
||||
raise ValueError(f"Invalid technicianId")
|
||||
|
||||
for technician_id in new_config.technician_ids:
|
||||
if technician_id in old_config.technician_ids:
|
||||
continue
|
||||
|
||||
self._technician_configs.add_technician_id_config(TechnicianIdConfig(technician_id))
|
@ -2,6 +2,7 @@ import hashlib
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
@ -15,19 +16,18 @@ from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryA
|
||||
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.api_key import ApiKey
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.user_joined_game_server import UserJoinedGameServer
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from modules.permission.service.permission_service import PermissionService
|
||||
|
||||
|
||||
class UserJoinedGameServerMutation(QueryABC):
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
base_helper: BaseHelperABC,
|
||||
servers: ServerRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
user_joined_game_servers: UserJoinedGameServerRepositoryABC,
|
||||
@ -41,8 +41,8 @@ class UserJoinedGameServerMutation(QueryABC):
|
||||
):
|
||||
QueryABC.__init__(self, "UserJoinedGameServerMutation")
|
||||
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._base_helper = base_helper
|
||||
self._servers = servers
|
||||
self._users = users
|
||||
self._user_joined_game_servers = user_joined_game_servers
|
||||
@ -116,7 +116,7 @@ class UserJoinedGameServerMutation(QueryABC):
|
||||
return
|
||||
active.leaved_on = datetime.now()
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(user.server.discord_id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.server.discord_id}")
|
||||
|
||||
ontime = round((active.leaved_on - active.joined_on).total_seconds() / 3600, 2)
|
||||
old_xp = user.xp
|
||||
|
39
kdb-bot/src/bot_graphql/queries/server_config_query.py
Normal file
39
kdb-bot/src/bot_graphql/queries/server_config_query.py
Normal file
@ -0,0 +1,39 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
|
||||
from bot_data.model.server_config_history import ServerConfigHistory
|
||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC
|
||||
|
||||
|
||||
class ServerConfigQuery(DataQueryWithHistoryABC):
|
||||
def __init__(self, db: DatabaseContextABC):
|
||||
DataQueryWithHistoryABC.__init__(self, "ServerConfig", "CFG_ServerHistory", ServerConfigHistory, db)
|
||||
|
||||
self.set_field("id", lambda config, *_: config.id)
|
||||
self.set_field("messageDeleteTimer", lambda config, *_: config.message_delete_timer)
|
||||
self.set_field("notificationChatId", lambda config, *_: config.notification_chat_id)
|
||||
self.set_field("maxVoiceStateHours", lambda config, *_: config.max_voice_state_hours)
|
||||
self.set_field("xpPerMessage", lambda config, *_: config.xp_per_message)
|
||||
self.set_field("xpPerReaction", lambda config, *_: config.xp_per_reaction)
|
||||
self.set_field("maxMessageXpPerHour", lambda config, *_: config.max_message_xp_per_hour)
|
||||
self.set_field("xpPerOntimeHour", lambda config, *_: config.xp_per_ontime_hour)
|
||||
self.set_field("xpPerEventParticipation", lambda config, *_: config.xp_per_event_participation)
|
||||
self.set_field("xpPerAchievement", lambda config, *_: config.xp_per_achievement)
|
||||
self.set_field("afkCommandChannelId", lambda config, *_: config.afk_command_channel_id)
|
||||
self.set_field("helpVoiceChannelId", lambda config, *_: config.help_voice_channel_id)
|
||||
self.set_field("teamChannelId", lambda config, *_: config.team_channel_id)
|
||||
self.set_field("loginMessageChannelId", lambda config, *_: config.login_message_channel_id)
|
||||
self.set_field("afkChannelIds", lambda config, *_: config.afk_channel_ids)
|
||||
self.set_field(
|
||||
"moderatorRoleIds",
|
||||
lambda config, *_: config.team_role_ids.where(
|
||||
lambda x: x.team_member_type == TeamMemberTypeEnum.moderator
|
||||
).select(lambda x: x.role_id),
|
||||
)
|
||||
self.set_field(
|
||||
"adminRoleIds",
|
||||
lambda config, *_: config.team_role_ids.where(
|
||||
lambda x: x.team_member_type == TeamMemberTypeEnum.admin
|
||||
).select(lambda x: x.role_id),
|
||||
)
|
||||
self.set_field("server", lambda config, *_: config.server)
|
@ -6,6 +6,7 @@ from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
@ -32,6 +33,7 @@ class ServerQuery(DataQueryWithHistoryABC):
|
||||
ujs: UserJoinedServerRepositoryABC,
|
||||
ujvs: UserJoinedVoiceChannelRepositoryABC,
|
||||
achievements: AchievementRepositoryABC,
|
||||
server_configs: ServerConfigRepositoryABC,
|
||||
):
|
||||
DataQueryWithHistoryABC.__init__(self, "Server", "ServersHistory", ServerHistory, db)
|
||||
|
||||
@ -62,6 +64,7 @@ class ServerQuery(DataQueryWithHistoryABC):
|
||||
self.add_collection(
|
||||
"achievement", lambda server, *_: achievements.get_achievements_by_server_id(server.id), AchievementFilter
|
||||
)
|
||||
self.set_field("config", lambda server, *_: server_configs.get_server_config_by_server(server.id))
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(server: Server, *_):
|
||||
|
@ -0,0 +1,11 @@
|
||||
from bot_graphql.abc.history_query_abc import HistoryQueryABC
|
||||
|
||||
|
||||
class TechnicianConfigHistoryQuery(HistoryQueryABC):
|
||||
def __init__(self):
|
||||
HistoryQueryABC.__init__(self, "TechnicianConfig")
|
||||
|
||||
self.set_field("helpCommandReferenceUrl", lambda config, *_: config.help_command_reference_url)
|
||||
self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart)
|
||||
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
|
||||
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
|
57
kdb-bot/src/bot_graphql/queries/technician_config_query.py
Normal file
57
kdb-bot/src/bot_graphql/queries/technician_config_query.py
Normal file
@ -0,0 +1,57 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.abc.table_with_id_abc import TableWithIdABC
|
||||
from bot_data.model.technician_config_history import TechnicianConfigHistory
|
||||
from bot_data.model.technician_id_config_history import TechnicianIdConfigHistory
|
||||
from bot_data.model.technician_ping_url_config_history import TechnicianPingUrlConfigHistory
|
||||
from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC
|
||||
|
||||
|
||||
class TechnicianConfigQuery(DataQueryWithHistoryABC):
|
||||
def __init__(self, db: DatabaseContextABC):
|
||||
DataQueryWithHistoryABC.__init__(self, "TechnicianConfig", "CFG_TechnicianHistory", TechnicianConfigHistory, db)
|
||||
|
||||
self.set_field("helpCommandReferenceUrl", lambda config, *_: config.help_command_reference_url)
|
||||
self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart)
|
||||
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
|
||||
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
|
||||
self.set_field("pingURLs", lambda config, *_: config.ping_urls)
|
||||
self.set_field("technicianIds", lambda config, *_: config.technician_ids)
|
||||
|
||||
self.set_field("pingURLHistory", self.resolve_ping_url_history)
|
||||
self.set_field("technicianIdHistory", self.resolve_technician_id_history)
|
||||
|
||||
def resolve_ping_url_history(self, entry: TableWithIdABC, *_):
|
||||
history = List(TechnicianPingUrlConfigHistory)
|
||||
|
||||
results = self._db.select(
|
||||
f"""
|
||||
SELECT *
|
||||
FROM CFG_TechnicianPingUrlsHistory
|
||||
WHERE Id = {entry.id}
|
||||
ORDER BY DateTo DESC;
|
||||
"""
|
||||
)
|
||||
|
||||
for result in results:
|
||||
history.add(TechnicianPingUrlConfigHistory(*result[1:], result[0]))
|
||||
|
||||
return history
|
||||
|
||||
def resolve_technician_id_history(self, entry: TableWithIdABC, *_):
|
||||
history = List(TechnicianIdConfigHistory)
|
||||
|
||||
results = self._db.select(
|
||||
f"""
|
||||
SELECT *
|
||||
FROM CFG_TechnicianIdsHistory
|
||||
WHERE Id = {entry.id}
|
||||
ORDER BY DateTo DESC;
|
||||
"""
|
||||
)
|
||||
|
||||
for result in results:
|
||||
history.add(TechnicianIdConfigHistory(*result[1:], result[0]))
|
||||
|
||||
return history
|
@ -0,0 +1,8 @@
|
||||
from bot_graphql.abc.history_query_abc import HistoryQueryABC
|
||||
|
||||
|
||||
class TechnicianIdConfigHistoryQuery(HistoryQueryABC):
|
||||
def __init__(self):
|
||||
HistoryQueryABC.__init__(self, "TechnicianIdConfig")
|
||||
|
||||
self.set_field("technicianId", lambda config, *_: config.technicianId)
|
@ -0,0 +1,8 @@
|
||||
from bot_graphql.abc.history_query_abc import HistoryQueryABC
|
||||
|
||||
|
||||
class TechnicianPingUrlConfigHistoryQuery(HistoryQueryABC):
|
||||
def __init__(self):
|
||||
HistoryQueryABC.__init__(self, "TechnicianPingUrlConfig")
|
||||
|
||||
self.set_field("url", lambda config, *_: config.ping_url)
|
@ -7,6 +7,7 @@ from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
@ -41,6 +42,7 @@ class Query(QueryABC):
|
||||
users: UserRepositoryABC,
|
||||
achievements: AchievementRepositoryABC,
|
||||
achievement_service: AchievementService,
|
||||
technician_config: TechnicianConfigRepositoryABC,
|
||||
):
|
||||
QueryABC.__init__(self, "Query")
|
||||
|
||||
@ -68,6 +70,7 @@ class Query(QueryABC):
|
||||
)
|
||||
self.add_collection("user", lambda *_: users.get_users(), UserFilter)
|
||||
self.add_collection("achievement", lambda *_: achievements.get_achievements(), AchievementFilter)
|
||||
self.set_field("technicianConfig", lambda *_: technician_config.get_technician_config())
|
||||
|
||||
self.set_field("guilds", self._resolve_guilds)
|
||||
self.set_field("achievementAttributes", lambda x, *_: achievement_service.get_attributes())
|
||||
|
@ -5,16 +5,15 @@ from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from cpl_translation import TranslatePipe
|
||||
|
||||
from bot_core.configuration.server_settings import ServerSettings
|
||||
from bot_core.service.message_service import MessageService
|
||||
from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.achievement import Achievement
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_got_achievement import UserGotAchievement
|
||||
from modules.achievements.achievement_attribute_resolver import AchievementAttributeResolver
|
||||
from modules.achievements.model.achievement_attribute import AchievementAttribute
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class AchievementService:
|
||||
@ -100,7 +99,7 @@ class AchievementService:
|
||||
await self._send_achievement_notification(user.server.discord_id, user.discord_id, achievement.name)
|
||||
|
||||
def _give_user_xp(self, user: User):
|
||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{user.server.discord_id}")
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.server.discord_id}")
|
||||
user.xp += settings.xp_per_achievement
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
@ -108,7 +107,7 @@ class AchievementService:
|
||||
async def _send_achievement_notification(self, guild_id: int, member_id: int, achievement_name: str):
|
||||
member = self._bot.get_guild(guild_id).get_member(member_id)
|
||||
|
||||
settings: ServerSettings = self._config.get_configuration(f"ServerSettings_{guild_id}")
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild_id}")
|
||||
await self._message_service.send_channel_message(
|
||||
self._bot.get_channel(settings.notification_chat_id),
|
||||
self._t.transform("modules.achievements.got_new_achievement").format(member.mention, achievement_name),
|
||||
|
@ -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__ = "modules.base.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
@ -1,12 +0,0 @@
|
||||
from abc import abstractmethod, ABC
|
||||
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseHelperABC(ABC):
|
||||
def __init__(self):
|
||||
ABC.__init__(self)
|
||||
|
||||
@abstractmethod
|
||||
def get_config(self, g_id: int) -> BaseServerSettings:
|
||||
pass
|
@ -6,7 +6,6 @@ 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.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.command.afk_command import AFKCommand
|
||||
from modules.base.command.game_server_group import GameServerGroup
|
||||
from modules.base.command.help_command import HelpCommand
|
||||
@ -40,7 +39,6 @@ from modules.base.events.base_on_voice_state_update_event_scheduled_event_bonus
|
||||
from modules.base.forms.bug_report_form import BugReportForm
|
||||
from modules.base.forms.complaint_form import ComplaintForm
|
||||
from modules.base.helper.base_reaction_handler import BaseReactionHandler
|
||||
from modules.base.service.base_helper_service import BaseHelperService
|
||||
from modules.base.service.event_service import EventService
|
||||
from modules.base.service.user_warnings_service import UserWarningsService
|
||||
|
||||
@ -53,7 +51,6 @@ class BaseModule(ModuleABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_transient(BaseHelperABC, BaseHelperService)
|
||||
services.add_transient(BaseReactionHandler)
|
||||
services.add_singleton(EventService)
|
||||
services.add_transient(UserWarningsService)
|
||||
|
@ -10,7 +10,6 @@ from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.helper.command_checks import CommandChecks
|
||||
from bot_core.logging.command_logger import CommandLogger
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class AFKCommand(DiscordCommandABC):
|
||||
@ -39,7 +38,7 @@ class AFKCommand(DiscordCommandABC):
|
||||
@CommandChecks.check_is_ready()
|
||||
async def afk(self, ctx: Context):
|
||||
self._logger.debug(__name__, f"Received command afk {ctx}")
|
||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{ctx.guild.id}")
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||
|
||||
if ctx.author.voice is None or ctx.author.voice.channel is None:
|
||||
await self._message_service.send_ctx_msg(
|
||||
|
@ -12,7 +12,6 @@ from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.helper.command_checks import CommandChecks
|
||||
from bot_core.logging.command_logger import CommandLogger
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class HelpCommand(DiscordCommandABC):
|
||||
@ -39,7 +38,7 @@ class HelpCommand(DiscordCommandABC):
|
||||
@CommandChecks.check_is_ready()
|
||||
async def help(self, ctx: Context, persistent_flag: str = None):
|
||||
self._logger.debug(__name__, f"Received command help {ctx}:{persistent_flag}")
|
||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{ctx.guild.id}")
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||
is_persistent = persistent_flag == "--stay"
|
||||
await self._message_service.send_ctx_msg(
|
||||
ctx,
|
||||
|
@ -10,8 +10,7 @@ from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.helper.command_checks import CommandChecks
|
||||
from bot_core.logging.command_logger import CommandLogger
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
@ -24,8 +23,8 @@ class PingCommand(DiscordCommandABC):
|
||||
client_utils: ClientUtilsABC,
|
||||
translate: TranslatePipe,
|
||||
permissions: PermissionServiceABC,
|
||||
base_helper: BaseHelperABC,
|
||||
servers: ServerRepositoryABC,
|
||||
settings: TechnicianConfig,
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
@ -35,8 +34,8 @@ class PingCommand(DiscordCommandABC):
|
||||
self._client_utils = client_utils
|
||||
self._t = translate
|
||||
self._permissions = permissions
|
||||
self._base_helper = base_helper
|
||||
self._servers = servers
|
||||
self._settings = settings
|
||||
|
||||
self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}")
|
||||
|
||||
@ -58,9 +57,7 @@ class PingCommand(DiscordCommandABC):
|
||||
description=self._t.transform("modules.base.info.description"),
|
||||
color=int("ef9d0d", 16),
|
||||
)
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||
for server in settings.ping_urls:
|
||||
for server in self._settings.ping_urls:
|
||||
embed.add_field(name=server, value=f"{self._get_ping(server)} ms", inline=False)
|
||||
await self._message_service.send_ctx_msg(ctx, embed)
|
||||
else:
|
||||
|
@ -8,9 +8,9 @@ from discord.ext.commands import Context
|
||||
|
||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.server_settings import ServerSettings
|
||||
from bot_core.helper.command_checks import CommandChecks
|
||||
from bot_core.logging.command_logger import CommandLogger
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ class PurgeCommand(DiscordCommandABC):
|
||||
@CommandChecks.check_is_member_moderator()
|
||||
async def purge(self, ctx: Context):
|
||||
self._logger.debug(__name__, f"Received command purge {ctx}")
|
||||
server_settings: ServerSettings = self._config.get_configuration(f"ServerSettings_{ctx.guild.id}")
|
||||
server_settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.moderator.purge_message"))
|
||||
await asyncio.sleep(server_settings.message_delete_timer)
|
||||
|
@ -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__ = "modules.base.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
@ -1,104 +0,0 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class BaseServerSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._id: int = 0
|
||||
self._max_voice_state_hours: int = 0
|
||||
self._xp_per_message: int = 0
|
||||
self._xp_per_reaction: int = 0
|
||||
self._max_message_xp_per_hour: int = 0
|
||||
self._xp_per_ontime_hour: int = 0
|
||||
self._xp_per_event_participation: int = 0
|
||||
self._xp_per_achievement: int = 0
|
||||
self._afk_channel_ids: List[int] = List(int)
|
||||
self._afk_command_channel_id: int = 0
|
||||
self._help_command_reference_url: str = ""
|
||||
self._help_voice_channel_id: int = 0
|
||||
self._team_channel_id: int = 0
|
||||
self._ping_urls = List(str)
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def max_voice_state_hours(self) -> int:
|
||||
return self._max_voice_state_hours
|
||||
|
||||
@property
|
||||
def xp_per_message(self) -> int:
|
||||
return self._xp_per_message
|
||||
|
||||
@property
|
||||
def xp_per_reaction(self) -> int:
|
||||
return self._xp_per_reaction
|
||||
|
||||
@property
|
||||
def max_message_xp_per_hour(self) -> int:
|
||||
return self._max_message_xp_per_hour
|
||||
|
||||
@property
|
||||
def xp_per_ontime_hour(self) -> int:
|
||||
return self._xp_per_ontime_hour
|
||||
|
||||
@property
|
||||
def xp_per_event_participation(self) -> int:
|
||||
return self._xp_per_event_participation
|
||||
|
||||
@property
|
||||
def xp_per_achievement(self) -> int:
|
||||
return self._xp_per_achievement
|
||||
|
||||
@property
|
||||
def afk_channel_ids(self) -> List[int]:
|
||||
return self._afk_channel_ids
|
||||
|
||||
@property
|
||||
def afk_command_channel_id(self) -> int:
|
||||
return self._afk_command_channel_id
|
||||
|
||||
@property
|
||||
def help_command_reference_url(self) -> str:
|
||||
return self._help_command_reference_url
|
||||
|
||||
@property
|
||||
def team_channel_id(self) -> int:
|
||||
return self._team_channel_id
|
||||
|
||||
@property
|
||||
def help_voice_channel_id(self) -> int:
|
||||
return self._help_voice_channel_id
|
||||
|
||||
@property
|
||||
def ping_urls(self) -> List[str]:
|
||||
return self._ping_urls
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._id = int(settings["Id"])
|
||||
self._max_voice_state_hours = int(settings["MaxVoiceStateHours"])
|
||||
self._xp_per_message = int(settings["XpPerMessage"])
|
||||
self._xp_per_reaction = int(settings["XpPerReaction"])
|
||||
self._max_message_xp_per_hour = int(settings["MaxMessageXpPerHour"])
|
||||
self._xp_per_ontime_hour = int(settings["XpPerOntimeHour"])
|
||||
self._xp_per_event_participation = (
|
||||
0 if "XpPerEventParticipation" not in settings else settings["XpPerEventParticipation"]
|
||||
)
|
||||
for index in settings["AFKChannelIds"]:
|
||||
self._afk_channel_ids.append(int(index))
|
||||
self._afk_command_channel_id = settings["AFKCommandChannelId"]
|
||||
self._help_command_reference_url = settings["HelpCommandReferenceUrl"]
|
||||
self._help_voice_channel_id = settings["HelpVoiceChannelId"]
|
||||
self._team_channel_id = settings["TeamChannelId"]
|
||||
for url in settings["PingURLs"]:
|
||||
self._ping_urls.append(url)
|
||||
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,31 +0,0 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._servers: List[BaseServerSettings] = List()
|
||||
|
||||
@property
|
||||
def servers(self) -> List[BaseServerSettings]:
|
||||
return self._servers
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
servers = List(BaseServerSettings)
|
||||
for s in settings:
|
||||
st = BaseServerSettings()
|
||||
settings[s]["Id"] = s
|
||||
st.from_dict(settings[s])
|
||||
servers.append(st)
|
||||
self._servers = servers
|
||||
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,18 +1,15 @@
|
||||
import datetime
|
||||
import traceback
|
||||
import uuid
|
||||
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_core.time import TimeFormatSettings
|
||||
from cpl_discord.events.on_command_error_abc import OnCommandErrorABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context, CommandError
|
||||
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events.on_command_error_abc import OnCommandErrorABC
|
||||
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.bot_settings import BotSettings
|
||||
from bot_core.exception.check_error import CheckError
|
||||
|
||||
|
||||
@ -22,7 +19,6 @@ class BaseOnCommandErrorEvent(OnCommandErrorABC):
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
messenger: MessageServiceABC,
|
||||
bot_settings: BotSettings,
|
||||
time_format_settings: TimeFormatSettings,
|
||||
translate: TranslatePipe,
|
||||
):
|
||||
|
@ -9,14 +9,11 @@ from cpl_translation import TranslatePipe
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.bot_settings import BotSettings
|
||||
from bot_core.logging.command_logger import CommandLogger
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.user import User
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseOnCommandEvent(OnCommandABC):
|
||||
@ -25,10 +22,8 @@ class BaseOnCommandEvent(OnCommandABC):
|
||||
logger: CommandLogger,
|
||||
bot: DiscordBotServiceABC,
|
||||
messenger: MessageServiceABC,
|
||||
bot_settings: BotSettings,
|
||||
time_format_settings: TimeFormatSettings,
|
||||
translate: TranslatePipe,
|
||||
bhs: BaseHelperABC,
|
||||
db: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
clients: ClientRepositoryABC,
|
||||
@ -38,10 +33,8 @@ class BaseOnCommandEvent(OnCommandABC):
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._messenger = messenger
|
||||
self._bot_settings = bot_settings
|
||||
self._time_format_settings = time_format_settings
|
||||
self._t = translate
|
||||
self._base_helper = bhs
|
||||
self._db = db
|
||||
self._users = users
|
||||
self._clients = clients
|
||||
@ -73,7 +66,7 @@ class BaseOnCommandEvent(OnCommandABC):
|
||||
self._logger.error(__name__, f"User not found {dc_user_id}")
|
||||
return
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(message.guild.id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{message.guild.id}")
|
||||
old_xp = user.xp
|
||||
user.xp += settings.xp_per_message
|
||||
self._users.update_user(user)
|
||||
|
@ -17,8 +17,6 @@ from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.known_user import KnownUser
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_joined_server import UserJoinedServer
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
@ -27,7 +25,6 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC):
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
base_helper: BaseHelperABC,
|
||||
messenger: MessageServiceABC,
|
||||
permissions: PermissionServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
@ -40,7 +37,6 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC):
|
||||
OnMemberJoinABC.__init__(self)
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._base_helper = base_helper
|
||||
self._messenger = messenger
|
||||
self._permission_service = permissions
|
||||
self._db = db
|
||||
@ -65,7 +61,6 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC):
|
||||
|
||||
async def _add_if_not_exists_user_async(self, member: Union[discord.User, discord.Member]):
|
||||
self._logger.debug(__name__, f"Check if user exists {member}")
|
||||
settings: BaseServerSettings = self._base_helper.get_config(member.guild.id)
|
||||
await self._messenger.send_dm_message(
|
||||
self._t.transform("modules.base.welcome_message").format(member.guild.name),
|
||||
member,
|
||||
|
@ -12,15 +12,12 @@ from bot_core.helper.event_checks import EventChecks
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseOnMemberRemoveEvent(OnMemberRemoveABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
base_helper: BaseHelperABC,
|
||||
db: DatabaseContextABC,
|
||||
messenger: MessageServiceABC,
|
||||
users: UserRepositoryABC,
|
||||
@ -41,7 +38,7 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC):
|
||||
|
||||
async def _remove_user(self, member: Union[discord.User, discord.Member]):
|
||||
self._logger.debug(__name__, f"Remove user {member}")
|
||||
settings: BaseServerSettings = self._base_helper.get_config(member.guild.id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}")
|
||||
await self._messenger.send_dm_message(self._t.transform("modules.base.goodbye_message"), member)
|
||||
|
||||
try:
|
||||
|
@ -11,15 +11,12 @@ from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.user import User
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseOnMessageDeleteEvent(OnMessageDeleteABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: MessageLogger,
|
||||
bhs: BaseHelperABC,
|
||||
db: DatabaseContextABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
users: UserRepositoryABC,
|
||||
@ -28,7 +25,6 @@ class BaseOnMessageDeleteEvent(OnMessageDeleteABC):
|
||||
):
|
||||
OnMessageDeleteABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._base_helper = bhs
|
||||
self._db = db
|
||||
self._bot = bot
|
||||
self._users = users
|
||||
@ -61,7 +57,7 @@ class BaseOnMessageDeleteEvent(OnMessageDeleteABC):
|
||||
self._logger.error(__name__, f"User not found {dc_user_id}")
|
||||
return
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(message.guild.id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{message.guild.id}")
|
||||
old_xp = user.xp
|
||||
user.xp -= settings.xp_per_message
|
||||
self._users.update_user(user)
|
||||
|
@ -12,16 +12,14 @@ from bot_core.service.client_utils_service import ClientUtilsService
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.user import User
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseOnMessageEvent(OnMessageABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: MessageLogger,
|
||||
bhs: BaseHelperABC,
|
||||
client_utils: ClientUtilsService,
|
||||
db: DatabaseContextABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
@ -31,7 +29,6 @@ class BaseOnMessageEvent(OnMessageABC):
|
||||
):
|
||||
OnMessageABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._base_helper = bhs
|
||||
self._client_utils = client_utils
|
||||
self._bot = bot
|
||||
self._db = db
|
||||
@ -66,7 +63,7 @@ class BaseOnMessageEvent(OnMessageABC):
|
||||
self._logger.error(__name__, f"User not found {dc_user_id}")
|
||||
return
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(message.guild.id)
|
||||
settings: ServerConfig = se
|
||||
if self._client_utils.is_message_xp_count_by_hour_higher_that_max_message_count_per_hour(
|
||||
message.created_at, user, settings
|
||||
):
|
||||
|
@ -16,10 +16,9 @@ from bot_data.abc.user_joined_voice_channel_repository_abc import (
|
||||
)
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
@ -27,7 +26,6 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
base_helper: BaseHelperABC,
|
||||
servers: ServerRepositoryABC,
|
||||
known_users: KnownUserRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
@ -38,7 +36,6 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
OnVoiceStateUpdateABC.__init__(self)
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._base_helper = base_helper
|
||||
self._servers = servers
|
||||
self._known_users = known_users
|
||||
self._users = users
|
||||
@ -67,7 +64,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
self._db.save_changes()
|
||||
return
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}")
|
||||
|
||||
join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.id)
|
||||
join.leaved_on = datetime.now()
|
||||
@ -98,7 +95,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
__name__,
|
||||
f"Detected on_voice_state_update {member.id} from {before} to {after}",
|
||||
)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(member.guild.id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}")
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
|
||||
try:
|
||||
|
@ -7,8 +7,7 @@ from cpl_translation import TranslatePipe
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.helper.event_checks import EventChecks
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
@ -17,7 +16,6 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC):
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
base_helper: BaseHelperABC,
|
||||
servers: ServerRepositoryABC,
|
||||
permissions: PermissionServiceABC,
|
||||
message_service: MessageServiceABC,
|
||||
@ -26,7 +24,6 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC):
|
||||
OnVoiceStateUpdateABC.__init__(self)
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._base_helper = base_helper
|
||||
self._servers = servers
|
||||
self._permissions = permissions
|
||||
self._message_service = message_service
|
||||
@ -43,7 +40,7 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC):
|
||||
):
|
||||
self._logger.debug(__name__, f"Module {type(self)} started")
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}")
|
||||
if after.channel is None or after.channel.id != settings.help_voice_channel_id:
|
||||
return
|
||||
|
||||
|
@ -7,8 +7,7 @@ from cpl_discord.events import OnVoiceStateUpdateABC
|
||||
from bot_core.helper.event_checks import EventChecks
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from modules.base.service.event_service import EventService
|
||||
|
||||
|
||||
@ -17,7 +16,6 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC):
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
base_helper: BaseHelperABC,
|
||||
servers: ServerRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
events: EventService,
|
||||
@ -26,7 +24,6 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC):
|
||||
OnVoiceStateUpdateABC.__init__(self)
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._base_helper = base_helper
|
||||
self._servers = servers
|
||||
self._users = users
|
||||
self._events = events
|
||||
@ -57,7 +54,7 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC):
|
||||
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
||||
return
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}")
|
||||
user.xp += settings.xp_per_event_participation
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
|
@ -5,9 +5,8 @@ from cpl_translation import TranslatePipe
|
||||
from discord import ui, TextStyle
|
||||
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.bot_settings import BotSettings
|
||||
from bot_core.logging.command_logger import CommandLogger
|
||||
from modules.base.service.base_helper_service import BaseHelperService
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
|
||||
|
||||
class BugReportForm(ui.Modal):
|
||||
@ -15,22 +14,20 @@ class BugReportForm(ui.Modal):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
bot_settings: BotSettings,
|
||||
technician_config: TechnicianConfig,
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
logger: CommandLogger,
|
||||
message_service: MessageServiceABC,
|
||||
base_helper: BaseHelperService,
|
||||
t: TranslatePipe,
|
||||
):
|
||||
ui.Modal.__init__(self, title=t.transform("modules.base.bug.title"))
|
||||
|
||||
self._bot_settings = bot_settings
|
||||
self._technician_config = technician_config
|
||||
self._bot = bot
|
||||
self._db = db
|
||||
self._message_service = message_service
|
||||
self._logger = logger
|
||||
self._base_helper = base_helper
|
||||
self._t = t
|
||||
|
||||
self.description.label = t.transform("modules.base.bug.label")
|
||||
@ -38,7 +35,7 @@ class BugReportForm(ui.Modal):
|
||||
async def on_submit(self, interaction: discord.Interaction):
|
||||
self._logger.debug(__name__, f"Started bug report form")
|
||||
|
||||
for t in self._bot_settings.technicians:
|
||||
for t in self._technician_config.technician_ids:
|
||||
member = self._bot.get_user(t)
|
||||
await self._message_service.send_dm_message(
|
||||
self._t.transform("modules.base.bug.message").format(interaction.user.mention, self.description.value),
|
||||
|
@ -1,12 +1,12 @@
|
||||
import discord
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord import ui, TextStyle
|
||||
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.logging.command_logger import CommandLogger
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from modules.base.service.base_helper_service import BaseHelperService
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
|
||||
|
||||
class ComplaintForm(ui.Modal):
|
||||
@ -14,25 +14,25 @@ class ComplaintForm(ui.Modal):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
db: DatabaseContextABC,
|
||||
logger: CommandLogger,
|
||||
message_service: MessageServiceABC,
|
||||
base_helper: BaseHelperService,
|
||||
t: TranslatePipe,
|
||||
):
|
||||
ui.Modal.__init__(self, title=t.transform("modules.base.complaints.title"))
|
||||
|
||||
self._config = config
|
||||
self._db = db
|
||||
self._message_service = message_service
|
||||
self._logger = logger
|
||||
self._base_helper = base_helper
|
||||
self._t = t
|
||||
|
||||
self.description.label = t.transform("modules.base.complaints.label")
|
||||
|
||||
async def on_submit(self, interaction: discord.Interaction):
|
||||
self._logger.debug(__name__, f"Started complaint command form")
|
||||
settings: BaseServerSettings = self._base_helper.get_config(interaction.guild.id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{interaction.guild.id}")
|
||||
channel = interaction.guild.get_channel(settings.team_channel_id)
|
||||
await self._message_service.send_channel_message(
|
||||
channel,
|
||||
|
@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from discord import RawReactionActionEvent
|
||||
@ -9,26 +10,25 @@ from bot_core.helper.log_message_helper import LogMessageHelper
|
||||
from bot_core.logging.message_logger import MessageLogger
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
|
||||
|
||||
class BaseReactionHandler:
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: MessageLogger,
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
base_helper: BaseHelperABC,
|
||||
client_utils: ClientUtilsABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._servers = servers
|
||||
self._users = users
|
||||
self._base_helper = base_helper
|
||||
self._client_utils = client_utils
|
||||
self._db = db
|
||||
|
||||
@ -70,7 +70,7 @@ class BaseReactionHandler:
|
||||
|
||||
server = self._servers.get_server_by_discord_id(guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(guild.id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}")
|
||||
|
||||
if r_type == "add":
|
||||
if self._client_utils.is_message_xp_count_by_hour_higher_that_max_message_count_per_hour(
|
||||
|
@ -1,13 +0,0 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseHelperService(BaseHelperABC):
|
||||
def __init__(self, config: ConfigurationABC):
|
||||
BaseHelperABC.__init__(self)
|
||||
self._config = config
|
||||
|
||||
def get_config(self, g_id: int) -> BaseServerSettings:
|
||||
return self._config.get_configuration(f"BaseServerSettings_{g_id}")
|
@ -11,8 +11,6 @@ from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_warnings import UserWarnings
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from modules.level.service.level_service import LevelService
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
@ -31,7 +29,6 @@ class UserWarningsService:
|
||||
message_service: MessageServiceABC,
|
||||
t: TranslatePipe,
|
||||
permissions: PermissionServiceABC,
|
||||
base_helper: BaseHelperABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
@ -44,11 +41,10 @@ class UserWarningsService:
|
||||
self._message_service = message_service
|
||||
self._t = t
|
||||
self._permissions = permissions
|
||||
self._base_helper = base_helper
|
||||
|
||||
async def notify_team(self, member: discord.Member, description: str, removed=False):
|
||||
try:
|
||||
settings: BaseServerSettings = self._base_helper.get_config(member.guild.id)
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}")
|
||||
channel = member.guild.get_channel(settings.team_channel_id)
|
||||
if removed:
|
||||
translation = self._t.transform("modules.base.warnings.team_removed").format(
|
||||
|
@ -8,10 +8,7 @@ from cpl_translation import TranslatePipe
|
||||
from discord import guild
|
||||
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.server_settings import ServerSettings
|
||||
from modules.boot_log.configuration.boot_log_server_settings import (
|
||||
BootLogServerSettings,
|
||||
)
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
|
||||
|
||||
class BootLogOnReadyEvent(OnReadyABC):
|
||||
@ -58,19 +55,14 @@ class BootLogOnReadyEvent(OnReadyABC):
|
||||
g: guild = g
|
||||
self._logger.debug(__name__, f"Server detected: {g.id}")
|
||||
|
||||
server_settings: ServerSettings = self._config.get_configuration(f"ServerSettings_{g.id}")
|
||||
if server_settings is None:
|
||||
self._logger.error(__name__, f"BootLog settings for server {g.id} not found!")
|
||||
return
|
||||
|
||||
module_settings: BootLogServerSettings = self._config.get_configuration(f"BootLogServerSettings_{g.id}")
|
||||
if module_settings is None:
|
||||
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{g.id}")
|
||||
if server_config is None:
|
||||
self._logger.error(__name__, f"Config {type(self).__name__}_{g.id} not found!")
|
||||
return
|
||||
|
||||
self._bot.loop.create_task(
|
||||
self._message_service.send_channel_message(
|
||||
self._bot.get_channel(module_settings.login_message_channel_id),
|
||||
self._bot.get_channel(server_config.login_message_channel_id),
|
||||
self._t.transform("modules.boot_log.login_message").format(init_time),
|
||||
)
|
||||
)
|
||||
|
@ -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__ = "modules.boot_log.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
@ -1,28 +0,0 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class BootLogServerSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._id: int = 0
|
||||
self._login_message_channel_id: int = 0
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def login_message_channel_id(self) -> int:
|
||||
return self._login_message_channel_id
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._id = int(settings["Id"])
|
||||
self._login_message_channel_id = int(settings["LoginMessageChannelId"])
|
||||
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,33 +0,0 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
|
||||
from modules.boot_log.configuration.boot_log_server_settings import (
|
||||
BootLogServerSettings,
|
||||
)
|
||||
|
||||
|
||||
class BootLogSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._servers: List[BootLogServerSettings] = List()
|
||||
|
||||
@property
|
||||
def servers(self) -> List[BootLogServerSettings]:
|
||||
return self._servers
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
servers = List(BootLogServerSettings)
|
||||
for s in settings:
|
||||
st = BootLogServerSettings()
|
||||
settings[s]["Id"] = s
|
||||
st.from_dict(settings[s])
|
||||
servers.append(st)
|
||||
self._servers = servers
|
||||
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
kdb-bot/src/modules/config/__init__.py
Normal file
1
kdb-bot/src/modules/config/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user