Moved folders #405
This commit is contained in:
26
bot/src/bot_data/__init__.py
Normal file
26
bot/src/bot_data/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
bot sh-edraft.de Discord bot
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Discord bot for customers of sh-edraft.de
|
||||
|
||||
:copyright: (c) 2022 - 2023 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "bot_data"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.2.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="2", micro="0")
|
26
bot/src/bot_data/abc/__init__.py
Normal file
26
bot/src/bot_data/abc/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
bot sh-edraft.de Discord bot
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Discord bot for customers of sh-edraft.de
|
||||
|
||||
:copyright: (c) 2022 - 2023 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "bot_data.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.2.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="2", micro="0")
|
54
bot/src/bot_data/abc/achievement_repository_abc.py
Normal file
54
bot/src/bot_data/abc/achievement_repository_abc.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.achievement import Achievement
|
||||
from bot_data.model.user_got_achievement import UserGotAchievement
|
||||
|
||||
|
||||
class AchievementRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_achievements(self) -> List[Achievement]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_achievement_by_id(self, id: int) -> Achievement:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_achievements_by_server_id(self, server_id: int) -> List[Achievement]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_achievements_by_user_id(self, user_id: int) -> List[Achievement]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_got_achievements_by_achievement_id(
|
||||
self, achievement_id: int
|
||||
) -> List[Achievement]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_achievement(self, achievement: Achievement):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_achievement(self, achievement: Achievement):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_achievement(self, achievement: Achievement):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_got_achievement(self, join: UserGotAchievement):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_got_achievement(self, join: UserGotAchievement):
|
||||
pass
|
39
bot/src/bot_data/abc/api_key_repository_abc.py
Normal file
39
bot/src/bot_data/abc/api_key_repository_abc.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.api_key import ApiKey
|
||||
|
||||
|
||||
class ApiKeyRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_keys(self) -> List[ApiKey]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_key(self, identifier: str, key: str) -> ApiKey:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_key_by_id(self, id: int) -> ApiKey:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_key_by_key(self, key: str) -> ApiKey:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_api_key(self, api_key: ApiKey):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_api_key(self, api_key: ApiKey):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_api_key(self, api_key: ApiKey):
|
||||
pass
|
69
bot/src/bot_data/abc/auth_user_repository_abc.py
Normal file
69
bot/src/bot_data/abc/auth_user_repository_abc.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.filter.auth_user_select_criteria import AuthUserSelectCriteria
|
||||
from bot_data.filtered_result import FilteredResult
|
||||
from bot_data.model.auth_user import AuthUser
|
||||
from bot_data.model.auth_user_users_relation import AuthUserUsersRelation
|
||||
|
||||
|
||||
class AuthUserRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auth_user_relation_ids(self, auth_user: AuthUser) -> List[int]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_all_auth_users(self) -> List[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_filtered_auth_users(
|
||||
self, criteria: AuthUserSelectCriteria
|
||||
) -> FilteredResult:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auth_user_by_email(self, email: str) -> AuthUser:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auth_user_by_email(self, email: str) -> Optional[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auth_user_by_confirmation_id(self, id: str) -> Optional[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auth_user_by_forgot_password_id(self, id: str) -> Optional[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auth_user(self, user: AuthUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_auth_user(self, user: AuthUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_auth_user(self, user: AuthUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
pass
|
73
bot/src/bot_data/abc/auto_role_repository_abc.py
Normal file
73
bot/src/bot_data/abc/auto_role_repository_abc.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.auto_role import AutoRole
|
||||
from bot_data.model.auto_role_rule import AutoRoleRule
|
||||
|
||||
|
||||
class AutoRoleRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_roles(self) -> List[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_by_id(self, id: int) -> AutoRole:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_by_message_id(self, id: int) -> AutoRole:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auto_role(self, auto_role: AutoRole):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_auto_role(self, auto_role: AutoRole):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_auto_role(self, auto_role: AutoRole):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_rules(self) -> List[AutoRoleRule]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auto_role_rule(self, auto_role: AutoRoleRule):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_auto_role_rule(self, auto_role: AutoRoleRule):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_auto_role_rule(self, auto_role: AutoRoleRule):
|
||||
pass
|
74
bot/src/bot_data/abc/client_repository_abc.py
Normal file
74
bot/src/bot_data/abc/client_repository_abc.py
Normal file
@@ -0,0 +1,74 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.client import Client
|
||||
|
||||
|
||||
class ClientRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_clients(self) -> List[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_client_by_id(self, client_id: int) -> Client:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_clients_by_server_id(self, server_id: int) -> List[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_server_id(self, server_id: int) -> Optional[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> Optional[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_client(self, client: Client):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_client(self, client: Client):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_client(self, client: Client):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_sent_message_count(self, client_id: int, server_id: int, value: int):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_received_message_count(self, client_id: int, server_id: int, value: int):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_deleted_message_count(self, client_id: int, server_id: int, value: int):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_received_command_count(self, client_id: int, server_id: int, value: int):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_moved_users_count(self, client_id: int, server_id: int, value: int):
|
||||
pass
|
11
bot/src/bot_data/abc/data_seeder_abc.py
Normal file
11
bot/src/bot_data/abc/data_seeder_abc.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class DataSeederABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def seed(self):
|
||||
pass
|
39
bot/src/bot_data/abc/game_server_repository_abc.py
Normal file
39
bot/src/bot_data/abc/game_server_repository_abc.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.game_server import GameServer
|
||||
|
||||
|
||||
class GameServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_servers(self) -> List[GameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_server_by_id(self, id: int) -> GameServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_servers_by_server_id(self, id: int) -> List[GameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_servers_by_api_key_id(self, id: int) -> List[GameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_game_server(self, game_server: GameServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_game_server(self, game_server: GameServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_game_server(self, game_server: GameServer):
|
||||
pass
|
27
bot/src/bot_data/abc/history_table_abc.py
Normal file
27
bot/src/bot_data/abc/history_table_abc.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class HistoryTableABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self._id = 0
|
||||
self._deleted = False
|
||||
self._date_from = datetime.now().isoformat()
|
||||
self._date_to = datetime.now().isoformat()
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def deleted(self) -> bool:
|
||||
return self._deleted
|
||||
|
||||
@property
|
||||
def date_from(self) -> str:
|
||||
return self._date_from
|
||||
|
||||
@property
|
||||
def date_to(self) -> str:
|
||||
return self._date_to
|
36
bot/src/bot_data/abc/known_user_repository_abc.py
Normal file
36
bot/src/bot_data/abc/known_user_repository_abc.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.known_user import KnownUser
|
||||
|
||||
|
||||
class KnownUserRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users(self) -> List[KnownUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_id(self, id: int) -> KnownUser:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id(self, discord_id: int) -> KnownUser:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id(self, discord_id: int) -> Optional[KnownUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user(self, known_user: KnownUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user(self, known_user: KnownUser):
|
||||
pass
|
44
bot/src/bot_data/abc/level_repository_abc.py
Normal file
44
bot/src/bot_data/abc/level_repository_abc.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.level import Level
|
||||
|
||||
|
||||
class LevelRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_levels(self) -> List[Level]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_level_by_id(self, id: int) -> Level:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_level_by_id(self, id: int) -> Optional[Level]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_levels_by_server_id(self, server_id: int) -> List[Level]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_level(self, level: Level):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_level(self, level: Level):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_level(self, level: Level):
|
||||
pass
|
32
bot/src/bot_data/abc/migration_abc.py
Normal file
32
bot/src/bot_data/abc/migration_abc.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from mysql.connector.cursor import MySQLCursorBuffered
|
||||
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class MigrationABC(ABC):
|
||||
name = None
|
||||
prio = 0
|
||||
|
||||
@abstractmethod
|
||||
@ServiceProviderABC.inject
|
||||
def __init__(self, db: DBContext):
|
||||
self._cursor: MySQLCursorBuffered = db.cursor
|
||||
|
||||
@abstractmethod
|
||||
def upgrade(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def downgrade(self):
|
||||
pass
|
||||
|
||||
def _exec(self, self_file: str, file: str):
|
||||
path = f"{os.path.dirname(os.path.realpath(self_file))}/db_history_scripts"
|
||||
sql = open(f"{path}/{file}").read()
|
||||
|
||||
for statement in sql.split("\n\n"):
|
||||
self._cursor.execute(statement + ";")
|
71
bot/src/bot_data/abc/server_config_repository_abc.py
Normal file
71
bot/src/bot_data/abc/server_config_repository_abc.py
Normal file
@@ -0,0 +1,71 @@
|
||||
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
|
46
bot/src/bot_data/abc/server_repository_abc.py
Normal file
46
bot/src/bot_data/abc/server_repository_abc.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.filter.discord.server_select_criteria import ServerSelectCriteria
|
||||
from bot_data.filtered_result import FilteredResult
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class ServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_servers(self) -> List[Server]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_filtered_servers(self, criteria: ServerSelectCriteria) -> FilteredResult:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_by_id(self, id: int) -> Server:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_by_discord_id(self, discord_id: int) -> Server:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_server(self, server: Server):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_server(self, server: Server):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_server(self, server: Server):
|
||||
pass
|
39
bot/src/bot_data/abc/short_role_name_repository_abc.py
Normal file
39
bot/src/bot_data/abc/short_role_name_repository_abc.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.short_role_name import ShortRoleName
|
||||
|
||||
|
||||
class ShortRoleNameRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_short_role_names(self) -> List[ShortRoleName]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_short_role_name_by_id(self, id: int) -> ShortRoleName:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_short_role_names_by_role_id(self, role_id: int) -> List[ShortRoleName]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_short_role_names_by_server_id(self, id: int) -> List[ShortRoleName]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_short_role_name(self, short_role_name: ShortRoleName):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_short_role_name(self, short_role_name: ShortRoleName):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_short_role_name(self, short_role_name: ShortRoleName):
|
||||
pass
|
32
bot/src/bot_data/abc/steam_special_offer_repository_abc.py
Normal file
32
bot/src/bot_data/abc/steam_special_offer_repository_abc.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.steam_special_offer import SteamSpecialOffer
|
||||
|
||||
|
||||
class SteamSpecialOfferRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_steam_special_offers(self) -> List[SteamSpecialOffer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_steam_special_offer_by_name(self, name: str) -> SteamSpecialOffer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_steam_special_offer(self, steam_special_offer: SteamSpecialOffer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_steam_special_offer(self, steam_special_offer: SteamSpecialOffer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_steam_special_offer(self, steam_special_offer: SteamSpecialOffer):
|
||||
pass
|
15
bot/src/bot_data/abc/table_with_id_abc.py
Normal file
15
bot/src/bot_data/abc/table_with_id_abc.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class TableWithIdABC(TableABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self.__init__()
|
||||
|
||||
self._id = 0
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
61
bot/src/bot_data/abc/technician_config_repository_abc.py
Normal file
61
bot/src/bot_data/abc/technician_config_repository_abc.py
Normal file
@@ -0,0 +1,61 @@
|
||||
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
|
51
bot/src/bot_data/abc/user_game_ident_repository_abc.py
Normal file
51
bot/src/bot_data/abc/user_game_ident_repository_abc.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_game_ident import UserGameIdent
|
||||
|
||||
|
||||
class UserGameIdentRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_idents(self) -> List[UserGameIdent]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_idents_by_game_server_id(self, id: int) -> List[UserGameIdent]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_ident_by_ident(self, ident: str) -> UserGameIdent:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_game_ident_by_ident(self, ident: str) -> UserGameIdent:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_idents_by_user_id(self, user_id: int) -> List[UserGameIdent]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_game_ident(self, user_game_ident: UserGameIdent):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_game_ident(self, user_game_ident: UserGameIdent):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_game_ident(self, user_game_ident: UserGameIdent):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_game_ident_by_user_id(self, user_id: int):
|
||||
pass
|
@@ -0,0 +1,66 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_joined_game_server import UserJoinedGameServer
|
||||
|
||||
|
||||
class UserJoinedGameServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_game_servers(self) -> List[UserJoinedGameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_game_server_by_id(self, id: int) -> UserJoinedGameServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_game_servers_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[UserJoinedGameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_active_user_joined_game_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> UserJoinedGameServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_game_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserJoinedGameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_game_servers_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[Optional[UserJoinedGameServer]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_joined_game_server(
|
||||
self, user_joined_game_server: UserJoinedGameServer
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_joined_game_server(
|
||||
self, user_joined_game_server: UserJoinedGameServer
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_game_server(
|
||||
self, user_joined_game_server: UserJoinedGameServer
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_game_server_by_user_id(self, user_id: int):
|
||||
pass
|
54
bot/src/bot_data/abc/user_joined_server_repository_abc.py
Normal file
54
bot/src/bot_data/abc/user_joined_server_repository_abc.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_joined_server import UserJoinedServer
|
||||
|
||||
|
||||
class UserJoinedServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers(self) -> List[UserJoinedServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_server_by_server_id(self, server_id: int) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers_by_user_id(
|
||||
self, user_id: int
|
||||
) -> list[UserJoinedServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_active_user_joined_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserJoinedServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
pass
|
@@ -0,0 +1,65 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
||||
|
||||
|
||||
class UserJoinedVoiceChannelRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_voice_channels(self) -> List[UserJoinedVoiceChannel]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_voice_channel_by_id(self, id: int) -> UserJoinedVoiceChannel:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_voice_channels_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[UserJoinedVoiceChannel]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_active_user_joined_voice_channel_by_user_id(
|
||||
self, user_id: int
|
||||
) -> UserJoinedVoiceChannel:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_voice_channel_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserJoinedVoiceChannel]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_voice_channels_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[Optional[UserJoinedVoiceChannel]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_joined_voice_channel(
|
||||
self, user_joined_voice_channel: UserJoinedVoiceChannel
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_joined_voice_channel(
|
||||
self, user_joined_voice_channel: UserJoinedVoiceChannel
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_voice_channel(
|
||||
self, user_joined_voice_channel: UserJoinedVoiceChannel
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_voice_channel_by_user_id(self, user_id: int):
|
||||
pass
|
@@ -0,0 +1,51 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_message_count_per_hour import UserMessageCountPerHour
|
||||
|
||||
|
||||
class UserMessageCountPerHourRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_message_count_per_hours(self) -> List[UserMessageCountPerHour]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_message_count_per_hour_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserMessageCountPerHour]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_message_count_per_hour_by_user_id_and_date(
|
||||
self, user_id: int, date: datetime
|
||||
) -> Optional[UserMessageCountPerHour]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_message_count_per_hour_by_user_id_and_date(
|
||||
self, user_id: int, date: datetime
|
||||
) -> Optional[UserMessageCountPerHour]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_message_count_per_hour_by_user_id(self, user_id: int):
|
||||
pass
|
56
bot/src/bot_data/abc/user_repository_abc.py
Normal file
56
bot/src/bot_data/abc/user_repository_abc.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class UserRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users(self) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_id(self, id: int) -> User:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_id(self, id: int) -> Optional[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> User:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> Optional[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user(self, user: User):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user(self, user: User):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user(self, user: User):
|
||||
pass
|
35
bot/src/bot_data/abc/user_warnings_repository_abc.py
Normal file
35
bot/src/bot_data/abc/user_warnings_repository_abc.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_warnings import UserWarnings
|
||||
|
||||
|
||||
class UserWarningsRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_warnings(self) -> List[UserWarnings]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_warnings_by_id(self, id: int) -> UserWarnings:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_warnings_by_user_id(self, user_id: int) -> List[UserWarnings]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_warnings(self, user_warnings: UserWarnings):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_warnings(self, user_warnings: UserWarnings):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_warnings(self, user_warnings: UserWarnings):
|
||||
pass
|
44
bot/src/bot_data/bot-data.json
Normal file
44
bot/src/bot_data/bot-data.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-data",
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "2",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "Keksdose bot - data",
|
||||
"LongDescription": "Discord bot for the Keksdose discord Server - database package",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2022",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core==2022.12.0"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.12.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "library",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "",
|
||||
"EntryPoint": "",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
139
bot/src/bot_data/data_module.py
Normal file
139
bot/src/bot_data/data_module.py
Normal file
@@ -0,0 +1,139 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
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 bot_data.abc.achievement_repository_abc import AchievementRepositoryABC
|
||||
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.short_role_name_repository_abc import ShortRoleNameRepositoryABC
|
||||
from bot_data.abc.steam_special_offer_repository_abc import (
|
||||
SteamSpecialOfferRepositoryABC,
|
||||
)
|
||||
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
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import (
|
||||
UserJoinedVoiceChannelRepositoryABC,
|
||||
)
|
||||
from bot_data.abc.user_message_count_per_hour_repository_abc import (
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
)
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.service.achievements_repository_service import (
|
||||
AchievementRepositoryService,
|
||||
)
|
||||
from bot_data.service.api_key_repository_service import ApiKeyRepositoryService
|
||||
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
||||
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||
from bot_data.service.cache_service import CacheService
|
||||
from bot_data.service.client_repository_service import ClientRepositoryService
|
||||
from bot_data.service.game_server_repository_service import GameServerRepositoryService
|
||||
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.short_role_name_repository_service import (
|
||||
ShortRoleNameRepositoryService,
|
||||
)
|
||||
from bot_data.service.steam_special_offer_repository_service import (
|
||||
SteamSpecialOfferRepositoryService,
|
||||
)
|
||||
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 (
|
||||
UserJoinedServerRepositoryService,
|
||||
)
|
||||
from bot_data.service.user_joined_voice_channel_repository_service import (
|
||||
UserJoinedVoiceChannelRepositoryService,
|
||||
)
|
||||
from bot_data.service.user_message_count_per_hour_repository_service import (
|
||||
UserMessageCountPerHourRepositoryService,
|
||||
)
|
||||
from bot_data.service.user_repository_service import UserRepositoryService
|
||||
from bot_data.service.user_warnings_repository_service import (
|
||||
UserWarningsRepositoryService,
|
||||
)
|
||||
|
||||
|
||||
class DataModule(ModuleABC):
|
||||
def __init__(self, dc: DiscordCollectionABC):
|
||||
ModuleABC.__init__(self, dc, FeatureFlagsEnum.data_module)
|
||||
|
||||
def configure_configuration(
|
||||
self, config: ConfigurationABC, env: ApplicationEnvironmentABC
|
||||
):
|
||||
pass
|
||||
|
||||
def configure_services(
|
||||
self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC
|
||||
):
|
||||
services.add_singleton(CacheService)
|
||||
|
||||
services.add_transient(ApiKeyRepositoryABC, ApiKeyRepositoryService)
|
||||
services.add_transient(AuthUserRepositoryABC, AuthUserRepositoryService)
|
||||
services.add_transient(ServerRepositoryABC, ServerRepositoryService)
|
||||
services.add_transient(UserRepositoryABC, UserRepositoryService)
|
||||
services.add_transient(ClientRepositoryABC, ClientRepositoryService)
|
||||
services.add_transient(KnownUserRepositoryABC, KnownUserRepositoryService)
|
||||
services.add_transient(
|
||||
UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService
|
||||
)
|
||||
services.add_transient(
|
||||
UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService
|
||||
)
|
||||
services.add_transient(
|
||||
UserJoinedGameServerRepositoryABC, UserJoinedGameServerRepositoryService
|
||||
)
|
||||
services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService)
|
||||
services.add_transient(LevelRepositoryABC, LevelRepositoryService)
|
||||
services.add_transient(UserWarningsRepositoryABC, UserWarningsRepositoryService)
|
||||
services.add_transient(
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
UserMessageCountPerHourRepositoryService,
|
||||
)
|
||||
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(
|
||||
ShortRoleNameRepositoryABC, ShortRoleNameRepositoryService
|
||||
)
|
||||
services.add_transient(
|
||||
SteamSpecialOfferRepositoryABC, SteamSpecialOfferRepositoryService
|
||||
)
|
||||
|
||||
services.add_transient(SeederService)
|
||||
services.add_transient(DataSeederABC, TechnicianConfigSeeder)
|
||||
services.add_transient(DataSeederABC, ServerConfigSeeder)
|
46
bot/src/bot_data/db_context.py
Normal file
46
bot/src/bot_data/db_context.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import time
|
||||
|
||||
from cpl_core.database import DatabaseSettings
|
||||
from cpl_core.database.context import DatabaseContext
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
|
||||
|
||||
class DBContext(DatabaseContext):
|
||||
def __init__(self, logger: DatabaseLogger):
|
||||
self._logger = logger
|
||||
|
||||
DatabaseContext.__init__(self)
|
||||
self._fails = 0
|
||||
|
||||
def connect(self, database_settings: DatabaseSettings):
|
||||
try:
|
||||
self._logger.debug(__name__, "Connecting to database")
|
||||
self._db.connect(database_settings)
|
||||
self._logger.info(__name__, "Connected to database")
|
||||
except Exception as e:
|
||||
self._logger.fatal(__name__, "Connecting to database failed", e)
|
||||
|
||||
def save_changes(self):
|
||||
try:
|
||||
self._logger.trace(__name__, "Save changes")
|
||||
super(DBContext, self).save_changes()
|
||||
self._logger.debug(__name__, "Saved changes")
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "Saving changes failed", e)
|
||||
|
||||
def select(self, statement: str) -> list[tuple]:
|
||||
try:
|
||||
return super(DBContext, self).select(statement)
|
||||
except Exception as e:
|
||||
if self._fails >= 3:
|
||||
self._logger.fatal(__name__, f"Database error caused by {statement}", e)
|
||||
|
||||
self._logger.error(__name__, f"Database error caused by {statement}", e)
|
||||
self._fails += 1
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
return self.select(statement)
|
||||
except Exception as e:
|
||||
pass
|
||||
return []
|
23
bot/src/bot_data/filtered_result.py
Normal file
23
bot/src/bot_data/filtered_result.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class FilteredResult:
|
||||
def __init__(self, result: List = None, total_count: int = 0):
|
||||
self._result = [] if result is None else result
|
||||
self._total_count = total_count
|
||||
|
||||
@property
|
||||
def result(self) -> List:
|
||||
return self._result
|
||||
|
||||
@result.setter
|
||||
def result(self, value: List):
|
||||
self._result = value
|
||||
|
||||
@property
|
||||
def total_count(self) -> int:
|
||||
return self._total_count
|
||||
|
||||
@total_count.setter
|
||||
def total_count(self, value: int):
|
||||
self._total_count = value
|
26
bot/src/bot_data/migration/__init__.py
Normal file
26
bot/src/bot_data/migration/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
bot sh-edraft.de Discord bot
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Discord bot for customers of sh-edraft.de
|
||||
|
||||
:copyright: (c) 2022 - 2023 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "bot_data.migration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.2.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="2", micro="0")
|
147
bot/src/bot_data/migration/achievements_migration.py
Normal file
147
bot/src/bot_data/migration/achievements_migration.py
Normal file
@@ -0,0 +1,147 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class AchievementsMigration(MigrationABC):
|
||||
name = "1.1.0_AchievementsMigration"
|
||||
|
||||
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 `Achievements` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`Attribute` VARCHAR(255) NOT NULL,
|
||||
`Operator` VARCHAR(255) NOT NULL,
|
||||
`Value` VARCHAR(255) NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`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 `AchievementsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`Attribute` VARCHAR(255) NOT NULL,
|
||||
`Operator` VARCHAR(255) NOT NULL,
|
||||
`Value` VARCHAR(255) NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserGotAchievements` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT,
|
||||
`AchievementId` BIGINT,
|
||||
`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 (`UserId`) REFERENCES `Users`(`UserId`),
|
||||
FOREIGN KEY (`AchievementId`) REFERENCES `Achievements`(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
# A join table history between users and achievements is not necessary.
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""ALTER TABLE Users ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""ALTER TABLE Users ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""ALTER TABLE UsersHistory ADD MessageCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""ALTER TABLE UsersHistory ADD ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""DROP TRIGGER IF EXISTS `TR_AchievementsUpdate`;""")
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TRIGGER `TR_AchievementsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Achievements`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AchievementsHistory` (
|
||||
`Id`, `Name`, `Description`, `Attribute`, `Operator`, `Value`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Description, OLD.Attribute, OLD.Operator, OLD.Value, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""DROP TRIGGER IF EXISTS `TR_AchievementsDelete`;""")
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TRIGGER `TR_AchievementsDelete`
|
||||
AFTER DELETE
|
||||
ON `Achievements`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AchievementsHistory` (
|
||||
`Id`, `Name`, `Description`, `Attribute`, `Operator`, `Value`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Description, OLD.Attribute, OLD.Operator, OLD.Value, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `Achievements`;")
|
||||
|
||||
self._cursor.execute(str(f"""ALTER TABLE Users DROP COLUMN MessageCount;"""))
|
||||
self._cursor.execute(str(f"""ALTER TABLE Users DROP COLUMN ReactionCount;"""))
|
38
bot/src/bot_data/migration/api_key_migration.py
Normal file
38
bot/src/bot_data/migration/api_key_migration.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ApiKeyMigration(MigrationABC):
|
||||
name = "1.0.0_ApiKeyMigration"
|
||||
|
||||
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 `ApiKeys` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Identifier` VARCHAR(255) NOT NULL,
|
||||
`Key` VARCHAR(255) NOT NULL,
|
||||
`CreatorId` BIGINT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`CreatorId`) REFERENCES `Users`(`UserId`),
|
||||
CONSTRAINT UC_Identifier_Key UNIQUE (`Identifier`,`Key`),
|
||||
CONSTRAINT UC_Key UNIQUE (`Key`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `ApiKeys`;")
|
61
bot/src/bot_data/migration/api_migration.py
Normal file
61
bot/src/bot_data/migration/api_migration.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ApiMigration(MigrationABC):
|
||||
name = "0.3_ApiMigration"
|
||||
|
||||
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 `AuthUsers` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`FirstName` VARCHAR(255),
|
||||
`LastName` VARCHAR(255),
|
||||
`EMail` VARCHAR(255),
|
||||
`Password` VARCHAR(255),
|
||||
`PasswordSalt` VARCHAR(255),
|
||||
`RefreshToken` VARCHAR(255),
|
||||
`ConfirmationId` VARCHAR(255) DEFAULT NULL,
|
||||
`ForgotPasswordId` VARCHAR(255) DEFAULT NULL,
|
||||
`OAuthId` VARCHAR(255) DEFAULT NULL,
|
||||
`RefreshTokenExpiryTime` DATETIME(6) NOT NULL,
|
||||
`AuthRole` INT NOT NULL DEFAULT 0,
|
||||
`CreatedAt` DATETIME(6) NOT NULL,
|
||||
`LastModifiedAt` DATETIME(6) NOT NULL,
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `AuthUserUsersRelations`(
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`AuthUserId` BIGINT DEFAULT NULL,
|
||||
`UserId` BIGINT DEFAULT NULL,
|
||||
`CreatedAt` DATETIME(6) NOT NULL,
|
||||
`LastModifiedAt` DATETIME(6) NOT NULL,
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`AuthUserId`) REFERENCES `AuthUsers`(`Id`),
|
||||
FOREIGN KEY (`UserId`) REFERENCES `Users`(`UserId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `AuthUsers`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUserUsersRelations`;")
|
33
bot/src/bot_data/migration/auto_role_fix1_migration.py
Normal file
33
bot/src/bot_data/migration/auto_role_fix1_migration.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class AutoRoleFix1Migration(MigrationABC):
|
||||
name = "0.3.0_AutoRoleFixMigration"
|
||||
|
||||
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"""
|
||||
ALTER TABLE AutoRoles ADD DiscordChannelId BIGINT NOT NULL AFTER ServerId;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE AutoRoles DROP COLUMN DiscordChannelId;
|
||||
"""
|
||||
)
|
||||
)
|
53
bot/src/bot_data/migration/auto_role_migration.py
Normal file
53
bot/src/bot_data/migration/auto_role_migration.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class AutoRoleMigration(MigrationABC):
|
||||
name = "0.2.1_AutoRoleMigration"
|
||||
|
||||
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 `AutoRoles` (
|
||||
`AutoRoleId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`ServerId` BIGINT,
|
||||
`DiscordMessageId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`AutoRoleId`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `AutoRoleRules` (
|
||||
`AutoRoleRuleId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`AutoRoleId` BIGINT,
|
||||
`DiscordEmojiName` VARCHAR(64),
|
||||
`DiscordRoleId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`AutoRoleRuleId`),
|
||||
FOREIGN KEY (`AutoRoleId`) REFERENCES `AutoRoles`(`AutoRoleId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `AutoRole`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRoleRules`;")
|
84
bot/src/bot_data/migration/birthday_migration.py
Normal file
84
bot/src/bot_data/migration/birthday_migration.py
Normal file
@@ -0,0 +1,84 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class BirthdayMigration(MigrationABC):
|
||||
name = "1.2.0_BirthdayMigration"
|
||||
|
||||
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"""
|
||||
ALTER TABLE Users
|
||||
ADD Birthday DATE NULL AFTER MessageCount;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE UsersHistory
|
||||
ADD Birthday DATE NULL AFTER MessageCount;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._exec(__file__, "users.sql")
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_Server
|
||||
ADD XpForBirthday BIGINT(20) NOT NULL DEFAULT 0 AFTER XpPerAchievement;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_ServerHistory
|
||||
ADD XpForBirthday BIGINT(20) NOT NULL DEFAULT 0 AFTER XpPerAchievement;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._exec(__file__, "config/server.sql")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE Users DROP COLUMN Birthday;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE UsersHistory DROP COLUMN Birthday;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_Server DROP COLUMN XpForBirthday;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_ServerHistory DROP COLUMN XpForBirthday;
|
||||
"""
|
||||
)
|
||||
)
|
33
bot/src/bot_data/migration/config_feature_flags_migration.py
Normal file
33
bot/src/bot_data/migration/config_feature_flags_migration.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ConfigFeatureFlagsMigration(MigrationABC):
|
||||
name = "1.1.0_ConfigFeatureFlagsMigration"
|
||||
|
||||
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(
|
||||
"""ALTER TABLE CFG_Technician ADD FeatureFlags JSON NULL DEFAULT ('{}') AFTER CacheMaxMessages;"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
"""ALTER TABLE CFG_Server ADD FeatureFlags JSON NULL DEFAULT ('{}') AFTER LoginMessageChannelId;"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._logger.debug(__name__, "Running downgrade")
|
||||
self._cursor.execute("ALTER TABLE CFG_Technician DROP COLUMN FeatureFlags;")
|
||||
self._cursor.execute("ALTER TABLE CFG_Server DROP COLUMN FeatureFlags;")
|
145
bot/src/bot_data/migration/config_migration.py
Normal file
145
bot/src/bot_data/migration/config_migration.py
Normal file
@@ -0,0 +1,145 @@
|
||||
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
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
self._server_upgrade()
|
||||
self._technician_upgrade()
|
||||
|
||||
self._exec(__file__, "config/server.sql")
|
||||
self._exec(__file__, "config/server_afk_channels.sql")
|
||||
self._exec(__file__, "config/server_team_roles.sql")
|
||||
self._exec(__file__, "config/technician.sql")
|
||||
self._exec(__file__, "config/technician_ids.sql")
|
||||
self._exec(__file__, "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")
|
||||
self._server_downgrade()
|
||||
self._technician_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`;")
|
56
bot/src/bot_data/migration/db_history_migration.py
Normal file
56
bot/src/bot_data/migration/db_history_migration.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class DBHistoryMigration(MigrationABC):
|
||||
name = "1.0.0_DBHistoryMigration"
|
||||
prio = 1
|
||||
|
||||
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._exec(__file__, "api_keys.sql")
|
||||
self._exec(__file__, "auth_users.sql")
|
||||
self._exec(__file__, "auth_user_users_relation.sql")
|
||||
self._exec(__file__, "auto_role_rules.sql")
|
||||
self._exec(__file__, "auto_roles.sql")
|
||||
self._exec(__file__, "clients.sql")
|
||||
self._exec(__file__, "game_servers.sql")
|
||||
self._exec(__file__, "known_users.sql")
|
||||
self._exec(__file__, "levels.sql")
|
||||
self._exec(__file__, "servers.sql")
|
||||
self._exec(__file__, "user_game_idents.sql")
|
||||
self._exec(__file__, "user_joined_game_servers.sql")
|
||||
self._exec(__file__, "user_joined_servers.sql")
|
||||
self._exec(__file__, "user_joined_voice_channel.sql")
|
||||
self._exec(__file__, "user_message_count_per_hour.sql")
|
||||
self._exec(__file__, "users.sql")
|
||||
self._exec(__file__, "user_warnings.sql")
|
||||
|
||||
self._logger.debug(__name__, "Finished history upgrade")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `ApiKeysHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUserUsersRelationsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRoleRulesHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRolesHistory`;")
|
||||
self._cursor.execute("DROP TABLE `ClientsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `GameServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `KnownUsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `LevelsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `ServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserGameIdentsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedGameServerHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedVoiceChannelHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserMessageCountPerHourHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserWarningsHistory`;")
|
46
bot/src/bot_data/migration/db_history_scripts/api_keys.sql
Normal file
46
bot/src/bot_data/migration/db_history_scripts/api_keys.sql
Normal file
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `ApiKeys`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `ApiKeys`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ApiKeysHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Identifier` VARCHAR(255) NOT NULL,
|
||||
`Key` VARCHAR(255) NOT NULL,
|
||||
`CreatorId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ApiKeysUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ApiKeysUpdate`
|
||||
AFTER UPDATE
|
||||
ON `ApiKeys`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ApiKeysHistory` (
|
||||
`Id`, `Identifier`, `Key`, `CreatorId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Identifier, OLD.Key, OLD.CreatorId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ApiKeysDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ApiKeysDelete`
|
||||
AFTER DELETE
|
||||
ON `ApiKeys`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ApiKeysHistory` (
|
||||
`Id`, `Identifier`, `Key`, `CreatorId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Identifier, OLD.Key, OLD.CreatorId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `AuthUserUsersRelations`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AuthUserUsersRelations`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AuthUserUsersRelationsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`AuthUserId` BIGINT(20) DEFAULT NULL,
|
||||
`UserId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUserUsersRelationsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUserUsersRelationsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AuthUserUsersRelations`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUserUsersRelationsHistory` (
|
||||
`Id`, `AuthUserId`, `UserId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.AuthUserId, OLD.UserId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUserUsersRelationsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUserUsersRelationsDelete`
|
||||
AFTER DELETE
|
||||
ON `AuthUserUsersRelations`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUserUsersRelationsHistory` (
|
||||
`Id`, `AuthUserId`, `UserId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.AuthUserId, OLD.UserId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
62
bot/src/bot_data/migration/db_history_scripts/auth_users.sql
Normal file
62
bot/src/bot_data/migration/db_history_scripts/auth_users.sql
Normal file
@@ -0,0 +1,62 @@
|
||||
ALTER TABLE `AuthUsers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AuthUsers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AuthUsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`FirstName` VARCHAR(255) DEFAULT NULL,
|
||||
`LastName` VARCHAR(255) DEFAULT NULL,
|
||||
`EMail` VARCHAR(255) DEFAULT NULL,
|
||||
`Password` VARCHAR(255) DEFAULT NULL,
|
||||
`PasswordSalt` VARCHAR(255) DEFAULT NULL,
|
||||
`RefreshToken` VARCHAR(255) DEFAULT NULL,
|
||||
`ConfirmationId` VARCHAR(255) DEFAULT NULL,
|
||||
`ForgotPasswordId` VARCHAR(255) DEFAULT NULL,
|
||||
`OAuthId` VARCHAR(255) DEFAULT NULL,
|
||||
`RefreshTokenExpiryTime` DATETIME(6) NOT NULL,
|
||||
`AuthRole` BIGINT(11) NOT NULL DEFAULT 0,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AuthUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUsersHistory` (
|
||||
`Id`, `FirstName`, `LastName`, `EMail`, `Password`, `PasswordSalt`,
|
||||
`RefreshToken`, `ConfirmationId`, `ForgotPasswordId`, `OAuthId`,
|
||||
`RefreshTokenExpiryTime`, `AuthRole`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.FirstName, OLD.LastName, OLD.EMail, OLD.Password, OLD.PasswordSalt, OLD.RefreshToken,
|
||||
OLD.ConfirmationId, OLD.ForgotPasswordId, OLD.OAuthId, OLD.RefreshTokenExpiryTime, OLD.AuthRole,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUsersDelete`
|
||||
AFTER DELETE
|
||||
ON `AuthUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUsersHistory` (
|
||||
`Id`, `FirstName`, `LastName`, `EMail`, `Password`, `PasswordSalt`, `RefreshToken`,
|
||||
`ConfirmationId`, `ForgotPasswordId`, `OAuthId`, `RefreshTokenExpiryTime`,
|
||||
`AuthRole`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.FirstName, OLD.LastName, OLD.EMail, OLD.Password, OLD.PasswordSalt, OLD.RefreshToken,
|
||||
OLD.ConfirmationId, OLD.ForgotPasswordId, OLD.OAuthId, OLD.RefreshTokenExpiryTime, OLD.AuthRole, TRUE,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `AutoRoleRules`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AutoRoleRules`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AutoRoleRulesHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`AutoRoleId` BIGINT(20) DEFAULT NULL,
|
||||
`DiscordEmojiName` VARCHAR(64) DEFAULT NULL,
|
||||
`DiscordRoleId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRoleRulesUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRoleRulesUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AutoRoleRules`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRoleRulesHistory` (
|
||||
`Id`, `AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleRuleId, OLD.AutoRoleId, OLD.DiscordEmojiName, OLD.DiscordRoleId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRoleRulesDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRoleRulesDelete`
|
||||
AFTER DELETE
|
||||
ON `AutoRoleRules`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRoleRulesHistory` (
|
||||
`Id`, `AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleRuleId, OLD.AutoRoleId, OLD.DiscordEmojiName, OLD.DiscordRoleId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
48
bot/src/bot_data/migration/db_history_scripts/auto_roles.sql
Normal file
48
bot/src/bot_data/migration/db_history_scripts/auto_roles.sql
Normal file
@@ -0,0 +1,48 @@
|
||||
ALTER TABLE `AutoRoles`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AutoRoles`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AutoRolesHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`DiscordChannelId` BIGINT(20) NOT NULL,
|
||||
`DiscordMessageId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRolesUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRolesUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AutoRoles`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRolesHistory` (
|
||||
`Id`, `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleId, OLD.ServerId, OLD.DiscordChannelId, OLD.DiscordMessageId, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRolesDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRolesDelete`
|
||||
AFTER DELETE
|
||||
ON `AutoRoles`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRolesHistory` (
|
||||
`Id`, `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleId, OLD.ServerId, OLD.DiscordChannelId, OLD.DiscordMessageId, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
54
bot/src/bot_data/migration/db_history_scripts/clients.sql
Normal file
54
bot/src/bot_data/migration/db_history_scripts/clients.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
ALTER TABLE `Clients`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Clients`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ClientsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`SentMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ReceivedMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`DeletedMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ReceivedCommandsCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`MovedUsersCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ClientsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ClientsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Clients`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ClientsHistory` (
|
||||
`Id`, `DiscordId`, `SentMessageCount`, `ReceivedMessageCount`, `DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`, `MovedUsersCount`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ClientId, OLD.DiscordClientId, OLD.SentMessageCount, OLD.ReceivedMessageCount, OLD.DeletedMessageCount,
|
||||
OLD.ReceivedCommandsCount, OLD.MovedUsersCount, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ClientsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ClientsDelete`
|
||||
AFTER DELETE
|
||||
ON `Clients`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ClientsHistory` (
|
||||
`Id`, `DiscordId`, `SentMessageCount`, `ReceivedMessageCount`, `DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`, `MovedUsersCount`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ClientId, OLD.DiscordClientId, OLD.SentMessageCount, OLD.ReceivedMessageCount, OLD.DeletedMessageCount,
|
||||
OLD.ReceivedCommandsCount, OLD.MovedUsersCount, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
124
bot/src/bot_data/migration/db_history_scripts/config/server.sql
Normal file
124
bot/src/bot_data/migration/db_history_scripts/config/server.sql
Normal file
@@ -0,0 +1,124 @@
|
||||
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,
|
||||
`DefaultRoleId` BIGINT NULL,
|
||||
`ShortRoleNameSetOnlyHighest` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`FeatureFlags` JSON NULL DEFAULT ('{}'),
|
||||
`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`,
|
||||
`DefaultRoleId`,
|
||||
`ShortRoleNameSetOnlyHighest`,
|
||||
`FeatureFlags`,
|
||||
`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.DefaultRoleId,
|
||||
OLD.ShortRoleNameSetOnlyHighest,
|
||||
OLD.FeatureFlags,
|
||||
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`,
|
||||
`DefaultRoleId`,
|
||||
`ShortRoleNameSetOnlyHighest`,
|
||||
`ServerId`,
|
||||
`FeatureFlags`,
|
||||
`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.DefaultRoleId,
|
||||
OLD.ShortRoleNameSetOnlyHighest,
|
||||
OLD.FeatureFlags,
|
||||
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,64 @@
|
||||
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,
|
||||
`FeatureFlags` JSON NULL DEFAULT ('{}'),
|
||||
`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`,
|
||||
`FeatureFlags`,
|
||||
`DateFrom`,
|
||||
`DateTo`)
|
||||
VALUES (OLD.Id,
|
||||
OLD.HelpCommandReferenceUrl,
|
||||
OLD.WaitForRestart,
|
||||
OLD.WaitForShutdown,
|
||||
OLD.CacheMaxMessages,
|
||||
OLD.FeatureFlags,
|
||||
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`,
|
||||
`FeatureFlags`,
|
||||
`Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`)
|
||||
VALUES (OLD.Id,
|
||||
OLD.HelpCommandReferenceUrl,
|
||||
OLD.WaitForRestart,
|
||||
OLD.WaitForShutdown,
|
||||
OLD.CacheMaxMessages,
|
||||
OLD.FeatureFlags,
|
||||
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;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `GameServers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `GameServers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `GameServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`ServerId` BIGINT(20) NOT NULL,
|
||||
`ApiKeyId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_GameServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_GameServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `GameServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `GameServersHistory` (
|
||||
`Id`, `Name`, `ServerId`, `ApiKeyId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.ServerId, OLD.ApiKeyId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_GameServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_GameServersDelete`
|
||||
AFTER DELETE
|
||||
ON `GameServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `GameServersHistory` (
|
||||
`Id`, `Name`, `ServerId`, `ApiKeyId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.ServerId, OLD.ApiKeyId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,44 @@
|
||||
ALTER TABLE `KnownUsers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `KnownUsers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `KnownUsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_KnownUsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_KnownUsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `KnownUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `KnownUsersHistory` (
|
||||
`Id`, `DiscordId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.KnownUserId, OLD.DiscordId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_KnownUsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_KnownUsersDelete`
|
||||
AFTER DELETE
|
||||
ON `KnownUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `KnownUsersHistory` (
|
||||
`Id`, `DiscordId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.KnownUserId, OLD.DiscordId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
50
bot/src/bot_data/migration/db_history_scripts/levels.sql
Normal file
50
bot/src/bot_data/migration/db_history_scripts/levels.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
ALTER TABLE `Levels`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Levels`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `LevelsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Color` VARCHAR(8) NOT NULL,
|
||||
`MinXp` BIGINT(20) NOT NULL,
|
||||
`PermissionInt` BIGINT(20) NOT NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_LevelsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_LevelsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Levels`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `LevelsHistory` (
|
||||
`Id`, `Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Color, OLD.MinXp, OLD.PermissionInt, OLD.ServerId, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_LevelsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_LevelsDelete`
|
||||
AFTER DELETE
|
||||
ON `Levels`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `LevelsHistory` (
|
||||
`Id`, `Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Color, OLD.MinXp, OLD.PermissionInt, OLD.ServerId, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
44
bot/src/bot_data/migration/db_history_scripts/servers.sql
Normal file
44
bot/src/bot_data/migration/db_history_scripts/servers.sql
Normal file
@@ -0,0 +1,44 @@
|
||||
ALTER TABLE `Servers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Servers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Servers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ServersHistory` (
|
||||
`Id`, `DiscordId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ServerId, OLD.DiscordServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ServersDelete`
|
||||
AFTER DELETE
|
||||
ON `Servers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ServersHistory` (
|
||||
`Id`, `DiscordId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ServerId, OLD.DiscordServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,38 @@
|
||||
CREATE TABLE IF NOT EXISTS `ShortRoleNamesHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`ShortName` VARCHAR(64) DEFAULT NULL,
|
||||
`DiscordRoleId` BIGINT(20) NOT NULL,
|
||||
`Position` ENUM ('Before', 'After') NOT NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ShortRoleNamesUpdate`
|
||||
AFTER UPDATE
|
||||
ON `ShortRoleNames`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `Position`, `ServerId`, `DateFrom`,
|
||||
`DateTo`)
|
||||
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.Position, OLD.ServerId, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6));
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ShortRoleNamesDelete`
|
||||
AFTER DELETE
|
||||
ON `ShortRoleNames`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `Position`, `ServerId`, `Deleted`,
|
||||
`DateFrom`,
|
||||
`DateTo`)
|
||||
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.Position, OLD.ServerId, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6));
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserGameIdents`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserGameIdents`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserGameIdentsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`GameServerId` BIGINT(20) NOT NULL,
|
||||
`Ident` VARCHAR(255) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserGameIdentsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserGameIdentsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserGameIdents`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserGameIdentsHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `Ident`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserGameIdentsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserGameIdentsDelete`
|
||||
AFTER DELETE
|
||||
ON `UserGameIdents`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserGameIdentsHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `Ident`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,47 @@
|
||||
ALTER TABLE `UserJoinedGameServer`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedGameServer`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedGameServerHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`GameServerId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedGameServerUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedGameServer`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedGameServerHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedGameServerDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedGameServer`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedGameServerHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserJoinedServers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedServers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedServersHistory` (
|
||||
`Id`, `UserId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedServersDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedServersHistory` (
|
||||
`Id`, `UserId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,49 @@
|
||||
ALTER TABLE `UserJoinedVoiceChannel`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedVoiceChannel`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedVoiceChannelHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`DiscordChannelId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedVoiceChannelUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedVoiceChannel`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedVoiceChannelHistory` (
|
||||
`Id`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedVoiceChannelDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedVoiceChannel`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedVoiceChannelHistory` (
|
||||
`Id`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,47 @@
|
||||
ALTER TABLE `UserMessageCountPerHour`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserMessageCountPerHour`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserMessageCountPerHourHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Date` DATETIME(6) NOT NULL,
|
||||
`Hour` BIGINT(20) DEFAULT NULL,
|
||||
`XPCount` BIGINT(20) DEFAULT NULL,
|
||||
`UserId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserMessageCountPerHourUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserMessageCountPerHour`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserMessageCountPerHourHistory` (
|
||||
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserMessageCountPerHourDelete`
|
||||
AFTER DELETE
|
||||
ON `UserMessageCountPerHour`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserMessageCountPerHourHistory` (
|
||||
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserWarnings`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserWarnings`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserWarningsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`Author` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserWarningsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserWarningsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserWarnings`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserWarningsHistory` (
|
||||
`Id`, `Description`, `UserId`, `Author`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserWarningsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserWarningsDelete`
|
||||
AFTER DELETE
|
||||
ON `UserWarnings`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserWarningsHistory` (
|
||||
`Id`, `Description`, `UserId`, `Author`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
45
bot/src/bot_data/migration/db_history_scripts/users.sql
Normal file
45
bot/src/bot_data/migration/db_history_scripts/users.sql
Normal file
@@ -0,0 +1,45 @@
|
||||
ALTER TABLE `Users`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Users`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`XP` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ReactionCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`MessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`Birthday` DATE NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Users`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UsersHistory` (`Id`, `DiscordId`, `XP`, `ReactionCount`, `MessageCount`, `Birthday`, `ServerId`,
|
||||
`DateFrom`, `DateTo`)
|
||||
VALUES (OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ReactionCount, OLD.MessageCount, OLD.Birthday, OLD.ServerId,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6));
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UsersDelete`
|
||||
AFTER DELETE
|
||||
ON `Users`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UsersHistory` (`Id`, `DiscordId`, `XP`, `ReactionCount`, `MessageCount`, `Birthday`, `ServerId`,
|
||||
`Deleted`, `DateFrom`, `DateTo`)
|
||||
VALUES (OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ReactionCount, OLD.MessageCount, OLD.Birthday, OLD.ServerId, TRUE,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6));
|
||||
END;
|
34
bot/src/bot_data/migration/default_role_migration.py
Normal file
34
bot/src/bot_data/migration/default_role_migration.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class DefaultRoleMigration(MigrationABC):
|
||||
name = "1.1.3_DefaultRoleMigration"
|
||||
|
||||
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"""
|
||||
ALTER TABLE CFG_Server
|
||||
ADD DefaultRoleId BIGINT NULL AFTER LoginMessageChannelId;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_Server DROP COLUMN DefaultRoleId;
|
||||
"""
|
||||
)
|
||||
)
|
53
bot/src/bot_data/migration/fix_updates_migration.py
Normal file
53
bot/src/bot_data/migration/fix_updates_migration.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class FixUpdatesMigration(MigrationABC):
|
||||
name = "1.1.7_FixUpdatesMigration"
|
||||
|
||||
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"""
|
||||
ALTER TABLE CFG_ServerHistory
|
||||
ADD DefaultRoleId BIGINT NULL AFTER LoginMessageChannelId;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
"""ALTER TABLE CFG_TechnicianHistory ADD FeatureFlags JSON NULL DEFAULT ('{}') AFTER CacheMaxMessages;"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
"""ALTER TABLE CFG_ServerHistory ADD FeatureFlags JSON NULL DEFAULT ('{}') AFTER LoginMessageChannelId;"""
|
||||
)
|
||||
)
|
||||
|
||||
self._exec(__file__, "config/server.sql")
|
||||
self._exec(__file__, "config/technician.sql")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_ServerHistory DROP COLUMN DefaultRoleId;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
"ALTER TABLE CFG_TechnicianHistory DROP COLUMN FeatureFlags;"
|
||||
)
|
||||
self._cursor.execute("ALTER TABLE CFG_ServerHistory DROP COLUMN FeatureFlags;")
|
45
bot/src/bot_data/migration/fix_user_history_migration.py
Normal file
45
bot/src/bot_data/migration/fix_user_history_migration.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class FixUserHistoryMigration(MigrationABC):
|
||||
name = "1.2.0_FixUserHistoryMigration"
|
||||
|
||||
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")
|
||||
|
||||
# fix 1.1.0_AchievementsMigration
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""ALTER TABLE UsersHistory ADD COLUMN IF NOT EXISTS ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""ALTER TABLE UsersHistory ADD COLUMN IF NOT EXISTS MessageCount BIGINT NOT NULL DEFAULT 0 AFTER ReactionCount;"""
|
||||
)
|
||||
)
|
||||
self._exec(__file__, "users.sql")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE UsersHistory DROP COLUMN MessageCount;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE UsersHistory DROP COLUMN ReactionCount;
|
||||
"""
|
||||
)
|
||||
)
|
138
bot/src/bot_data/migration/initial_migration.py
Normal file
138
bot/src/bot_data/migration/initial_migration.py
Normal file
@@ -0,0 +1,138 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class InitialMigration(MigrationABC):
|
||||
name = "0.1_InitialMigration"
|
||||
|
||||
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 `MigrationHistory` (
|
||||
`MigrationId` VARCHAR(255),
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`MigrationId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Servers` (
|
||||
`ServerId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordServerId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Users` (
|
||||
`UserId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordId` BIGINT NOT NULL,
|
||||
`XP` BIGINT NOT NULL DEFAULT 0,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
||||
PRIMARY KEY(`UserId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Clients` (
|
||||
`ClientId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordClientId` BIGINT NOT NULL,
|
||||
`SentMessageCount` BIGINT NOT NULL DEFAULT 0,
|
||||
`ReceivedMessageCount` BIGINT NOT NULL DEFAULT 0,
|
||||
`DeletedMessageCount` BIGINT NOT NULL DEFAULT 0,
|
||||
`ReceivedCommandsCount` BIGINT NOT NULL DEFAULT 0,
|
||||
`MovedUsersCount` BIGINT NOT NULL DEFAULT 0,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
||||
PRIMARY KEY(`ClientId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `KnownUsers` (
|
||||
`KnownUserId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`KnownUserId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedServers` (
|
||||
`JoinId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6),
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`UserId`) REFERENCES Users(`UserId`),
|
||||
PRIMARY KEY(`JoinId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedVoiceChannel` (
|
||||
`JoinId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`DiscordChannelId` BIGINT NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6),
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`UserId`) REFERENCES Users(`UserId`),
|
||||
PRIMARY KEY(`JoinId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `Servers`;")
|
||||
self._cursor.execute("DROP TABLE `Users`;")
|
||||
self._cursor.execute("DROP TABLE `Clients`;")
|
||||
self._cursor.execute("DROP TABLE `KnownUsers`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedServers`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedVoiceChannel`;")
|
38
bot/src/bot_data/migration/level_migration.py
Normal file
38
bot/src/bot_data/migration/level_migration.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class LevelMigration(MigrationABC):
|
||||
name = "0.3_LevelMigration"
|
||||
|
||||
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 `Levels` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Color` VARCHAR(8) NOT NULL,
|
||||
`MinXp` BIGINT NOT NULL,
|
||||
`PermissionInt` BIGINT NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `Levels`;")
|
43
bot/src/bot_data/migration/remove_stats_migration.py
Normal file
43
bot/src/bot_data/migration/remove_stats_migration.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class RemoveStatsMigration(MigrationABC):
|
||||
name = "1.0.0_RemoveStatsMigration"
|
||||
|
||||
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"""
|
||||
DROP TABLE IF EXISTS `Statistics`;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Statistics` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`Code` LONGTEXT NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
40
bot/src/bot_data/migration/short_role_name_migration.py
Normal file
40
bot/src/bot_data/migration/short_role_name_migration.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ShortRoleNameMigration(MigrationABC):
|
||||
name = "1.1.7_ShortRoleNameMigration"
|
||||
|
||||
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 `ShortRoleNames` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`ShortName` VARCHAR(255) NOT NULL,
|
||||
`DiscordRoleId` BIGINT NOT NULL,
|
||||
`Position` ENUM('before', 'after') NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`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._exec(__file__, "short_rule_names.sql")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `ShortRoleNames`;")
|
||||
self._cursor.execute("DROP TABLE `ShortRoleNamesHistory`;")
|
@@ -0,0 +1,51 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ShortRoleNameOnlyHighestMigration(MigrationABC):
|
||||
name = "1.1.9_ShortRoleNameOnlyHighestMigration"
|
||||
|
||||
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"""
|
||||
ALTER TABLE CFG_Server
|
||||
ADD ShortRoleNameSetOnlyHighest BOOLEAN NOT NULL DEFAULT FALSE AFTER DefaultRoleId;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_ServerHistory
|
||||
ADD ShortRoleNameSetOnlyHighest BOOLEAN NOT NULL DEFAULT FALSE AFTER DefaultRoleId;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._exec(__file__, "config/server.sql")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_Server DROP COLUMN ShortRoleNameSetOnlyHighest;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_ServerHistory DROP COLUMN ShortRoleNameSetOnlyHighest;
|
||||
"""
|
||||
)
|
||||
)
|
37
bot/src/bot_data/migration/stats_migration.py
Normal file
37
bot/src/bot_data/migration/stats_migration.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class StatsMigration(MigrationABC):
|
||||
name = "0.3_StatsMigration"
|
||||
|
||||
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 `Statistics` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`Code` LONGTEXT NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `Statistics`;")
|
68
bot/src/bot_data/migration/steam_special_offer_migration.py
Normal file
68
bot/src/bot_data/migration/steam_special_offer_migration.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class SteamSpecialOfferMigration(MigrationABC):
|
||||
name = "1.2.0_SteamSpecialOfferMigration"
|
||||
|
||||
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 `SteamSpecialOffers` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Game` VARCHAR(255) NOT NULL,
|
||||
`OriginalPrice` FLOAT NOT NULL,
|
||||
`DiscountPrice` FLOAT NOT NULL,
|
||||
`DiscountPct` 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`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_Server
|
||||
ADD COLUMN IF NOT EXISTS GameOfferNotificationChatId BIGINT NULL AFTER ShortRoleNameSetOnlyHighest;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_ServerHistory
|
||||
ADD COLUMN IF NOT EXISTS GameOfferNotificationChatId BIGINT NULL AFTER ShortRoleNameSetOnlyHighest;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `SteamSpecialOffers`;")
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_Server DROP COLUMN ShortRoleNameSetOnlyHighest;
|
||||
"""
|
||||
)
|
||||
)
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE CFG_ServerHistory DROP COLUMN ShortRoleNameSetOnlyHighest;
|
||||
"""
|
||||
)
|
||||
)
|
@@ -0,0 +1,77 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserJoinedGameServerMigration(MigrationABC):
|
||||
name = "1.0.0_UserJoinedGameServerMigration"
|
||||
|
||||
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 `GameServers` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`ApiKeyId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
||||
FOREIGN KEY (`ApiKeyId`) REFERENCES ApiKeys(`Id`),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedGameServer` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`GameServerId` BIGINT NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6),
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`UserId`) REFERENCES Users(`UserId`),
|
||||
FOREIGN KEY (`GameServerId`) REFERENCES GameServers(`Id`),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserGameIdents` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`GameServerId` BIGINT NOT NULL,
|
||||
`Ident` VARCHAR(255) NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`UserId`) REFERENCES Users(`UserId`),
|
||||
FOREIGN KEY (`GameServerId`) REFERENCES GameServers(`Id`),
|
||||
CONSTRAINT UC_UserGameIdent UNIQUE (`GameServerId`,`Ident`),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `GameServers`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedGameServer`;")
|
||||
self._cursor.execute("DROP TABLE `UserGameIdents`;")
|
@@ -0,0 +1,37 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserMessageCountPerHourMigration(MigrationABC):
|
||||
name = "0.3.1_UserMessageCountPerHourMigration"
|
||||
|
||||
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 `UserMessageCountPerHour` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Date` DATETIME(6) NOT NULL,
|
||||
`Hour` BIGINT,
|
||||
`XPCount` BIGINT,
|
||||
`UserId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`UserId`) REFERENCES `Users`(`UserId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `UserMessageCountPerHour`;")
|
37
bot/src/bot_data/migration/user_warning_migration.py
Normal file
37
bot/src/bot_data/migration/user_warning_migration.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserWarningMigration(MigrationABC):
|
||||
name = "1.0.0_UserWarningMigration"
|
||||
|
||||
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 `UserWarnings` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`Author` BIGINT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`UserId`) REFERENCES `Users`(`UserId`),
|
||||
FOREIGN KEY (`Author`) REFERENCES `Users`(`UserId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `UserWarnings`;")
|
26
bot/src/bot_data/model/__init__.py
Normal file
26
bot/src/bot_data/model/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
bot sh-edraft.de Discord bot
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Discord bot for customers of sh-edraft.de
|
||||
|
||||
:copyright: (c) 2022 - 2023 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "bot_data.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.2.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="2", micro="0")
|
160
bot/src/bot_data/model/achievement.py
Normal file
160
bot/src/bot_data/model/achievement.py
Normal file
@@ -0,0 +1,160 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class Achievement(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
description: str,
|
||||
attribute: str,
|
||||
operator: str,
|
||||
value: str,
|
||||
server: Optional[Server],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._description = description
|
||||
self._attribute = attribute
|
||||
|
||||
if self._is_operator_valid(operator):
|
||||
raise ValueError("Operator invalid")
|
||||
|
||||
self._operator = operator
|
||||
self._value = value
|
||||
self._server = server
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
@ServiceProviderABC.inject
|
||||
def _is_operator_valid(self, operator, service: ServiceProviderABC) -> bool:
|
||||
from modules.achievements.achievement_service import AchievementService
|
||||
|
||||
achievements: AchievementService = service.get_service(AchievementService)
|
||||
return operator not in achievements.get_operators()
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, value: str):
|
||||
self._name = value
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
@description.setter
|
||||
def description(self, value: str):
|
||||
self._description = value
|
||||
|
||||
@property
|
||||
def attribute(self) -> str:
|
||||
return self._attribute
|
||||
|
||||
@attribute.setter
|
||||
def attribute(self, value: str):
|
||||
self._attribute = value
|
||||
|
||||
@property
|
||||
def operator(self) -> str:
|
||||
return self._operator
|
||||
|
||||
@operator.setter
|
||||
def operator(self, value: str):
|
||||
self._operator = value
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value: str):
|
||||
self._value = value
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Achievements`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Achievements`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Achievements`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Achievements` (
|
||||
`Name`, `Description`, `Attribute`, `Operator`, `Value`, `ServerId`
|
||||
) VALUES (
|
||||
'{self._name}',
|
||||
'{self._description}',
|
||||
'{self._attribute}',
|
||||
'{self._operator}',
|
||||
'{self._value}',
|
||||
{self._server.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Achievements`
|
||||
SET `Name` = '{self._name}',
|
||||
`Description` = '{self._description}',
|
||||
`Attribute` = '{self._attribute}',
|
||||
`Operator` = '{self._operator}',
|
||||
`Value` = '{self._value}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Achievements`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
58
bot/src/bot_data/model/achievement_history.py
Normal file
58
bot/src/bot_data/model/achievement_history.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class AchievementHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
description: str,
|
||||
attribute: str,
|
||||
operator: str,
|
||||
value: str,
|
||||
server: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._description = description
|
||||
self._attribute = attribute
|
||||
self._operator = operator
|
||||
self._value = value
|
||||
self._server = server
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
@property
|
||||
def attribute(self) -> str:
|
||||
return self._attribute
|
||||
|
||||
@property
|
||||
def operator(self) -> str:
|
||||
return self._operator
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
||||
@property
|
||||
def server(self) -> int:
|
||||
return self._server
|
115
bot/src/bot_data/model/api_key.py
Normal file
115
bot/src/bot_data/model/api_key.py
Normal file
@@ -0,0 +1,115 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class ApiKey(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
identifier: str,
|
||||
key: str,
|
||||
creator: Optional[User],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._identifier = identifier
|
||||
self._key = key
|
||||
self._creator = creator
|
||||
|
||||
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 identifier(self) -> str:
|
||||
return self._identifier
|
||||
|
||||
@property
|
||||
def key(self) -> str:
|
||||
return self._key
|
||||
|
||||
@property
|
||||
def creator(self) -> Optional[User]:
|
||||
return self._creator
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_string(identifier: str, key: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`
|
||||
WHERE `Identifier` = '{identifier}'
|
||||
AND `Key` = '{key}';
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_key(key: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`
|
||||
WHERE `Key` = '{key}';
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `ApiKeys` (
|
||||
`Identifier`, `Key`, `CreatorId`
|
||||
) VALUES (
|
||||
'{self._identifier}',
|
||||
'{self._key}',
|
||||
{"NULL" if self._creator is None else f"'{self._creator.id}'"}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `ApiKeys`
|
||||
SET `Identifier` = '{self._identifier}',
|
||||
`Key` = '{self._key}',
|
||||
`CreatorId` = {"NULL" if self._creator is None else f"'{self._creator.id}'"}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `ApiKeys`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
6
bot/src/bot_data/model/auth_role_enum.py
Normal file
6
bot/src/bot_data/model/auth_role_enum.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class AuthRoleEnum(Enum):
|
||||
normal = 0
|
||||
admin = 1
|
270
bot/src/bot_data/model/auth_user.py
Normal file
270
bot/src/bot_data/model/auth_user.py
Normal file
@@ -0,0 +1,270 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class AuthUser(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
first_name: str,
|
||||
last_name: str,
|
||||
email: str,
|
||||
password: str,
|
||||
password_salt: Optional[str],
|
||||
refresh_token: Optional[str],
|
||||
confirmation_id: Optional[str],
|
||||
forgot_password_id: Optional[str],
|
||||
oauth_id: Optional[str],
|
||||
refresh_token_expire_time: datetime,
|
||||
auth_role: AuthRoleEnum,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
auth_user_id=0,
|
||||
users: List[User] = None,
|
||||
):
|
||||
self._auth_user_id = auth_user_id
|
||||
self._first_name = first_name
|
||||
self._last_name = last_name
|
||||
self._email = email
|
||||
self._password = password
|
||||
self._password_salt = uuid.uuid4() if password_salt is None else password_salt
|
||||
self._refresh_token = refresh_token
|
||||
self._confirmation_id = confirmation_id
|
||||
self._oauth_id = oauth_id
|
||||
self._forgot_password_id = forgot_password_id
|
||||
self._refresh_token_expire_time = refresh_token_expire_time
|
||||
|
||||
if users is None:
|
||||
self._users = List(User)
|
||||
else:
|
||||
self._users = users
|
||||
|
||||
self._auth_role_id = auth_role
|
||||
|
||||
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._auth_user_id
|
||||
|
||||
@property
|
||||
def first_name(self) -> str:
|
||||
return self._first_name
|
||||
|
||||
@first_name.setter
|
||||
def first_name(self, value: str):
|
||||
self._first_name = value
|
||||
|
||||
@property
|
||||
def last_name(self) -> str:
|
||||
return self._last_name
|
||||
|
||||
@last_name.setter
|
||||
def last_name(self, value: str):
|
||||
self._last_name = value
|
||||
|
||||
@property
|
||||
def email(self) -> str:
|
||||
return self._email
|
||||
|
||||
@email.setter
|
||||
def email(self, value: str):
|
||||
self._email = value
|
||||
|
||||
@property
|
||||
def password(self) -> str:
|
||||
return self._password
|
||||
|
||||
@password.setter
|
||||
def password(self, value: str):
|
||||
self._password = value
|
||||
|
||||
@property
|
||||
def password_salt(self) -> str:
|
||||
return self._password_salt
|
||||
|
||||
@password_salt.setter
|
||||
def password_salt(self, value: str):
|
||||
self._password_salt = value
|
||||
|
||||
@property
|
||||
def refresh_token(self) -> Optional[str]:
|
||||
return self._refresh_token
|
||||
|
||||
@refresh_token.setter
|
||||
def refresh_token(self, value: Optional[str]):
|
||||
self._refresh_token = value
|
||||
|
||||
@property
|
||||
def confirmation_id(self) -> Optional[str]:
|
||||
return self._confirmation_id
|
||||
|
||||
@confirmation_id.setter
|
||||
def confirmation_id(self, value: Optional[str]):
|
||||
self._confirmation_id = value
|
||||
|
||||
@property
|
||||
def forgot_password_id(self) -> Optional[str]:
|
||||
return self._forgot_password_id
|
||||
|
||||
@forgot_password_id.setter
|
||||
def forgot_password_id(self, value: Optional[str]):
|
||||
self._forgot_password_id = value
|
||||
|
||||
@property
|
||||
def oauth_id(self) -> Optional[str]:
|
||||
return self._oauth_id
|
||||
|
||||
@oauth_id.setter
|
||||
def oauth_id(self, value: Optional[str]):
|
||||
self._oauth_id = value
|
||||
|
||||
@property
|
||||
def refresh_token_expire_time(self) -> datetime:
|
||||
return self._refresh_token_expire_time
|
||||
|
||||
@refresh_token_expire_time.setter
|
||||
def refresh_token_expire_time(self, value: datetime):
|
||||
self._refresh_token_expire_time = value
|
||||
|
||||
@property
|
||||
def auth_role(self) -> AuthRoleEnum:
|
||||
return self._auth_role_id
|
||||
|
||||
@auth_role.setter
|
||||
def auth_role(self, value: AuthRoleEnum):
|
||||
self._auth_role_id = value
|
||||
|
||||
@property
|
||||
def users(self) -> List[User]:
|
||||
return self._users
|
||||
|
||||
@users.setter
|
||||
def users(self, value: List[User]):
|
||||
self._users = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_email_string(email: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `EMail` = '{email}';
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_confirmation_id_string(id: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `ConfirmationId` = '{id}';
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_forgot_password_id_string(id: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `ForgotPasswordId` = '{id}';
|
||||
"""
|
||||
)
|
||||
|
||||
def get_select_user_id_from_relations(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT `UserId`
|
||||
FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {self._auth_user_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AuthUsers` (
|
||||
`Id`,
|
||||
`FirstName`,
|
||||
`LastName`,
|
||||
`EMail`,
|
||||
`Password`,
|
||||
`PasswordSalt`,
|
||||
`RefreshToken`,
|
||||
`ConfirmationId`,
|
||||
`ForgotPasswordId`,
|
||||
`OAuthId`,
|
||||
`RefreshTokenExpiryTime`,
|
||||
`AuthRole`
|
||||
) VALUES (
|
||||
{self._auth_user_id},
|
||||
'{self._first_name}',
|
||||
'{self._last_name}',
|
||||
'{self._email}',
|
||||
'{self._password}',
|
||||
'{self._password_salt}',
|
||||
{"NULL" if self._refresh_token is None else f"'{self._refresh_token}'"},
|
||||
{"NULL" if self._confirmation_id is None else f"'{self._confirmation_id}'"},
|
||||
{"NULL" if self._forgot_password_id is None else f"'{self._forgot_password_id}'"},
|
||||
{"NULL" if self._oauth_id is None else f"'{self._oauth_id}'"},
|
||||
'{self._refresh_token_expire_time.isoformat()}',
|
||||
{self._auth_role_id.value}
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AuthUsers`
|
||||
SET `FirstName` = '{self._first_name}',
|
||||
`LastName` = '{self._last_name}',
|
||||
`EMail` = '{self._email}',
|
||||
`Password` = '{self._password}',
|
||||
`PasswordSalt` = '{self._password_salt}',
|
||||
`RefreshToken` = {"NULL" if self._refresh_token is None else f"'{self._refresh_token}'"},
|
||||
`ConfirmationId` = {"NULL" if self._confirmation_id is None else f"'{self._confirmation_id}'"},
|
||||
`ForgotPasswordId` = {"NULL" if self._forgot_password_id is None else f"'{self._forgot_password_id}'"},
|
||||
`OAuthId` = {"NULL" if self._oauth_id is None else f"'{self._oauth_id}'"},
|
||||
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
||||
`AuthRole` = {self._auth_role_id.value}
|
||||
WHERE `AuthUsers`.`Id` = {self._auth_user_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AuthUsers`
|
||||
WHERE `Id` = {self._auth_user_id};
|
||||
"""
|
||||
)
|
101
bot/src/bot_data/model/auth_user_users_relation.py
Normal file
101
bot/src/bot_data/model/auth_user_users_relation.py
Normal file
@@ -0,0 +1,101 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.auth_user import AuthUser
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class AuthUserUsersRelation(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
auth_user: AuthUser,
|
||||
user: User,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
):
|
||||
self._auth_user = auth_user
|
||||
self._user = user
|
||||
|
||||
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 auth_user(self) -> AuthUser:
|
||||
return self._auth_user
|
||||
|
||||
@auth_user.setter
|
||||
def auth_user(self, value: AuthUser):
|
||||
self._auth_user = value
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
return self._user
|
||||
|
||||
@user.setter
|
||||
def user(self, value: User):
|
||||
self._user = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUserUsersRelations`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_auth_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUserUsersRelations`
|
||||
WHERE `UserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AuthUserUsersRelations` (
|
||||
`AuthUserId`, `UserId`
|
||||
) VALUES (
|
||||
{self._auth_user.id},
|
||||
{self._user.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AuthUserUsersRelations`
|
||||
SET `AuthUserId` = '{self._auth_user.id}',
|
||||
`UserId` = '{self._user.id}'
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
130
bot/src/bot_data/model/auto_role.py
Normal file
130
bot/src/bot_data/model/auto_role.py
Normal file
@@ -0,0 +1,130 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class AutoRole(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
server: Optional[Server],
|
||||
channel_id: int,
|
||||
dc_message_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._auto_role_id = id
|
||||
self._server = server
|
||||
self._discord_channel_id = channel_id
|
||||
self._discord_message_id = dc_message_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._auto_role_id
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
def discord_channel_id(self) -> int:
|
||||
return self._discord_channel_id
|
||||
|
||||
@discord_channel_id.setter
|
||||
def discord_channel_id(self, value: int):
|
||||
self._discord_channel_id = value
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def discord_channel_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
channel = bot.get_channel(self.discord_channel_id)
|
||||
return None if channel is None else channel.name
|
||||
|
||||
@property
|
||||
def discord_message_id(self) -> int:
|
||||
return self._discord_message_id
|
||||
|
||||
@discord_message_id.setter
|
||||
def discord_message_id(self, value: int):
|
||||
self._discord_message_id = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`
|
||||
WHERE `AutoRoleId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_message_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`
|
||||
WHERE `DiscordMessageId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AutoRoles` (
|
||||
`ServerId`, `DiscordChannelId`, `DiscordMessageId`
|
||||
) VALUES (
|
||||
{self._server.id},
|
||||
{self._discord_channel_id},
|
||||
{self._discord_message_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoles`
|
||||
SET `ServerId` = {self._server.id},
|
||||
`DiscordChannelId` = {self._discord_channel_id},
|
||||
`DiscordMessageId` = {self._discord_message_id}
|
||||
WHERE `AutoRoleId` = {self._auto_role_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AutoRoles`
|
||||
WHERE `AutoRoleId` = {self._auto_role_id};
|
||||
"""
|
||||
)
|
49
bot/src/bot_data/model/auto_role_history.py
Normal file
49
bot/src/bot_data/model/auto_role_history.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class AutoRoleHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
server: int,
|
||||
channel_id: int,
|
||||
dc_message_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._auto_role_id = id
|
||||
self._server = server
|
||||
self._discord_channel_id = channel_id
|
||||
self._discord_message_id = dc_message_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._auto_role_id
|
||||
|
||||
@property
|
||||
def server(self) -> int:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
def discord_channel_id(self) -> int:
|
||||
return self._discord_channel_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def discord_channel_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
channel = bot.get_channel(self.discord_channel_id)
|
||||
return None if channel is None else channel.name
|
||||
|
||||
@property
|
||||
def discord_message_id(self) -> int:
|
||||
return self._discord_message_id
|
120
bot/src/bot_data/model/auto_role_rule.py
Normal file
120
bot/src/bot_data/model/auto_role_rule.py
Normal file
@@ -0,0 +1,120 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.auto_role import AutoRole
|
||||
|
||||
|
||||
class AutoRoleRule(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
auto_role: AutoRole,
|
||||
discord_emoji_name: str,
|
||||
discord_role_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._auto_role_rule_id = id
|
||||
self._auto_role = auto_role
|
||||
self._discord_emoji_name = discord_emoji_name
|
||||
self._discord_role_id = discord_role_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._auto_role_rule_id
|
||||
|
||||
@property
|
||||
def auto_role(self) -> AutoRole:
|
||||
return self._auto_role
|
||||
|
||||
@property
|
||||
def emoji_name(self) -> str:
|
||||
return self._discord_emoji_name
|
||||
|
||||
@emoji_name.setter
|
||||
def emoji_name(self, value: str):
|
||||
self._discord_emoji_name = value
|
||||
|
||||
@property
|
||||
def role_id(self) -> int:
|
||||
return self._discord_role_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def role_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.auto_role.server.discord_id)
|
||||
return guild.get_role(self.role_id).name
|
||||
|
||||
@role_id.setter
|
||||
def role_id(self, value: int):
|
||||
self._discord_role_id = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoleRules`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoleRules`
|
||||
WHERE `AutoRoleRuleId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_auto_role_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoleRules`
|
||||
WHERE `AutoRoleId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AutoRoleRules` (
|
||||
`AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`
|
||||
) VALUES (
|
||||
{self._auto_role.id},
|
||||
'{self._discord_emoji_name}',
|
||||
{self._discord_role_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoleRules`
|
||||
SET `AutoRoleId` = {self._auto_role.id},
|
||||
`DiscordEmojiName` = '{self._discord_emoji_name}',
|
||||
`DiscordRoleId` = {self._discord_role_id}
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AutoRoleRules`
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
"""
|
||||
)
|
48
bot/src/bot_data/model/auto_role_rule_history.py
Normal file
48
bot/src/bot_data/model/auto_role_rule_history.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class AutoRoleRuleHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
auto_role: int,
|
||||
discord_emoji_name: str,
|
||||
discord_role_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
self._auto_role_rule_id = id
|
||||
self._auto_role = auto_role
|
||||
self._discord_emoji_name = discord_emoji_name
|
||||
self._discord_role_id = discord_role_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._auto_role_rule_id
|
||||
|
||||
@property
|
||||
def auto_role(self) -> int:
|
||||
return self._auto_role
|
||||
|
||||
@property
|
||||
def emoji_name(self) -> str:
|
||||
return self._discord_emoji_name
|
||||
|
||||
@property
|
||||
def role_id(self) -> int:
|
||||
return self._discord_role_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def role_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.auto_role.server.discord_id)
|
||||
return guild.get_role(self.role_id).name
|
186
bot/src/bot_data/model/client.py
Normal file
186
bot/src/bot_data/model/client.py
Normal file
@@ -0,0 +1,186 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class Client(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
smc: int,
|
||||
rmc: int,
|
||||
dmc: int,
|
||||
rcc: int,
|
||||
muc: int,
|
||||
server: Server,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._client_id = id
|
||||
self._discord_client_id = dc_id
|
||||
self._sent_message_count = smc
|
||||
self._received_message_count = rmc
|
||||
self._deleted_message_count = dmc
|
||||
self._received_command_count = rcc
|
||||
self._moved_users_count = muc
|
||||
self._server: Server = server
|
||||
|
||||
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._client_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_client_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
return bot.user.name
|
||||
|
||||
@property
|
||||
def sent_message_count(self) -> int:
|
||||
return self._sent_message_count
|
||||
|
||||
@sent_message_count.setter
|
||||
def sent_message_count(self, value: int):
|
||||
self._sent_message_count = value
|
||||
|
||||
@property
|
||||
def received_message_count(self) -> int:
|
||||
return self._received_message_count
|
||||
|
||||
@received_message_count.setter
|
||||
def received_message_count(self, value: int):
|
||||
self._received_message_count = value
|
||||
|
||||
@property
|
||||
def deleted_message_count(self) -> int:
|
||||
return self._deleted_message_count
|
||||
|
||||
@deleted_message_count.setter
|
||||
def deleted_message_count(self, value: int):
|
||||
self._deleted_message_count = value
|
||||
|
||||
@property
|
||||
def received_command_count(self) -> int:
|
||||
return self._received_command_count
|
||||
|
||||
@received_command_count.setter
|
||||
def received_command_count(self, value: int):
|
||||
self._received_command_count = value
|
||||
|
||||
@property
|
||||
def moved_users_count(self) -> int:
|
||||
return self._moved_users_count
|
||||
|
||||
@moved_users_count.setter
|
||||
def moved_users_count(self, value: int):
|
||||
self._moved_users_count = value
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`
|
||||
WHERE `ClientId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`
|
||||
WHERE `DiscordClientId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_and_server_id_string(id: int, server_id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`
|
||||
WHERE `DiscordClientId` = {id}
|
||||
AND `ServerId` = {server_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Clients` (
|
||||
`DiscordClientId`,
|
||||
`SentMessageCount`,
|
||||
`ReceivedMessageCount`,
|
||||
`DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`,
|
||||
`MovedUsersCount`,
|
||||
`ServerId`
|
||||
) VALUES (
|
||||
{self._discord_client_id},
|
||||
{self._sent_message_count},
|
||||
{self._received_message_count},
|
||||
{self._deleted_message_count},
|
||||
{self._received_message_count},
|
||||
{self._moved_users_count},
|
||||
{self._server.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Clients`
|
||||
SET `SentMessageCount` = {self._sent_message_count},
|
||||
`ReceivedMessageCount` = {self._received_message_count},
|
||||
`DeletedMessageCount` = {self._deleted_message_count},
|
||||
`ReceivedCommandsCount` = {self._received_command_count},
|
||||
`MovedUsersCount` = {self._moved_users_count}
|
||||
WHERE `ClientId` = {self._client_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Clients`
|
||||
WHERE `ClientId` = {self._client_id};
|
||||
"""
|
||||
)
|
72
bot/src/bot_data/model/client_history.py
Normal file
72
bot/src/bot_data/model/client_history.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class ClientHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
smc: int,
|
||||
rmc: int,
|
||||
dmc: int,
|
||||
rcc: int,
|
||||
muc: int,
|
||||
server: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._client_id = id
|
||||
self._discord_client_id = dc_id
|
||||
self._sent_message_count = smc
|
||||
self._received_message_count = rmc
|
||||
self._deleted_message_count = dmc
|
||||
self._received_command_count = rcc
|
||||
self._moved_users_count = muc
|
||||
self._server = server
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._client_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_client_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
return bot.user.name
|
||||
|
||||
@property
|
||||
def sent_message_count(self) -> int:
|
||||
return self._sent_message_count
|
||||
|
||||
@property
|
||||
def received_message_count(self) -> int:
|
||||
return self._received_message_count
|
||||
|
||||
@property
|
||||
def deleted_message_count(self) -> int:
|
||||
return self._deleted_message_count
|
||||
|
||||
@property
|
||||
def received_command_count(self) -> int:
|
||||
return self._received_command_count
|
||||
|
||||
@property
|
||||
def moved_users_count(self) -> int:
|
||||
return self._moved_users_count
|
||||
|
||||
@property
|
||||
def server(self) -> int:
|
||||
return self._server
|
142
bot/src/bot_data/model/game_server.py
Normal file
142
bot/src/bot_data/model/game_server.py
Normal file
@@ -0,0 +1,142 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.api_key import ApiKey
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class GameServer(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
server: Server,
|
||||
api_key: ApiKey,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._server = server
|
||||
self._api_key = api_key
|
||||
|
||||
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 name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, value: str):
|
||||
self._name = value
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@server.setter
|
||||
def server(self, value: Server):
|
||||
self._server = value
|
||||
|
||||
@property
|
||||
def api_key(self) -> ApiKey:
|
||||
return self._api_key
|
||||
|
||||
@api_key.setter
|
||||
def api_key(self, value: ApiKey):
|
||||
self._api_key = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `GameServers`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_api_key_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `ApiKeyId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `UserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `GameServers` (
|
||||
`Name`, `ServerId`, `ApiKeyId`
|
||||
) VALUES (
|
||||
'{self._name}',
|
||||
{self._server.id},
|
||||
{self._api_key.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `GameServers`
|
||||
SET `Name` = '{self._name}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `GameServers`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `GameServers`
|
||||
WHERE `UserId` = {id}
|
||||
"""
|
||||
)
|
80
bot/src/bot_data/model/known_user.py
Normal file
80
bot/src/bot_data/model/known_user.py
Normal file
@@ -0,0 +1,80 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class KnownUser(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._known_user_id = id
|
||||
self._discord_id = dc_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._known_user_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_id
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `KnownUsers`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `KnownUsers`
|
||||
WHERE `KnownUserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `KnownUsers`
|
||||
WHERE `DiscordId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `KnownUsers` (
|
||||
`DiscordId`
|
||||
) VALUES (
|
||||
{self._discord_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return ""
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `KnownUsers`
|
||||
WHERE `Id` = {self._known_user_id};
|
||||
"""
|
||||
)
|
28
bot/src/bot_data/model/known_user_history.py
Normal file
28
bot/src/bot_data/model/known_user_history.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class KnownUserHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._known_user_id = id
|
||||
self._discord_id = dc_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._known_user_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_id
|
140
bot/src/bot_data/model/level.py
Normal file
140
bot/src/bot_data/model/level.py
Normal file
@@ -0,0 +1,140 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class Level(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
color: str,
|
||||
min_xp: int,
|
||||
permissions: int,
|
||||
server: Optional[Server],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._color = color
|
||||
self._min_xp = min_xp
|
||||
self._permissions = permissions
|
||||
self._server = server
|
||||
|
||||
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 name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, value: str):
|
||||
self._name = value
|
||||
|
||||
@property
|
||||
def color(self) -> str:
|
||||
return self._color
|
||||
|
||||
@color.setter
|
||||
def color(self, value: str):
|
||||
self._color = value
|
||||
|
||||
@property
|
||||
def min_xp(self) -> int:
|
||||
return self._min_xp
|
||||
|
||||
@min_xp.setter
|
||||
def min_xp(self, value: int):
|
||||
self._min_xp = value
|
||||
|
||||
@property
|
||||
def permissions(self) -> int:
|
||||
return self._permissions
|
||||
|
||||
@permissions.setter
|
||||
def permissions(self, value: int):
|
||||
self._permissions = value
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@server.setter
|
||||
def server(self, value: Server):
|
||||
self._server = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Levels`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Levels`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(s_id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Levels`
|
||||
WHERE `ServerId` = {s_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Levels` (
|
||||
`Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`
|
||||
) VALUES (
|
||||
'{self._name}',
|
||||
'{self._color}',
|
||||
{self._min_xp},
|
||||
{self._permissions},
|
||||
{self._server.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Levels`
|
||||
SET `Name` = '{self._name}',
|
||||
`Color` = '{self._color}',
|
||||
`MinXp` = {self._min_xp},
|
||||
`PermissionInt` = {self._permissions}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Levels`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
55
bot/src/bot_data/model/level_history.py
Normal file
55
bot/src/bot_data/model/level_history.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from typing import Optional
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class LevelHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
color: str,
|
||||
min_xp: int,
|
||||
permissions: int,
|
||||
server: Optional[Server],
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._color = color
|
||||
self._min_xp = min_xp
|
||||
self._permissions = permissions
|
||||
self._server = server
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def color(self) -> str:
|
||||
return self._color
|
||||
|
||||
@property
|
||||
def min_xp(self) -> int:
|
||||
return self._min_xp
|
||||
|
||||
@property
|
||||
def permissions(self) -> int:
|
||||
return self._permissions
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
54
bot/src/bot_data/model/migration_history.py
Normal file
54
bot/src/bot_data/model/migration_history.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class MigrationHistory(TableABC):
|
||||
def __init__(self, id: str):
|
||||
self._id = id
|
||||
|
||||
TableABC.__init__(self)
|
||||
|
||||
@property
|
||||
def migration_id(self) -> str:
|
||||
return self._id
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `MigrationHistory`
|
||||
WHERE `MigrationId` = '{id}';
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `MigrationHistory` (
|
||||
`MigrationId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
'{self._id}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `MigrationHistory`
|
||||
SET LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `MigrationId` = '{self._id}';
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `MigrationHistory`
|
||||
WHERE `MigrationId` = '{self._id}';
|
||||
"""
|
||||
)
|
100
bot/src/bot_data/model/server.py
Normal file
100
bot/src/bot_data/model/server.py
Normal file
@@ -0,0 +1,100 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
|
||||
class Server(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._server_id = id
|
||||
self._discord_server_id = dc_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._server_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_server_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.name
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def icon_url(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.icon.url
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Servers`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Servers`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Servers`
|
||||
WHERE `DiscordServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Servers` (
|
||||
`DiscordServerId`
|
||||
) VALUES (
|
||||
{self._discord_server_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Servers`
|
||||
SET `DiscordServerId` = {self._discord_server_id}
|
||||
WHERE `ServerId` = {self._server_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Servers`
|
||||
WHERE `ServerId` = {self._server_id};
|
||||
"""
|
||||
)
|
87
bot/src/bot_data/model/server_afk_channel_ids_config.py
Normal file
87
bot/src/bot_data/model/server_afk_channel_ids_config.py
Normal file
@@ -0,0 +1,87 @@
|
||||
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};
|
||||
"""
|
||||
)
|
378
bot/src/bot_data/model/server_config.py
Normal file
378
bot/src/bot_data/model/server_config.py
Normal file
@@ -0,0 +1,378 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_query.extension import List
|
||||
from discord import Guild
|
||||
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
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,
|
||||
xp_for_birthday: int,
|
||||
afk_command_channel_id: int,
|
||||
help_voice_channel_id: int,
|
||||
team_channel_id: int,
|
||||
login_message_channel_id: int,
|
||||
default_role_id: Optional[int],
|
||||
short_role_name_only_set_highest_role: bool,
|
||||
game_offer_notification_chat_id: int,
|
||||
feature_flags: dict[FeatureFlagsEnum],
|
||||
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._xp_for_birthday = xp_for_birthday
|
||||
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._default_role_id = default_role_id
|
||||
self._short_role_name_only_set_highest_role = (
|
||||
short_role_name_only_set_highest_role
|
||||
)
|
||||
self._game_offer_notification_chat_id = game_offer_notification_chat_id
|
||||
|
||||
self._feature_flags = feature_flags
|
||||
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
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def new(guild: Guild, server: Server) -> "ServerConfig":
|
||||
return ServerConfig(
|
||||
6,
|
||||
guild.system_channel.id,
|
||||
6,
|
||||
1,
|
||||
1,
|
||||
20,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
guild.system_channel.id,
|
||||
None,
|
||||
False,
|
||||
guild.system_channel.id,
|
||||
{},
|
||||
server,
|
||||
List(int),
|
||||
List(int),
|
||||
)
|
||||
|
||||
@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 xp_for_birthday(self) -> int:
|
||||
return self._xp_for_birthday
|
||||
|
||||
@xp_for_birthday.setter
|
||||
def xp_for_birthday(self, value: int):
|
||||
self._xp_for_birthday = 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 default_role_id(self) -> int:
|
||||
return self._default_role_id
|
||||
|
||||
@default_role_id.setter
|
||||
def default_role_id(self, value: int):
|
||||
self._default_role_id = value
|
||||
|
||||
@property
|
||||
def short_role_name_only_set_highest_role(self) -> bool:
|
||||
return self._short_role_name_only_set_highest_role
|
||||
|
||||
@short_role_name_only_set_highest_role.setter
|
||||
def short_role_name_only_set_highest_role(self, value: bool):
|
||||
self._short_role_name_only_set_highest_role = value
|
||||
|
||||
@property
|
||||
def game_offer_notification_chat_id(self) -> int:
|
||||
return self._game_offer_notification_chat_id
|
||||
|
||||
@game_offer_notification_chat_id.setter
|
||||
def game_offer_notification_chat_id(self, value: int):
|
||||
self._game_offer_notification_chat_id = value
|
||||
|
||||
@property
|
||||
def feature_flags(self) -> dict[FeatureFlagsEnum]:
|
||||
return self._feature_flags
|
||||
|
||||
@feature_flags.setter
|
||||
def feature_flags(self, value: dict[FeatureFlagsEnum]):
|
||||
self._feature_flags = 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`,
|
||||
`XpForBirthday`,
|
||||
`AFKCommandChannelId`,
|
||||
`HelpVoiceChannelId`,
|
||||
`TeamChannelId`,
|
||||
`LoginMessageChannelId`,
|
||||
`DefaultRoleId`,
|
||||
`ShortRoleNameSetOnlyHighest`,
|
||||
`GameOfferNotificationChatId`,
|
||||
`FeatureFlags`,
|
||||
`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._xp_for_birthday}',
|
||||
{self._afk_command_channel_id},
|
||||
{self._help_voice_channel_id},
|
||||
{self._team_channel_id},
|
||||
{self._login_message_channel_id},
|
||||
{"NULL" if self._default_role_id is None else self._default_role_id},
|
||||
{self._short_role_name_only_set_highest_role},
|
||||
{self._game_offer_notification_chat_id},
|
||||
'{json.dumps(self._feature_flags)}',
|
||||
{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},
|
||||
`XpForBirthday` = {self._xp_for_birthday},
|
||||
`AFKCommandChannelId` = {self._afk_command_channel_id},
|
||||
`HelpVoiceChannelId` = {self._help_voice_channel_id},
|
||||
`TeamChannelId` = {self._team_channel_id},
|
||||
`LoginMessageChannelId` = {self._login_message_channel_id},
|
||||
`DefaultRoleId` = {"NULL" if self._default_role_id is None else self._default_role_id},
|
||||
`ShortRoleNameSetOnlyHighest` = {self._short_role_name_only_set_highest_role},
|
||||
`GameOfferNotificationChatId` = {self._game_offer_notification_chat_id},
|
||||
`FeatureFlags` = '{json.dumps(self._feature_flags)}',
|
||||
`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};
|
||||
"""
|
||||
)
|
123
bot/src/bot_data/model/server_config_history.py
Normal file
123
bot/src/bot_data/model/server_config_history.py
Normal file
@@ -0,0 +1,123 @@
|
||||
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,
|
||||
default_role_id: int,
|
||||
short_role_name_only_set_highest_role: bool,
|
||||
feature_flags: dict[str],
|
||||
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._default_role_id = default_role_id
|
||||
self._short_role_name_only_set_highest_role = (
|
||||
short_role_name_only_set_highest_role
|
||||
)
|
||||
|
||||
self._feature_flags = feature_flags
|
||||
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 default_role_id(self) -> int:
|
||||
return self._default_role_id
|
||||
|
||||
@property
|
||||
def short_role_name_only_set_highest_role(self) -> bool:
|
||||
return self._short_role_name_only_set_highest_role
|
||||
|
||||
@property
|
||||
def feature_flags(self) -> dict[str]:
|
||||
return self._feature_flags
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
return self._server_id
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user