Formatted files with black
This commit is contained in:
@@ -11,16 +11,16 @@ Discord bot for the Keksdose discord Server
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'bot_data'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||
__version__ = '0.3.0'
|
||||
__title__ = "bot_data"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 sh-edraft.de"
|
||||
__version__ = "0.3.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='3', micro='0')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="0")
|
||||
|
@@ -11,16 +11,16 @@ Discord bot for the Keksdose discord Server
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'bot_data.abc'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||
__version__ = '0.3.0'
|
||||
__title__ = "bot_data.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 sh-edraft.de"
|
||||
__version__ = "0.3.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='3', micro='0')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="0")
|
||||
|
@@ -10,42 +10,56 @@ from bot_data.model.auth_user_users_relation import AuthUserUsersRelation
|
||||
|
||||
|
||||
class AuthUserRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def get_all_auth_users(self) -> List[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_all_auth_users(self) -> List[AuthUser]: pass
|
||||
def get_filtered_auth_users(
|
||||
self, criteria: AuthUserSelectCriteria
|
||||
) -> FilteredResult:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_filtered_auth_users(self, criteria: AuthUserSelectCriteria) -> FilteredResult: pass
|
||||
def get_auth_user_by_email(self, email: str) -> AuthUser:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auth_user_by_email(self, email: str) -> AuthUser: pass
|
||||
def find_auth_user_by_email(self, email: str) -> Optional[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auth_user_by_email(self, email: str) -> Optional[AuthUser]: pass
|
||||
def find_auth_user_by_confirmation_id(self, id: str) -> Optional[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auth_user_by_confirmation_id(self, id: str) -> Optional[AuthUser]: pass
|
||||
def find_auth_user_by_forgot_password_id(self, id: str) -> Optional[AuthUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auth_user_by_forgot_password_id(self, id: str) -> Optional[AuthUser]: pass
|
||||
def add_auth_user(self, user: AuthUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auth_user(self, user: AuthUser): pass
|
||||
def update_auth_user(self, user: AuthUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_auth_user(self, user: AuthUser): pass
|
||||
def delete_auth_user(self, user: AuthUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_auth_user(self, user: AuthUser): pass
|
||||
def add_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auth_user_user_rel(self, rel: AuthUserUsersRelation): pass
|
||||
def update_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
|
||||
def delete_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
pass
|
||||
|
@@ -8,51 +8,66 @@ from bot_data.model.auto_role_rule import AutoRoleRule
|
||||
|
||||
|
||||
class AutoRoleRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def get_auto_roles(self) -> List[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_roles(self) -> List[AutoRole]: pass
|
||||
def get_auto_role_by_id(self, id: int) -> AutoRole:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_by_id(self, id: int) -> AutoRole: pass
|
||||
def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]: pass
|
||||
def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]: pass
|
||||
def get_auto_role_by_message_id(self, id: int) -> AutoRole:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_by_message_id(self, id: int) -> AutoRole: pass
|
||||
def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]: pass
|
||||
def add_auto_role(self, auto_role: AutoRole):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auto_role(self, auto_role: AutoRole): pass
|
||||
def update_auto_role(self, auto_role: AutoRole):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_auto_role(self, auto_role: AutoRole): pass
|
||||
def delete_auto_role(self, auto_role: AutoRole):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_auto_role(self, auto_role: AutoRole): pass
|
||||
def get_auto_role_rules(self) -> List[AutoRoleRule]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_rules(self) -> List[AutoRoleRule]: pass
|
||||
def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule: pass
|
||||
def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]: pass
|
||||
def add_auto_role_rule(self, auto_role: AutoRoleRule):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_auto_role_rule(self, auto_role: AutoRoleRule): pass
|
||||
def update_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
|
||||
def delete_auto_role_rule(self, auto_role: AutoRoleRule):
|
||||
pass
|
||||
|
@@ -6,48 +6,64 @@ from bot_data.model.client import Client
|
||||
|
||||
|
||||
class ClientRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@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 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
|
||||
def get_clients(self) -> List[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_sent_message_count(self, client_id: int, server_id: int, value: int): pass
|
||||
def get_client_by_id(self, client_id: int) -> Client:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_received_message_count(self, client_id: int, server_id: int, value: int): pass
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_deleted_message_count(self, client_id: int, server_id: int, value: int): pass
|
||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_received_command_count(self, client_id: int, server_id: int, value: int): pass
|
||||
def find_client_by_server_id(self, server_id: int) -> Optional[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def append_moved_users_count(self, client_id: int, server_id: int, value: int): pass
|
||||
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
|
||||
|
@@ -2,9 +2,10 @@ from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class DataSeederABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def seed(self): pass
|
||||
def seed(self):
|
||||
pass
|
||||
|
@@ -7,24 +7,30 @@ from bot_data.model.known_user import KnownUser
|
||||
|
||||
|
||||
class KnownUserRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
def get_users(self) -> List[KnownUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users(self) -> List[KnownUser]: pass
|
||||
|
||||
def get_user_by_id(self, id: int) -> KnownUser:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_id(self, id: int) -> KnownUser: pass
|
||||
|
||||
def get_user_by_discord_id(self, discord_id: int) -> KnownUser:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id(self, discord_id: int) -> KnownUser: pass
|
||||
|
||||
def find_user_by_discord_id(self, discord_id: int) -> Optional[KnownUser]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id(self, discord_id: int) -> Optional[KnownUser]: pass
|
||||
|
||||
def add_user(self, known_user: KnownUser):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user(self, known_user: KnownUser): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user(self, known_user: KnownUser): pass
|
||||
def delete_user(self, known_user: KnownUser):
|
||||
pass
|
||||
|
@@ -7,30 +7,38 @@ from bot_data.model.level import Level
|
||||
|
||||
|
||||
class LevelRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_levels(self) -> List[Level]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_level_by_id(self, id: int) -> Level: pass
|
||||
def get_levels(self) -> List[Level]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_level_by_id(self, id: int) -> Optional[Level]: pass
|
||||
|
||||
def get_level_by_id(self, id: int) -> Level:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_levels_by_server_id(self, server_id: int) -> List[Level]: pass
|
||||
|
||||
def find_level_by_id(self, id: int) -> Optional[Level]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]: pass
|
||||
|
||||
def get_levels_by_server_id(self, server_id: int) -> List[Level]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_level(self, level: Level): pass
|
||||
|
||||
def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_level(self, level: Level): pass
|
||||
|
||||
def add_level(self, level: Level):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_level(self, level: Level): pass
|
||||
def update_level(self, level: Level):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_level(self, level: Level):
|
||||
pass
|
||||
|
@@ -5,10 +5,13 @@ class MigrationABC(ABC):
|
||||
name = None
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def upgrade(self): pass
|
||||
def upgrade(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def downgrade(self): pass
|
||||
def downgrade(self):
|
||||
pass
|
||||
|
@@ -9,30 +9,38 @@ from bot_data.model.server import Server
|
||||
|
||||
|
||||
class ServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_servers(self) -> List[Server]: pass
|
||||
def get_servers(self) -> List[Server]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_filtered_servers(self, criteria: ServerSelectCriteria) -> FilteredResult: pass
|
||||
|
||||
def get_filtered_servers(self, criteria: ServerSelectCriteria) -> FilteredResult:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_by_id(self, id: int) -> Server: pass
|
||||
|
||||
def get_server_by_id(self, id: int) -> Server:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_by_discord_id(self, discord_id: int) -> Server: pass
|
||||
|
||||
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
|
||||
|
||||
def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_server(self, server: Server): pass
|
||||
|
||||
def add_server(self, server: Server):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_server(self, server: Server): pass
|
||||
|
||||
def update_server(self, server: Server):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_server(self, server: Server): pass
|
||||
def delete_server(self, server: Server):
|
||||
pass
|
||||
|
@@ -7,30 +7,38 @@ from bot_data.model.statistic import Statistic
|
||||
|
||||
|
||||
class StatisticRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def get_statistics(self) -> List[Statistic]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistics(self) -> List[Statistic]: pass
|
||||
def get_statistics_by_server_id(self, server_id: int) -> List[Statistic]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistics_by_server_id(self, server_id: int) -> List[Statistic]: pass
|
||||
def get_statistic_by_id(self, id: int) -> Statistic:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistic_by_id(self, id: int) -> Statistic: pass
|
||||
def get_statistic_by_name(self, name: str, server_id: int) -> Statistic:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistic_by_name(self, name: str, server_id: int) -> Statistic: pass
|
||||
def find_statistic_by_name(self, name: str, server_id: int) -> Optional[Statistic]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_statistic_by_name(self, name: str, server_id: int) -> Optional[Statistic]: pass
|
||||
def add_statistic(self, statistic: Statistic):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_statistic(self, statistic: Statistic): pass
|
||||
def update_statistic(self, statistic: Statistic):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_statistic(self, statistic: Statistic): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_statistic(self, statistic: Statistic): pass
|
||||
def delete_statistic(self, statistic: Statistic):
|
||||
pass
|
||||
|
@@ -6,30 +6,44 @@ from bot_data.model.user_joined_server import UserJoinedServer
|
||||
|
||||
|
||||
class UserJoinedServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
def get_user_joined_servers(self) -> List[UserJoinedServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers(self) -> List[UserJoinedServer]: pass
|
||||
|
||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer: pass
|
||||
|
||||
def get_user_joined_servers_by_user_id(
|
||||
self, user_id: int
|
||||
) -> list[UserJoinedServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> list[UserJoinedServer]: pass
|
||||
|
||||
def get_active_user_joined_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_active_user_joined_server_by_user_id(self, user_id: int) -> UserJoinedServer: pass
|
||||
|
||||
def find_active_user_joined_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserJoinedServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_server_by_user_id(self, user_id: int) -> Optional[UserJoinedServer]: pass
|
||||
|
||||
def add_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_joined_server(self, user_joined_server: UserJoinedServer): pass
|
||||
|
||||
def update_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
|
||||
def delete_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
pass
|
||||
|
@@ -4,37 +4,62 @@ 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 __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
|
||||
def get_user_joined_voice_channels(self) -> List[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
|
||||
def get_user_joined_voice_channel_by_id(self, id: int) -> UserJoinedVoiceChannel:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_voice_channel_by_user_id(self, user_id: int): pass
|
||||
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
|
||||
|
@@ -8,32 +8,44 @@ from bot_data.model.user_message_count_per_hour import UserMessageCountPerHour
|
||||
|
||||
|
||||
class UserMessageCountPerHourRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def get_user_message_count_per_hours(self) -> List[UserMessageCountPerHour]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_message_count_per_hours(self) -> List[UserMessageCountPerHour]: pass
|
||||
def find_user_message_count_per_hour_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserMessageCountPerHour]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_message_count_per_hour_by_user_id(self, user_id: int) -> Optional[UserMessageCountPerHour]: pass
|
||||
def get_user_message_count_per_hour_by_user_id_and_date(
|
||||
self, user_id: int, date: datetime
|
||||
) -> 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
|
||||
def find_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
|
||||
def add_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_message_count_per_hour(self, umcph: UserMessageCountPerHour): pass
|
||||
def update_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_message_count_per_hour(self, umcph: UserMessageCountPerHour): pass
|
||||
def delete_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
|
||||
def delete_user_message_count_per_hour_by_user_id(self, user_id: int):
|
||||
pass
|
||||
|
@@ -7,33 +7,46 @@ from bot_data.model.user import User
|
||||
|
||||
|
||||
class UserRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users(self) -> List[User]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_id(self, id: int) -> User: pass
|
||||
def get_users(self) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_id(self, id: int) -> Optional[User]: pass
|
||||
|
||||
def get_user_by_id(self, id: int) -> User:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]: pass
|
||||
|
||||
def find_user_by_id(self, id: int) -> Optional[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User: pass
|
||||
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[User]: pass
|
||||
|
||||
def get_user_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> User:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user(self, user: User): pass
|
||||
|
||||
def find_user_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> Optional[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user(self, user: User): pass
|
||||
|
||||
def add_user(self, user: User):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user(self, user: User): pass
|
||||
def update_user(self, user: User):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user(self, user: User):
|
||||
pass
|
||||
|
@@ -13,8 +13,12 @@ from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
|
||||
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_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.service.auth_user_repository_service import AuthUserRepositoryService
|
||||
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||
@@ -24,31 +28,47 @@ from bot_data.service.level_repository_service import LevelRepositoryService
|
||||
from bot_data.service.seeder_service import SeederService
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
from bot_data.service.statistic_repository_service import StatisticRepositoryService
|
||||
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_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
|
||||
|
||||
|
||||
class DataModule(ModuleABC):
|
||||
|
||||
def __init__(self, dc: DiscordCollectionABC):
|
||||
ModuleABC.__init__(self, dc, FeatureFlagsEnum.data_module)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
def configure_configuration(
|
||||
self, config: ConfigurationABC, env: ApplicationEnvironmentABC
|
||||
):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
def configure_services(
|
||||
self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC
|
||||
):
|
||||
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(
|
||||
UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService
|
||||
)
|
||||
services.add_transient(
|
||||
UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService
|
||||
)
|
||||
services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService)
|
||||
services.add_transient(LevelRepositoryABC, LevelRepositoryService)
|
||||
services.add_transient(StatisticRepositoryABC, StatisticRepositoryService)
|
||||
services.add_transient(UserMessageCountPerHourRepositoryABC, UserMessageCountPerHourRepositoryService)
|
||||
services.add_transient(
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
UserMessageCountPerHourRepositoryService,
|
||||
)
|
||||
|
||||
services.add_transient(SeederService)
|
||||
|
@@ -5,7 +5,6 @@ from bot_core.logging.database_logger import DatabaseLogger
|
||||
|
||||
|
||||
class DBContext(DatabaseContext):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger):
|
||||
|
||||
self._logger = logger
|
||||
@@ -32,5 +31,5 @@ class DBContext(DatabaseContext):
|
||||
try:
|
||||
return super(DBContext, self).select(statement)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Database error caused by {statement}', e)
|
||||
self._logger.error(__name__, f"Database error caused by {statement}", e)
|
||||
return []
|
||||
|
@@ -2,7 +2,6 @@ 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
|
||||
|
@@ -11,16 +11,16 @@ Discord bot for the Keksdose discord Server
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'bot_data.migration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||
__version__ = '0.3.0'
|
||||
__title__ = "bot_data.migration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 sh-edraft.de"
|
||||
__version__ = "0.3.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='3', micro='0')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="0")
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ApiMigration(MigrationABC):
|
||||
name = '0.3_ApiMigration'
|
||||
name = "0.3_ApiMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@@ -13,10 +13,11 @@ class ApiMigration(MigrationABC):
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, 'Running upgrade')
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `AuthUsers` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`FirstName` VARCHAR(255),
|
||||
@@ -34,11 +35,13 @@ class ApiMigration(MigrationABC):
|
||||
`LastModifiedAt` DATETIME(6) NOT NULL,
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `AuthUserUsersRelations`(
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`AuthUserId` BIGINT DEFAULT NULL,
|
||||
@@ -49,10 +52,10 @@ class ApiMigration(MigrationABC):
|
||||
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`;')
|
||||
|
||||
self._cursor.execute("DROP TABLE `AuthUsers`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUserUsersRelations`;")
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class AutoRoleFix1Migration(MigrationABC):
|
||||
name = '0.3.0_AutoRoleMigration'
|
||||
name = "0.3.0_AutoRoleMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@@ -13,17 +13,21 @@ class AutoRoleFix1Migration(MigrationABC):
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, 'Running upgrade')
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE AutoRoles ADD DiscordChannelId BIGINT NOT NULL AFTER ServerId;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
ALTER TABLE AutoRoles DROP COLUMN DiscordChannelId;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class AutoRoleMigration(MigrationABC):
|
||||
name = '0.2.1_AutoRoleMigration'
|
||||
name = "0.2.1_AutoRoleMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@@ -13,10 +13,11 @@ class AutoRoleMigration(MigrationABC):
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, 'Running upgrade')
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `AutoRoles` (
|
||||
`AutoRoleId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`ServerId` BIGINT,
|
||||
@@ -26,11 +27,13 @@ class AutoRoleMigration(MigrationABC):
|
||||
PRIMARY KEY(`AutoRoleId`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `AutoRoleRules` (
|
||||
`AutoRoleRuleId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`AutoRoleId` BIGINT,
|
||||
@@ -41,9 +44,10 @@ class AutoRoleMigration(MigrationABC):
|
||||
PRIMARY KEY(`AutoRoleRuleId`),
|
||||
FOREIGN KEY (`AutoRoleId`) REFERENCES `AutoRoles`(`AutoRoleId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute('DROP TABLE `AutoRole`;')
|
||||
self._cursor.execute('DROP TABLE `AutoRoleRules`;')
|
||||
self._cursor.execute("DROP TABLE `AutoRole`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRoleRules`;")
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class InitialMigration(MigrationABC):
|
||||
name = '0.1_InitialMigration'
|
||||
name = "0.1_InitialMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@@ -13,21 +13,24 @@ class InitialMigration(MigrationABC):
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, 'Running upgrade')
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
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"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Servers` (
|
||||
`ServerId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordServerId` BIGINT NOT NULL,
|
||||
@@ -35,11 +38,13 @@ class InitialMigration(MigrationABC):
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`ServerId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Users` (
|
||||
`UserId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordId` BIGINT NOT NULL,
|
||||
@@ -50,11 +55,13 @@ class InitialMigration(MigrationABC):
|
||||
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
||||
PRIMARY KEY(`UserId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Clients` (
|
||||
`ClientId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordClientId` BIGINT NOT NULL,
|
||||
@@ -69,11 +76,13 @@ class InitialMigration(MigrationABC):
|
||||
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
||||
PRIMARY KEY(`ClientId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `KnownUsers` (
|
||||
`KnownUserId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`DiscordId` BIGINT NOT NULL,
|
||||
@@ -81,11 +90,13 @@ class InitialMigration(MigrationABC):
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`KnownUserId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedServers` (
|
||||
`JoinId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
@@ -96,11 +107,13 @@ class InitialMigration(MigrationABC):
|
||||
FOREIGN KEY (`UserId`) REFERENCES Users(`UserId`),
|
||||
PRIMARY KEY(`JoinId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedVoiceChannel` (
|
||||
`JoinId` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
@@ -112,13 +125,14 @@ class InitialMigration(MigrationABC):
|
||||
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`;')
|
||||
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`;")
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class LevelMigration(MigrationABC):
|
||||
name = '0.3_LevelMigration'
|
||||
name = "0.3_LevelMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@@ -13,10 +13,11 @@ class LevelMigration(MigrationABC):
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, 'Running upgrade')
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Levels` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
@@ -29,9 +30,9 @@ class LevelMigration(MigrationABC):
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute('DROP TABLE `Levels`;')
|
||||
|
||||
self._cursor.execute("DROP TABLE `Levels`;")
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class StatsMigration(MigrationABC):
|
||||
name = '0.3_StatsMigration'
|
||||
name = "0.3_StatsMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@@ -13,10 +13,11 @@ class StatsMigration(MigrationABC):
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, 'Running upgrade')
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Statistics` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
@@ -28,9 +29,9 @@ class StatsMigration(MigrationABC):
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute('DROP TABLE `Statistics`;')
|
||||
|
||||
self._cursor.execute("DROP TABLE `Statistics`;")
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserMessageCountPerHourMigration(MigrationABC):
|
||||
name = '0.3.1_UserMessageCountPerHourMigration'
|
||||
name = "0.3.1_UserMessageCountPerHourMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@@ -13,10 +13,11 @@ class UserMessageCountPerHourMigration(MigrationABC):
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, 'Running upgrade')
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(f"""
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserMessageCountPerHour` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Date` DATETIME(6) NOT NULL,
|
||||
@@ -28,8 +29,9 @@ class UserMessageCountPerHourMigration(MigrationABC):
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`UserId`) REFERENCES `Users`(`UserId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute('DROP TABLE `UserMessageCountPerHour`;')
|
||||
self._cursor.execute("DROP TABLE `UserMessageCountPerHour`;")
|
||||
|
@@ -11,16 +11,16 @@ Discord bot for the Keksdose discord Server
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'bot_data.model'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||
__version__ = '0.3.0'
|
||||
__title__ = "bot_data.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 sh-edraft.de"
|
||||
__version__ = "0.3.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='3', micro='0')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="0")
|
||||
|
@@ -10,24 +10,23 @@ 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,
|
||||
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
|
||||
@@ -48,7 +47,9 @@ class AuthUser(TableABC):
|
||||
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
@@ -152,48 +153,61 @@ class AuthUser(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `Id` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_email_string(email: str) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `EMail` = '{email}';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_confirmation_id_string(id: str) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `ConfirmationId` = '{id}';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_forgot_password_id_string(id: str) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUsers`
|
||||
WHERE `ForgotPasswordId` = '{id}';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
def get_select_user_id_from_relations(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT `UserId`
|
||||
FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {self._auth_user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AuthUsers` (
|
||||
`Id`,
|
||||
`FirstName`,
|
||||
@@ -225,11 +239,13 @@ class AuthUser(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AuthUsers`
|
||||
SET `FirstName` = '{self._first_name}',
|
||||
`LastName` = '{self._last_name}',
|
||||
@@ -244,11 +260,14 @@ class AuthUser(TableABC):
|
||||
`AuthRole` = {self._auth_role_id.value},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AuthUsers`.`Id` = {self._auth_user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AuthUsers`
|
||||
WHERE `Id` = {self._auth_user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -7,14 +7,21 @@ 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):
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def auth_user(self) -> AuthUser:
|
||||
@@ -34,27 +41,34 @@ class AuthUserUsersRelation(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUserUsersRelations`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_auth_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AuthUserUsersRelations`
|
||||
WHERE `UserId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AuthUserUsersRelations` (
|
||||
`AuthUserId`, `UserId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -63,23 +77,28 @@ class AuthUserUsersRelation(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AuthUserUsersRelations`
|
||||
SET `AuthUserId` = '{self._auth_user.id}',,
|
||||
`UserId` = '{self._user.user_id}'
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -5,16 +5,25 @@ from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class AutoRole(TableABC):
|
||||
|
||||
def __init__(self, server_id: int, dc_channel_id: int, dc_message_id: int, created_at: datetime=None, modified_at: datetime=None, id=0):
|
||||
def __init__(
|
||||
self,
|
||||
server_id: int,
|
||||
dc_channel_id: int,
|
||||
dc_message_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._auto_role_id = id
|
||||
self._server_id = server_id
|
||||
self._discord_channel_id = dc_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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def auto_role_id(self) -> int:
|
||||
@@ -34,34 +43,43 @@ class AutoRole(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`;
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`
|
||||
WHERE `AutoRoleId` = {id};
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`
|
||||
WHERE `ServerId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_message_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoles`
|
||||
WHERE `DiscordMessageId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AutoRoles` (
|
||||
`ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -71,22 +89,27 @@ class AutoRole(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoles`
|
||||
SET `ServerId` = {self._server_id},
|
||||
`DiscordChannelId` = {self._discord_channel_id},
|
||||
`DiscordMessageId` = {self._discord_message_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AutoRoleId` = {self._auto_role_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AutoRoles`
|
||||
WHERE `AutoRoleId` = {self._auto_role_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -5,8 +5,15 @@ from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class AutoRoleRule(TableABC):
|
||||
|
||||
def __init__(self, auto_role_id: int, discord_emoji_name: str, discord_role_id: int, created_at: datetime=None, modified_at: datetime=None, id=0):
|
||||
def __init__(
|
||||
self,
|
||||
auto_role_id: int,
|
||||
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_id = auto_role_id
|
||||
self._discord_emoji_name = discord_emoji_name
|
||||
@@ -14,7 +21,9 @@ class AutoRoleRule(TableABC):
|
||||
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def auto_role_rule_id(self) -> int:
|
||||
@@ -34,27 +43,34 @@ class AutoRoleRule(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoleRules`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoleRules`
|
||||
WHERE `AutoRoleRuleId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_auto_role_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `AutoRoleRules`
|
||||
WHERE `AutoRoleId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AutoRoleRules` (
|
||||
`AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -64,22 +80,27 @@ class AutoRoleRule(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoleRules`
|
||||
SET `AutoRoleId` = {self._auto_role_id},
|
||||
`DiscordEmojiName` = {self._discord_emoji_name},
|
||||
`DiscordRoleId` = {self._discord_role_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `AutoRoleRules`
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -5,18 +5,18 @@ 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
|
||||
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
|
||||
@@ -29,7 +29,9 @@ class Client(TableABC):
|
||||
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def client_id(self) -> int:
|
||||
@@ -90,42 +92,53 @@ class Client(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`
|
||||
WHERE `ClientId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`
|
||||
WHERE `DiscordClientId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
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"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Clients`
|
||||
WHERE `DiscordClientId` = {id}
|
||||
AND `ServerId` = {server_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Clients` (
|
||||
`DiscordClientId`,
|
||||
`SentMessageCount`,
|
||||
@@ -147,11 +160,13 @@ class Client(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Clients`
|
||||
SET `SentMessageCount` = {self._sent_message_count},
|
||||
`ReceivedMessageCount` = {self._received_message_count},
|
||||
@@ -160,11 +175,14 @@ class Client(TableABC):
|
||||
`MovedUsersCount` = {self._moved_users_count},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `ClientId` = {self._client_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Clients`
|
||||
WHERE `ClientId` = {self._client_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -6,14 +6,21 @@ from bot_data.model.server import Server
|
||||
|
||||
|
||||
class KnownUser(TableABC):
|
||||
|
||||
def __init__(self, dc_id: int, created_at: datetime = None, modified_at: datetime = None, id=0):
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def known_user_id(self) -> int:
|
||||
@@ -25,27 +32,34 @@ class KnownUser(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `KnownUsers`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `KnownUsers`
|
||||
WHERE `KnownUserId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `KnownUsers`
|
||||
WHERE `DiscordId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `KnownUsers` (
|
||||
`DiscordId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -53,15 +67,18 @@ class KnownUser(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return ''
|
||||
return ""
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `KnownUsers`
|
||||
WHERE `Id` = {self._known_user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -6,63 +6,74 @@ 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):
|
||||
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
|
||||
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._modified_at = datetime.now().isoformat()
|
||||
self._name = value
|
||||
|
||||
|
||||
@property
|
||||
def color(self) -> str:
|
||||
return self._color
|
||||
|
||||
|
||||
@color.setter
|
||||
def color(self, value: str):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._color = value
|
||||
|
||||
|
||||
@property
|
||||
def min_xp(self) -> int:
|
||||
return self._min_xp
|
||||
|
||||
|
||||
@min_xp.setter
|
||||
def min_xp(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._min_xp = value
|
||||
|
||||
|
||||
@property
|
||||
def permissions(self) -> int:
|
||||
return self._permissions
|
||||
|
||||
|
||||
@permissions.setter
|
||||
def permissions(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._permissions = value
|
||||
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
|
||||
@server.setter
|
||||
def server(self, value: Server):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
@@ -70,27 +81,34 @@ class Level(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Levels`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Levels`
|
||||
WHERE `Id` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(s_id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Levels`
|
||||
WHERE `ServerId` = {s_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Levels` (
|
||||
`Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -102,11 +120,13 @@ class Level(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Levels`
|
||||
SET `Name` = '{self._name}',
|
||||
`Color` = '{self._color}',
|
||||
@@ -114,11 +134,14 @@ class Level(TableABC):
|
||||
`PermissionInt` = {self._permissions},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Levels`
|
||||
WHERE `Id` = {self._id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -2,26 +2,28 @@ 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"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `MigrationHistory`
|
||||
WHERE `MigrationId` = '{id}';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `MigrationHistory` (
|
||||
`MigrationId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -29,19 +31,24 @@ class MigrationHistory(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `MigrationHistory`
|
||||
SET LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `MigrationId` = '{self._id}';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `MigrationHistory`
|
||||
WHERE `MigrationId` = '{self._id}';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -5,15 +5,22 @@ from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class Server(TableABC):
|
||||
|
||||
def __init__(self, dc_id: int, created_at: datetime=None, modified_at: datetime=None, id=0):
|
||||
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
|
||||
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
return self._server_id
|
||||
@@ -21,30 +28,37 @@ class Server(TableABC):
|
||||
@property
|
||||
def discord_server_id(self) -> int:
|
||||
return self._discord_server_id
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Servers`;
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Servers`
|
||||
WHERE `ServerId` = {id};
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Servers`
|
||||
WHERE `DiscordServerId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Servers` (
|
||||
`DiscordServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -52,20 +66,25 @@ class Server(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Servers`
|
||||
SET `DiscordServerId` = {self._discord_server_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `ServerId` = {self._server_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Servers`
|
||||
WHERE `ServerId` = {self._server_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -7,8 +7,16 @@ from bot_data.model.server import Server
|
||||
|
||||
|
||||
class Statistic(TableABC):
|
||||
|
||||
def __init__(self, name: str, description: str, code: str, server: Server, created_at: datetime=None, modified_at: datetime=None, id=0):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
description: str,
|
||||
code: str,
|
||||
server: Server,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._description = description
|
||||
@@ -17,67 +25,78 @@ class Statistic(TableABC):
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
|
||||
@description.setter
|
||||
def description(self, value: str):
|
||||
self._description = value
|
||||
|
||||
|
||||
@property
|
||||
def code(self) -> str:
|
||||
return CredentialManager.decrypt(self._code)
|
||||
|
||||
|
||||
@code.setter
|
||||
def code(self, value: str):
|
||||
self._code = CredentialManager.encrypt(value)
|
||||
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`;
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`
|
||||
WHERE `Id` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_name_string(name: str, s_id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`
|
||||
WHERE `ServerId` = {s_id}
|
||||
AND `Name` = '{name}';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_string(s_id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`
|
||||
WHERE `ServerId` = {s_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Statistics` (
|
||||
`Name`, `Description`, `Code`, `ServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -88,22 +107,27 @@ class Statistic(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Statistics`
|
||||
SET `Name` = '{self._name}',
|
||||
`Description` = '{self._description}',
|
||||
`Code` = '{self._code}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Statistics`
|
||||
WHERE `Id` = {self._id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -6,16 +6,25 @@ from bot_data.model.server import Server
|
||||
|
||||
|
||||
class User(TableABC):
|
||||
|
||||
def __init__(self, dc_id: int, xp: int, server: Optional[Server], created_at: datetime = None, modified_at: datetime = None, id=0):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
xp: int,
|
||||
server: Optional[Server],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._user_id = id
|
||||
self._discord_id = dc_id
|
||||
self._xp = xp
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def user_id(self) -> int:
|
||||
@@ -40,35 +49,44 @@ class User(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Users`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Users`
|
||||
WHERE `UserId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Users`
|
||||
WHERE `DiscordId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_and_server_id_string(dc_id: int, s_id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Users`
|
||||
WHERE `DiscordId` = {dc_id}
|
||||
AND `ServerId` = {s_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Users` (
|
||||
`DiscordId`, `XP`, `ServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -78,20 +96,25 @@ class User(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Users`
|
||||
SET `XP` = {self._xp},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `UserId` = {self._user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Users`
|
||||
WHERE `UserId` = {self._user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -8,16 +8,25 @@ from bot_data.model.server import Server
|
||||
|
||||
|
||||
class UserJoinedServer(TableABC):
|
||||
|
||||
def __init__(self, user: User, joined_on: datetime, leaved_on: datetime=None, created_at: datetime=None, modified_at: datetime=None, id=0):
|
||||
def __init__(
|
||||
self,
|
||||
user: User,
|
||||
joined_on: datetime,
|
||||
leaved_on: datetime = None,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._join_id = id
|
||||
self._user = user
|
||||
self._joined_on = joined_on
|
||||
self._leaved_on = leaved_on
|
||||
|
||||
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
@@ -44,39 +53,48 @@ class UserJoinedServer(TableABC):
|
||||
def leaved_on(self, value: datetime):
|
||||
self._modified_at = datetime.now()
|
||||
self._leaved_on = value
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedServers`;
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedServers`
|
||||
WHERE `JoinId` = {id};
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedServers`
|
||||
WHERE `UserId` = {id};
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_active_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedServers`
|
||||
WHERE `UserId` = {id}
|
||||
AND `LeavedOn` IS NULL;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
if self._leaved_on is not None:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -86,9 +104,11 @@ class UserJoinedServer(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
else:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -97,20 +117,25 @@ class UserJoinedServer(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserJoinedServers`
|
||||
SET `LeavedOn` = '{self._leaved_on}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `UserId` = {self._user.user_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserJoinedServers`
|
||||
WHERE `Id` = {self._join_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -6,8 +6,16 @@ from bot_data.model.user import User
|
||||
|
||||
|
||||
class UserJoinedVoiceChannel(TableABC):
|
||||
|
||||
def __init__(self, user: User, dc_channel_id: int, joined_on: datetime, leaved_on: datetime = None, created_at: datetime = None, modified_at: datetime = None, id=0):
|
||||
def __init__(
|
||||
self,
|
||||
user: User,
|
||||
dc_channel_id: int,
|
||||
joined_on: datetime,
|
||||
leaved_on: datetime = None,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._join_id = id
|
||||
self._dc_channel_id = dc_channel_id
|
||||
self._user = user
|
||||
@@ -16,12 +24,14 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
return self._join_id
|
||||
|
||||
|
||||
@property
|
||||
def dc_channel_id(self) -> int:
|
||||
return self._dc_channel_id
|
||||
@@ -47,39 +57,48 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
def leaved_on(self, value: datetime):
|
||||
self._modified_at = datetime.now()
|
||||
self._leaved_on = value
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedVoiceChannel`;
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedVoiceChannel`
|
||||
WHERE `JoinId` = {id};
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedVoiceChannel`
|
||||
WHERE `UserId` = {id};
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_active_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedVoiceChannel`
|
||||
WHERE `UserId` = {id}
|
||||
AND `LeavedOn` IS NULL;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
if self._leaved_on is not None:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -90,9 +109,11 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
else:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -102,27 +123,34 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserJoinedVoiceChannel`
|
||||
SET `LeavedOn` = '{self._leaved_on}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `JoinId` = {self._join_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserJoinedVoiceChannel`
|
||||
WHERE `JoinId` = {self._join_id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserJoinedVoiceChannel`
|
||||
WHERE `UserId` = {id}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -6,16 +6,16 @@ from bot_data.model.user import User
|
||||
|
||||
|
||||
class UserMessageCountPerHour(TableABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
date: str,
|
||||
hour: int,
|
||||
xp_count: int,
|
||||
user: User,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0):
|
||||
self,
|
||||
date: str,
|
||||
hour: int,
|
||||
xp_count: int,
|
||||
user: User,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._date = date
|
||||
self._hour = hour
|
||||
@@ -24,7 +24,9 @@ class UserMessageCountPerHour(TableABC):
|
||||
|
||||
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
|
||||
self._modified_at = (
|
||||
modified_at if modified_at is not None else self._modified_at
|
||||
)
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
@@ -53,38 +55,47 @@ class UserMessageCountPerHour(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserMessageCountPerHour`;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserMessageCountPerHour`
|
||||
WHERE `Id` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserMessageCountPerHour`
|
||||
WHERE `UserId` = {id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_and_date_string(id: int, date: datetime) -> str:
|
||||
date_str = f'{str(date.year).zfill(4)}-{str(date.month).zfill(2)}-{str(date.day).zfill(2)}%'
|
||||
date_str = f"{str(date.year).zfill(4)}-{str(date.month).zfill(2)}-{str(date.day).zfill(2)}%"
|
||||
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserMessageCountPerHour`
|
||||
WHERE `UserId` = {id}
|
||||
AND `Date` LIKE '{date_str}'
|
||||
AND `Hour` = {date.hour};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserMessageCountPerHour` (
|
||||
`UserId`, `Date`, `Hour`, `XPCount`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
@@ -95,27 +106,34 @@ class UserMessageCountPerHour(TableABC):
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserMessageCountPerHour`
|
||||
SET `XPCount` = '{self._xp_count}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserMessageCountPerHour`
|
||||
WHERE `Id` = {self._id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete_by_user_id_string(id: int) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserMessageCountPerHour`
|
||||
WHERE `UserId` = {id}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -11,16 +11,16 @@ Discord bot for the Keksdose discord Server
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'bot_data.service'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||
__version__ = '0.3.0'
|
||||
__title__ = "bot_data.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 sh-edraft.de"
|
||||
__version__ = "0.3.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='3', micro='0')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="0")
|
||||
|
@@ -15,8 +15,12 @@ from bot_data.model.user import User
|
||||
|
||||
|
||||
class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, users: UserRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
self._users = users
|
||||
@@ -25,7 +29,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
|
||||
@staticmethod
|
||||
def _get_value_from_result(value: any) -> Optional[any]:
|
||||
if isinstance(value, str) and 'NULL' in value:
|
||||
if isinstance(value, str) and "NULL" in value:
|
||||
return None
|
||||
|
||||
return value
|
||||
@@ -43,10 +47,13 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
self._get_value_from_result(au_result[9]),
|
||||
self._get_value_from_result(au_result[10]),
|
||||
AuthRoleEnum(self._get_value_from_result(au_result[11])),
|
||||
auth_user_id=self._get_value_from_result(au_result[0])
|
||||
auth_user_id=self._get_value_from_result(au_result[0]),
|
||||
)
|
||||
|
||||
self._logger.trace(__name__, f'Send SQL command: {auth_user.get_select_user_id_from_relations()}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {auth_user.get_select_user_id_from_relations()}",
|
||||
)
|
||||
results = self._context.select(auth_user.get_select_user_id_from_relations())
|
||||
for result in results:
|
||||
user_id = self._get_value_from_result(result[0])
|
||||
@@ -60,36 +67,59 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
|
||||
def get_all_auth_users(self) -> List[AuthUser]:
|
||||
users = List(AuthUser)
|
||||
self._logger.trace(__name__, f'Send SQL command: {AuthUser.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AuthUser.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(AuthUser.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get auth user with id {result[0]}')
|
||||
self._logger.trace(__name__, f"Get auth user with id {result[0]}")
|
||||
users.append(self._user_from_result(result))
|
||||
|
||||
return users
|
||||
|
||||
def get_filtered_auth_users(self, criteria: AuthUserSelectCriteria) -> FilteredResult:
|
||||
def get_filtered_auth_users(
|
||||
self, criteria: AuthUserSelectCriteria
|
||||
) -> FilteredResult:
|
||||
users = self.get_all_auth_users()
|
||||
self._logger.trace(__name__, f'Send SQL command: {AuthUser.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AuthUser.get_select_all_string()}"
|
||||
)
|
||||
query = users
|
||||
|
||||
if criteria.first_name is not None and criteria.first_name != '':
|
||||
query = query.where(lambda x: criteria.first_name in x.first_name or x.first_name == criteria.first_name)
|
||||
if criteria.first_name is not None and criteria.first_name != "":
|
||||
query = query.where(
|
||||
lambda x: criteria.first_name in x.first_name
|
||||
or x.first_name == criteria.first_name
|
||||
)
|
||||
|
||||
if criteria.last_name is not None and criteria.last_name != '':
|
||||
query = query.where(lambda x: criteria.last_name in x.last_name or x.last_name == criteria.last_name)
|
||||
if criteria.last_name is not None and criteria.last_name != "":
|
||||
query = query.where(
|
||||
lambda x: criteria.last_name in x.last_name
|
||||
or x.last_name == criteria.last_name
|
||||
)
|
||||
|
||||
if criteria.email is not None and criteria.email != '':
|
||||
query = query.where(lambda x: criteria.email in x.email or x.email == criteria.email)
|
||||
if criteria.email is not None and criteria.email != "":
|
||||
query = query.where(
|
||||
lambda x: criteria.email in x.email or x.email == criteria.email
|
||||
)
|
||||
|
||||
if criteria.auth_role is not None:
|
||||
query = query.where(lambda x: x.auth_role == AuthRoleEnum(criteria.auth_role))
|
||||
query = query.where(
|
||||
lambda x: x.auth_role == AuthRoleEnum(criteria.auth_role)
|
||||
)
|
||||
|
||||
# sort
|
||||
if criteria.sort_column is not None and criteria.sort_column != '' and criteria.sort_direction is not None and criteria.sort_direction:
|
||||
if (
|
||||
criteria.sort_column is not None
|
||||
and criteria.sort_column != ""
|
||||
and criteria.sort_direction is not None
|
||||
and criteria.sort_direction
|
||||
):
|
||||
crit_sort_direction = criteria.sort_direction.lower()
|
||||
if crit_sort_direction == "desc" or crit_sort_direction == "descending":
|
||||
query = query.order_by_descending(lambda x: getattr(x, criteria.sort_column))
|
||||
query = query.order_by_descending(
|
||||
lambda x: getattr(x, criteria.sort_column)
|
||||
)
|
||||
else:
|
||||
query = query.order_by(lambda x: getattr(x, criteria.sort_column))
|
||||
|
||||
@@ -101,12 +131,16 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
return result
|
||||
|
||||
def get_auth_user_by_email(self, email: str) -> AuthUser:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AuthUser.get_select_by_email_string(email)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}"
|
||||
)
|
||||
result = self._context.select(AuthUser.get_select_by_email_string(email))[0]
|
||||
return self._user_from_result(result)
|
||||
|
||||
def find_auth_user_by_email(self, email: str) -> Optional[AuthUser]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AuthUser.get_select_by_email_string(email)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}"
|
||||
)
|
||||
result = self._context.select(AuthUser.get_select_by_email_string(email))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
@@ -116,7 +150,10 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
return self._user_from_result(result)
|
||||
|
||||
def find_auth_user_by_confirmation_id(self, id: str) -> Optional[AuthUser]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AuthUser.get_select_by_confirmation_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {AuthUser.get_select_by_confirmation_id_string(id)}",
|
||||
)
|
||||
result = self._context.select(AuthUser.get_select_by_confirmation_id_string(id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
@@ -126,8 +163,13 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
return self._user_from_result(result)
|
||||
|
||||
def find_auth_user_by_forgot_password_id(self, id: str) -> Optional[AuthUser]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AuthUser.get_select_by_forgot_password_id_string(id)}')
|
||||
result = self._context.select(AuthUser.get_select_by_forgot_password_id_string(id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {AuthUser.get_select_by_forgot_password_id_string(id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
AuthUser.get_select_by_forgot_password_id_string(id)
|
||||
)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
@@ -136,25 +178,25 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
return self._user_from_result(result)
|
||||
|
||||
def add_auth_user(self, user: AuthUser):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {user.insert_string}")
|
||||
self._context.cursor.execute(user.insert_string)
|
||||
|
||||
def update_auth_user(self, user: AuthUser):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {user.udpate_string}")
|
||||
self._context.cursor.execute(user.udpate_string)
|
||||
|
||||
def delete_auth_user(self, user: AuthUser):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {user.delete_string}")
|
||||
self._context.cursor.execute(user.delete_string)
|
||||
|
||||
def add_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
self._logger.trace(__name__, f'Send SQL command: {rel.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {rel.insert_string}")
|
||||
self._context.cursor.execute(rel.insert_string)
|
||||
|
||||
def update_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
self._logger.trace(__name__, f'Send SQL command: {rel.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {rel.udpate_string}")
|
||||
self._context.cursor.execute(rel.udpate_string)
|
||||
|
||||
def delete_auth_user_user_rel(self, rel: AuthUserUsersRelation):
|
||||
self._logger.trace(__name__, f'Send SQL command: {rel.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {rel.delete_string}")
|
||||
self._context.cursor.execute(rel.delete_string)
|
||||
|
@@ -10,7 +10,6 @@ from bot_data.model.auto_role_rule import AutoRoleRule
|
||||
|
||||
|
||||
class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
@@ -19,34 +18,32 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
||||
|
||||
def get_auto_roles(self) -> List[AutoRole]:
|
||||
auto_roles = List(AutoRole)
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AutoRole.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(AutoRole.get_select_all_string())
|
||||
for result in results:
|
||||
auto_roles.append(AutoRole(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
auto_roles.append(
|
||||
AutoRole(
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
)
|
||||
|
||||
return auto_roles
|
||||
|
||||
def get_auto_role_by_id(self, id: int) -> AutoRole:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(AutoRole.get_select_by_id_string(id))[0]
|
||||
return AutoRole(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
|
||||
def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(AutoRole.get_select_by_id_string(id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
@@ -54,44 +51,39 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
||||
result = result[0]
|
||||
|
||||
return AutoRole(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
|
||||
def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_server_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AutoRole.get_select_by_server_id_string(id)}"
|
||||
)
|
||||
auto_roles = List(AutoRole)
|
||||
results = self._context.select(AutoRole.get_select_by_server_id_string(id))
|
||||
for result in results:
|
||||
auto_roles.append(AutoRole(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
auto_roles.append(
|
||||
AutoRole(
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
)
|
||||
|
||||
return auto_roles
|
||||
|
||||
def get_auto_role_by_message_id(self, id: int) -> AutoRole:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_message_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {AutoRole.get_select_by_message_id_string(id)}",
|
||||
)
|
||||
result = self._context.select(AutoRole.get_select_by_message_id_string(id))[0]
|
||||
return AutoRole(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
|
||||
def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_message_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {AutoRole.get_select_by_message_id_string(id)}",
|
||||
)
|
||||
result = self._context.select(AutoRole.get_select_by_message_id_string(id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
@@ -99,78 +91,77 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
||||
result = result[0]
|
||||
|
||||
return AutoRole(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
|
||||
def add_auto_role(self, auto_role: AutoRole):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {auto_role.insert_string}")
|
||||
self._context.cursor.execute(auto_role.insert_string)
|
||||
|
||||
def update_auto_role(self, auto_role: AutoRole):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {auto_role.udpate_string}")
|
||||
self._context.cursor.execute(auto_role.udpate_string)
|
||||
|
||||
def delete_auto_role(self, auto_role: AutoRole):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {auto_role.delete_string}")
|
||||
self._context.cursor.execute(auto_role.delete_string)
|
||||
|
||||
def get_auto_role_rules(self) -> List[AutoRoleRule]:
|
||||
auto_role_rules = List(AutoRoleRule)
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRoleRule.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AutoRoleRule.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(AutoRoleRule.get_select_all_string())
|
||||
for result in results:
|
||||
auto_role_rules.append(AutoRoleRule(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
auto_role_rules.append(
|
||||
AutoRoleRule(
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
)
|
||||
|
||||
return auto_role_rules
|
||||
|
||||
def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule:
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRoleRule.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {AutoRoleRule.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(AutoRoleRule.get_select_by_id_string(id))[0]
|
||||
return AutoRoleRule(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
|
||||
def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]:
|
||||
auto_role_rules = List(AutoRoleRule)
|
||||
self._logger.trace(__name__, f'Send SQL command: {AutoRoleRule.get_select_by_auto_role_id_string(id)}')
|
||||
results = self._context.select(AutoRoleRule.get_select_by_auto_role_id_string(id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {AutoRoleRule.get_select_by_auto_role_id_string(id)}",
|
||||
)
|
||||
results = self._context.select(
|
||||
AutoRoleRule.get_select_by_auto_role_id_string(id)
|
||||
)
|
||||
for result in results:
|
||||
auto_role_rules.append(AutoRoleRule(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
auto_role_rules.append(
|
||||
AutoRoleRule(
|
||||
result[1], result[2], result[3], result[4], result[5], id=result[0]
|
||||
)
|
||||
)
|
||||
|
||||
return auto_role_rules
|
||||
|
||||
def add_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.insert_string}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {auto_role_rule.insert_string}"
|
||||
)
|
||||
self._context.cursor.execute(auto_role_rule.insert_string)
|
||||
|
||||
def update_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.udpate_string}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {auto_role_rule.udpate_string}"
|
||||
)
|
||||
self._context.cursor.execute(auto_role_rule.udpate_string)
|
||||
|
||||
def delete_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.delete_string}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {auto_role_rule.delete_string}"
|
||||
)
|
||||
self._context.cursor.execute(auto_role_rule.delete_string)
|
||||
|
@@ -10,8 +10,12 @@ from bot_data.model.client import Client
|
||||
|
||||
|
||||
class ClientRepositoryService(ClientRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
servers: ServerRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
@@ -21,25 +25,31 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
|
||||
def get_clients(self) -> List[Client]:
|
||||
clients = List(Client)
|
||||
self._logger.trace(__name__, f'Send SQL command: {Client.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Client.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(Client.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get client with id {result[0]}')
|
||||
clients.append(Client(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
id=result[0]
|
||||
))
|
||||
self._logger.trace(__name__, f"Get client with id {result[0]}")
|
||||
clients.append(
|
||||
Client(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return clients
|
||||
|
||||
def get_client_by_id(self, client_id: int) -> Client:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_id_string(client_id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Client.get_select_by_id_string(client_id)}"
|
||||
)
|
||||
result = self._context.select(Client.get_select_by_id_string(client_id))
|
||||
return Client(
|
||||
result[1],
|
||||
@@ -49,12 +59,17 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(Client.get_select_by_discord_id_string(discord_id))[0]
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Client.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
Client.get_select_by_discord_id_string(discord_id)
|
||||
)[0]
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -63,17 +78,22 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(Client.get_select_by_discord_id_string(discord_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Client.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
Client.get_select_by_discord_id_string(discord_id)
|
||||
)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -82,17 +102,20 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_client_by_server_id(self, discord_id: int) -> Optional[Client]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_server_id_string(discord_id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Client.get_select_by_server_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(Client.get_select_by_server_id_string(discord_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -101,17 +124,24 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}')
|
||||
result = self._context.select(Client.get_select_by_discord_id_and_server_id_string(discord_id, server_id))
|
||||
def find_client_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> Optional[Client]:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Client.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
Client.get_select_by_discord_id_and_server_id_string(discord_id, server_id)
|
||||
)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -120,32 +150,34 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result[5],
|
||||
result[6],
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
|
||||
def add_client(self, client: Client):
|
||||
self._logger.trace(__name__, f'Send SQL command: {client.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {client.insert_string}")
|
||||
self._context.cursor.execute(client.insert_string)
|
||||
|
||||
|
||||
def update_client(self, client: Client):
|
||||
self._logger.trace(__name__, f'Send SQL command: {client.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {client.udpate_string}")
|
||||
self._context.cursor.execute(client.udpate_string)
|
||||
|
||||
|
||||
def delete_client(self, client: Client):
|
||||
self._logger.trace(__name__, f'Send SQL command: {client.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {client.delete_string}")
|
||||
self._context.cursor.execute(client.delete_string)
|
||||
|
||||
def _get_client_and_server(self, id: int, server_id: int) -> Client:
|
||||
server = self._servers.find_server_by_discord_id(server_id)
|
||||
if server is None:
|
||||
self._logger.warn(__name__, f'Cannot find server by id {server_id}')
|
||||
raise Exception('Value not found')
|
||||
|
||||
self._logger.warn(__name__, f"Cannot find server by id {server_id}")
|
||||
raise Exception("Value not found")
|
||||
|
||||
client = self.find_client_by_discord_id_and_server_id(id, server.server_id)
|
||||
if client is None:
|
||||
self._logger.warn(__name__, f'Cannot find client by ids {id}@{server.server_id}')
|
||||
raise Exception('Value not found')
|
||||
|
||||
self._logger.warn(
|
||||
__name__, f"Cannot find client by ids {id}@{server.server_id}"
|
||||
)
|
||||
raise Exception("Value not found")
|
||||
|
||||
return client
|
||||
|
||||
def append_sent_message_count(self, client_id: int, server_id: int, value: int):
|
||||
|
@@ -10,8 +10,12 @@ from bot_data.model.known_user import KnownUser
|
||||
|
||||
|
||||
class KnownUserRepositoryService(KnownUserRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
servers: ServerRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
@@ -21,58 +25,52 @@ class KnownUserRepositoryService(KnownUserRepositoryABC):
|
||||
|
||||
def get_users(self) -> List[KnownUser]:
|
||||
users = List(KnownUser)
|
||||
self._logger.trace(__name__, f'Send SQL command: {KnownUser.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {KnownUser.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(KnownUser.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get known_user with id {result[0]}')
|
||||
users.append(KnownUser(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
))
|
||||
self._logger.trace(__name__, f"Get known_user with id {result[0]}")
|
||||
users.append(KnownUser(result[1], result[2], result[3], id=result[0]))
|
||||
|
||||
return users
|
||||
|
||||
def get_user_by_id(self, id: int) -> KnownUser:
|
||||
self._logger.trace(__name__, f'Send SQL command: {KnownUser.get_select_by_id_string(id)}')
|
||||
result = self._context.select(KnownUser.get_select_by_id_string(id))
|
||||
return KnownUser(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {KnownUser.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(KnownUser.get_select_by_id_string(id))
|
||||
return KnownUser(result[1], result[2], result[3], id=result[0])
|
||||
|
||||
def get_user_by_discord_id(self, discord_id: int) -> KnownUser:
|
||||
self._logger.trace(__name__, f'Send SQL command: {KnownUser.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(KnownUser.get_select_by_discord_id_string(discord_id))[0]
|
||||
return KnownUser(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {KnownUser.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
KnownUser.get_select_by_discord_id_string(discord_id)
|
||||
)[0]
|
||||
return KnownUser(result[1], result[2], result[3], id=result[0])
|
||||
|
||||
def find_user_by_discord_id(self, discord_id: int) -> Optional[KnownUser]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {KnownUser.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(KnownUser.get_select_by_discord_id_string(discord_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {KnownUser.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
KnownUser.get_select_by_discord_id_string(discord_id)
|
||||
)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
return KnownUser(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
|
||||
return KnownUser(result[1], result[2], result[3], id=result[0])
|
||||
|
||||
def add_user(self, known_user: KnownUser):
|
||||
self._logger.trace(__name__, f'Send SQL command: {known_user.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {known_user.insert_string}")
|
||||
self._context.cursor.execute(known_user.insert_string)
|
||||
|
||||
|
||||
def delete_user(self, known_user: KnownUser):
|
||||
self._logger.trace(__name__, f'Send SQL command: {known_user.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {known_user.delete_string}")
|
||||
self._context.cursor.execute(known_user.delete_string)
|
||||
|
@@ -10,8 +10,12 @@ from bot_data.model.level import Level
|
||||
|
||||
|
||||
class LevelRepositoryService(LevelRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
servers: ServerRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
@@ -21,7 +25,7 @@ class LevelRepositoryService(LevelRepositoryABC):
|
||||
|
||||
@staticmethod
|
||||
def _get_value_from_result(value: any) -> Optional[any]:
|
||||
if isinstance(value, str) and 'NULL' in value:
|
||||
if isinstance(value, str) and "NULL" in value:
|
||||
return None
|
||||
|
||||
return value
|
||||
@@ -33,27 +37,33 @@ class LevelRepositoryService(LevelRepositoryABC):
|
||||
int(self._get_value_from_result(sql_result[3])), # min xp
|
||||
int(self._get_value_from_result(sql_result[4])), # permissions
|
||||
self._servers.get_server_by_id(sql_result[5]), # server
|
||||
id=self._get_value_from_result(sql_result[0]) # id
|
||||
id=self._get_value_from_result(sql_result[0]), # id
|
||||
)
|
||||
|
||||
def get_levels(self) -> List[Level]:
|
||||
levels = List(Level)
|
||||
self._logger.trace(__name__, f'Send SQL command: {Level.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Level.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(Level.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get level with id {result[0]}')
|
||||
self._logger.trace(__name__, f"Get level with id {result[0]}")
|
||||
levels.append(self._level_from_result(result))
|
||||
|
||||
return levels
|
||||
|
||||
def get_level_by_id(self, id: int) -> Level:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(Level.get_select_by_id_string(id))[0]
|
||||
|
||||
return self._level_from_result(result)
|
||||
|
||||
def find_level_by_id(self, id: int) -> Optional[Level]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(Level.get_select_by_id_string(id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
@@ -62,36 +72,42 @@ class LevelRepositoryService(LevelRepositoryABC):
|
||||
|
||||
def get_levels_by_server_id(self, server_id: int) -> List[Level]:
|
||||
levels = List(Level)
|
||||
self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_server_id_string(server_id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}",
|
||||
)
|
||||
results = self._context.select(Level.get_select_by_server_id_string(server_id))
|
||||
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get level with id {result[0]}')
|
||||
self._logger.trace(__name__, f"Get level with id {result[0]}")
|
||||
levels.append(self._level_from_result(result))
|
||||
|
||||
return levels
|
||||
|
||||
def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]:
|
||||
levels = List(Level)
|
||||
self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_server_id_string(server_id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}",
|
||||
)
|
||||
results = self._context.select(Level.get_select_by_server_id_string(server_id))
|
||||
if results is None or len(results) == 0:
|
||||
return None
|
||||
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get level with id {result[0]}')
|
||||
self._logger.trace(__name__, f"Get level with id {result[0]}")
|
||||
levels.append(self._level_from_result(result))
|
||||
|
||||
return levels
|
||||
|
||||
def add_level(self, level: Level):
|
||||
self._logger.trace(__name__, f'Send SQL command: {level.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {level.insert_string}")
|
||||
self._context.cursor.execute(level.insert_string)
|
||||
|
||||
def update_level(self, level: Level):
|
||||
self._logger.trace(__name__, f'Send SQL command: {level.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {level.udpate_string}")
|
||||
self._context.cursor.execute(level.udpate_string)
|
||||
|
||||
def delete_level(self, level: Level):
|
||||
self._logger.trace(__name__, f'Send SQL command: {level.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {level.delete_string}")
|
||||
self._context.cursor.execute(level.delete_string)
|
||||
|
@@ -10,16 +10,22 @@ from bot_data.model.migration_history import MigrationHistory
|
||||
|
||||
|
||||
class MigrationService:
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, services: ServiceProviderABC, db: DatabaseContextABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
services: ServiceProviderABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._services = services
|
||||
|
||||
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
self._migrations = List(type, MigrationABC.__subclasses__()).order_by(lambda x: x.name)
|
||||
|
||||
self._migrations = List(type, MigrationABC.__subclasses__()).order_by(
|
||||
lambda x: x.name
|
||||
)
|
||||
|
||||
def migrate(self):
|
||||
self._logger.info(__name__, f"Running Migrations")
|
||||
for migration in self._migrations:
|
||||
@@ -30,16 +36,25 @@ class MigrationService:
|
||||
result = self._cursor.fetchone()
|
||||
if result:
|
||||
# there is a table named "tableName"
|
||||
self._logger.trace(__name__, f"Running SQL Command: {MigrationHistory.get_select_by_id_string(migration_id)}")
|
||||
migration_from_db = self._db.select(MigrationHistory.get_select_by_id_string(migration_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Running SQL Command: {MigrationHistory.get_select_by_id_string(migration_id)}",
|
||||
)
|
||||
migration_from_db = self._db.select(
|
||||
MigrationHistory.get_select_by_id_string(migration_id)
|
||||
)
|
||||
if migration_from_db is not None and len(migration_from_db) > 0:
|
||||
continue
|
||||
|
||||
|
||||
self._logger.debug(__name__, f"Running Migration {migration_id}")
|
||||
migration_as_service: MigrationABC = self._services.get_service(migration)
|
||||
migration_as_service: MigrationABC = self._services.get_service(
|
||||
migration
|
||||
)
|
||||
migration_as_service.upgrade()
|
||||
self._cursor.execute(MigrationHistory(migration_id).insert_string)
|
||||
self._db.save_changes()
|
||||
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Cannot get migration with id {migration}', e)
|
||||
self._logger.error(
|
||||
__name__, f"Cannot get migration with id {migration}", e
|
||||
)
|
||||
|
@@ -7,8 +7,12 @@ from bot_data.abc.data_seeder_abc import DataSeederABC
|
||||
|
||||
|
||||
class SeederService:
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, services: ServiceProviderABC, db: DatabaseContextABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
services: ServiceProviderABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._services = services
|
||||
|
||||
|
@@ -11,7 +11,6 @@ from bot_data.model.server import Server
|
||||
|
||||
|
||||
class ServerRepositoryService(ServerRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
@@ -20,26 +19,34 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
|
||||
def get_servers(self) -> List[Server]:
|
||||
servers = List(Server)
|
||||
self._logger.trace(__name__, f'Send SQL command: {Server.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Server.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(Server.get_select_all_string())
|
||||
for result in results:
|
||||
servers.append(Server(
|
||||
result[1],
|
||||
id=result[0]
|
||||
))
|
||||
servers.append(Server(result[1], id=result[0]))
|
||||
|
||||
return servers
|
||||
|
||||
def get_filtered_servers(self, criteria: ServerSelectCriteria) -> FilteredResult:
|
||||
servers = self.get_servers()
|
||||
self._logger.trace(__name__, f'Send SQL command: {Server.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Server.get_select_all_string()}"
|
||||
)
|
||||
query = servers
|
||||
|
||||
# sort
|
||||
if criteria.sort_column is not None and criteria.sort_column != '' and criteria.sort_direction is not None and criteria.sort_direction:
|
||||
if (
|
||||
criteria.sort_column is not None
|
||||
and criteria.sort_column != ""
|
||||
and criteria.sort_direction is not None
|
||||
and criteria.sort_direction
|
||||
):
|
||||
crit_sort_direction = criteria.sort_direction.lower()
|
||||
if crit_sort_direction == "desc" or crit_sort_direction == "descending":
|
||||
query = query.order_by_descending(lambda x: getattr(x, criteria.sort_column))
|
||||
query = query.order_by_descending(
|
||||
lambda x: getattr(x, criteria.sort_column)
|
||||
)
|
||||
else:
|
||||
query = query.order_by(lambda x: getattr(x, criteria.sort_column))
|
||||
|
||||
@@ -51,44 +58,45 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
return result
|
||||
|
||||
def get_server_by_id(self, server_id: int) -> Server:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_id_string(server_id)}')
|
||||
result = self._context.select(Server.get_select_by_id_string(server_id))[0]
|
||||
return Server(
|
||||
result[1],
|
||||
id=result[0]
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Server.get_select_by_id_string(server_id)}"
|
||||
)
|
||||
result = self._context.select(Server.get_select_by_id_string(server_id))[0]
|
||||
return Server(result[1], id=result[0])
|
||||
|
||||
def get_server_by_discord_id(self, discord_id: int) -> Server:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(Server.get_select_by_discord_id_string(discord_id))[0]
|
||||
return Server(
|
||||
result[1],
|
||||
id=result[0]
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
Server.get_select_by_discord_id_string(discord_id)
|
||||
)[0]
|
||||
return Server(result[1], id=result[0])
|
||||
|
||||
def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(Server.get_select_by_discord_id_string(discord_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
Server.get_select_by_discord_id_string(discord_id)
|
||||
)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
|
||||
return Server(result[1], result[2], result[3], id=result[0])
|
||||
|
||||
def add_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {server.insert_string}")
|
||||
self._context.cursor.execute(server.insert_string)
|
||||
|
||||
|
||||
def update_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {server.udpate_string}")
|
||||
self._context.cursor.execute(server.udpate_string)
|
||||
|
||||
|
||||
def delete_server(self, server: Server):
|
||||
self._logger.trace(__name__, f'Send SQL command: {server.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {server.delete_string}")
|
||||
self._context.cursor.execute(server.delete_string)
|
||||
|
@@ -11,8 +11,12 @@ from bot_data.model.statistic import Statistic
|
||||
|
||||
|
||||
class StatisticRepositoryService(StatisticRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, statistics: ServerRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
statistics: ServerRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
@@ -22,7 +26,7 @@ class StatisticRepositoryService(StatisticRepositoryABC):
|
||||
|
||||
@staticmethod
|
||||
def _get_value_from_result(value: any) -> Optional[any]:
|
||||
if isinstance(value, str) and 'NULL' in value:
|
||||
if isinstance(value, str) and "NULL" in value:
|
||||
return None
|
||||
|
||||
return value
|
||||
@@ -37,14 +41,16 @@ class StatisticRepositoryService(StatisticRepositoryABC):
|
||||
self._get_value_from_result(sql_result[2]),
|
||||
code,
|
||||
self._statistics.get_server_by_id(sql_result[4]),
|
||||
id=self._get_value_from_result(sql_result[0])
|
||||
id=self._get_value_from_result(sql_result[0]),
|
||||
)
|
||||
|
||||
return statistic
|
||||
|
||||
def get_statistics(self) -> List[Statistic]:
|
||||
statistics = List(Statistic)
|
||||
self._logger.trace(__name__, f'Send SQL command: {Statistic.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Statistic.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(Statistic.get_select_all_string())
|
||||
for result in results:
|
||||
statistics.append(self._statistic_from_result(result))
|
||||
@@ -53,7 +59,10 @@ class StatisticRepositoryService(StatisticRepositoryABC):
|
||||
|
||||
def get_statistics_by_server_id(self, server_id: int) -> List[Statistic]:
|
||||
statistics = List(Statistic)
|
||||
self._logger.trace(__name__, f'Send SQL command: {Statistic.get_select_by_server_string(server_id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Statistic.get_select_by_server_string(server_id)}",
|
||||
)
|
||||
results = self._context.select(Statistic.get_select_by_server_string(server_id))
|
||||
for result in results:
|
||||
statistics.append(self._statistic_from_result(result))
|
||||
@@ -61,18 +70,30 @@ class StatisticRepositoryService(StatisticRepositoryABC):
|
||||
return statistics
|
||||
|
||||
def get_statistic_by_id(self, id: int) -> Statistic:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Statistic.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {Statistic.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(Statistic.get_select_by_id_string(id))[0]
|
||||
return self._statistic_from_result(result)
|
||||
|
||||
def get_statistic_by_name(self, name: str, server_id: int) -> Statistic:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Statistic.get_select_by_name_string(name, server_id)}')
|
||||
result = self._context.select(Statistic.get_select_by_name_string(name, server_id))[0]
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Statistic.get_select_by_name_string(name, server_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
Statistic.get_select_by_name_string(name, server_id)
|
||||
)[0]
|
||||
return self._statistic_from_result(result)
|
||||
|
||||
def find_statistic_by_name(self, name: str, server_id: int) -> Optional[Statistic]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {Statistic.get_select_by_name_string(name, server_id)}')
|
||||
result = self._context.select(Statistic.get_select_by_name_string(name, server_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {Statistic.get_select_by_name_string(name, server_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
Statistic.get_select_by_name_string(name, server_id)
|
||||
)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
@@ -81,13 +102,13 @@ class StatisticRepositoryService(StatisticRepositoryABC):
|
||||
return self._statistic_from_result(result)
|
||||
|
||||
def add_statistic(self, statistic: Statistic):
|
||||
self._logger.trace(__name__, f'Send SQL command: {statistic.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {statistic.insert_string}")
|
||||
self._context.cursor.execute(statistic.insert_string)
|
||||
|
||||
def update_statistic(self, statistic: Statistic):
|
||||
self._logger.trace(__name__, f'Send SQL command: {statistic.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {statistic.udpate_string}")
|
||||
self._context.cursor.execute(statistic.udpate_string)
|
||||
|
||||
def delete_statistic(self, statistic: Statistic):
|
||||
self._logger.trace(__name__, f'Send SQL command: {statistic.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {statistic.delete_string}")
|
||||
self._context.cursor.execute(statistic.delete_string)
|
||||
|
@@ -4,15 +4,18 @@ from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.user_joined_server_repository_abc import \
|
||||
UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.user_joined_server import UserJoinedServer
|
||||
|
||||
|
||||
class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, users: UserRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
@@ -22,23 +25,30 @@ class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
||||
|
||||
def get_user_joined_servers(self) -> List[UserJoinedServer]:
|
||||
joins = List(UserJoinedServer)
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedServer.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {UserJoinedServer.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(UserJoinedServer.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get user-joined-server with id {result[0]}')
|
||||
joins.append(UserJoinedServer(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
self._logger.trace(__name__, f"Get user-joined-server with id {result[0]}")
|
||||
joins.append(
|
||||
UserJoinedServer(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return joins
|
||||
|
||||
|
||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedServer.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedServer.get_select_by_id_string(id)}",
|
||||
)
|
||||
result = self._context.select(UserJoinedServer.get_select_by_id_string(id))[0]
|
||||
return UserJoinedServer(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
@@ -46,40 +56,63 @@ class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> List[UserJoinedServer]:
|
||||
|
||||
def get_user_joined_servers_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[UserJoinedServer]:
|
||||
joins = List(UserJoinedServer)
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}')
|
||||
results = self._context.select(UserJoinedServer.get_select_by_user_id_string(user_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}",
|
||||
)
|
||||
results = self._context.select(
|
||||
UserJoinedServer.get_select_by_user_id_string(user_id)
|
||||
)
|
||||
for result in results:
|
||||
joins.append(UserJoinedServer(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
|
||||
joins.append(
|
||||
UserJoinedServer(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return joins
|
||||
|
||||
def get_active_user_joined_server_by_user_id(self, user_id: int) -> UserJoinedServer:
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}')
|
||||
result = self._context.select(UserJoinedServer.get_select_active_by_user_id_string(user_id))[0]
|
||||
|
||||
def get_active_user_joined_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> UserJoinedServer:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
UserJoinedServer.get_select_active_by_user_id_string(user_id)
|
||||
)[0]
|
||||
return UserJoinedServer(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_active_user_joined_server_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserJoinedServer]:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
UserJoinedServer.get_select_active_by_user_id_string(user_id)
|
||||
)
|
||||
|
||||
def find_active_user_joined_server_by_user_id(self, user_id: int) -> Optional[UserJoinedServer]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}')
|
||||
result = self._context.select(UserJoinedServer.get_select_active_by_user_id_string(user_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
@@ -91,17 +124,23 @@ class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
|
||||
def add_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user_joined_server.insert_string}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {user_joined_server.insert_string}"
|
||||
)
|
||||
self._context.cursor.execute(user_joined_server.insert_string)
|
||||
|
||||
|
||||
def update_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user_joined_server.udpate_string}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {user_joined_server.udpate_string}"
|
||||
)
|
||||
self._context.cursor.execute(user_joined_server.udpate_string)
|
||||
|
||||
|
||||
def delete_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user_joined_server.delete_string}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {user_joined_server.delete_string}"
|
||||
)
|
||||
self._context.cursor.execute(user_joined_server.delete_string)
|
||||
|
@@ -4,14 +4,20 @@ from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import (
|
||||
UserJoinedVoiceChannelRepositoryABC,
|
||||
)
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
||||
|
||||
|
||||
class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, users: UserRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
@@ -21,64 +27,99 @@ class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryAB
|
||||
|
||||
def get_user_joined_voice_channels(self) -> List[UserJoinedVoiceChannel]:
|
||||
joins = List(UserJoinedVoiceChannel)
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_all_string()}",
|
||||
)
|
||||
results = self._context.select(UserJoinedVoiceChannel.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get user-joined-voice-channel with id {result[0]}')
|
||||
joins.append(UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
self._logger.trace(
|
||||
__name__, f"Get user-joined-voice-channel with id {result[0]}"
|
||||
)
|
||||
joins.append(
|
||||
UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return joins
|
||||
|
||||
|
||||
def get_user_joined_voice_channel_by_id(self, id: int) -> UserJoinedVoiceChannel:
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.get_select_by_id_string(id)}')
|
||||
result = self._context.select(UserJoinedVoiceChannel.get_select_by_id_string(id))[0]
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_id_string(id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
UserJoinedVoiceChannel.get_select_by_id_string(id)
|
||||
)[0]
|
||||
return UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def get_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[UserJoinedVoiceChannel]:
|
||||
|
||||
def get_user_joined_voice_channels_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[UserJoinedVoiceChannel]:
|
||||
joins = List(UserJoinedVoiceChannel)
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}')
|
||||
results = self._context.select(UserJoinedVoiceChannel.get_select_by_user_id_string(user_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}",
|
||||
)
|
||||
results = self._context.select(
|
||||
UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)
|
||||
)
|
||||
for result in results:
|
||||
joins.append(UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
))
|
||||
|
||||
joins.append(
|
||||
UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return joins
|
||||
|
||||
def get_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> UserJoinedVoiceChannel:
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}')
|
||||
result = self._context.select(UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id))[0]
|
||||
|
||||
def get_active_user_joined_voice_channel_by_user_id(
|
||||
self, user_id: int
|
||||
) -> UserJoinedVoiceChannel:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id)
|
||||
)[0]
|
||||
return UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(result[1]),
|
||||
result[2],
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_active_user_joined_voice_channel_by_user_id(
|
||||
self, user_id: int
|
||||
) -> Optional[UserJoinedVoiceChannel]:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id)
|
||||
)
|
||||
|
||||
def find_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> Optional[UserJoinedVoiceChannel]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}')
|
||||
result = self._context.select(UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
@@ -90,38 +131,64 @@ class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryAB
|
||||
result[3],
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_active_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[Optional[UserJoinedVoiceChannel]]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id)}')
|
||||
def find_active_user_joined_voice_channels_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[Optional[UserJoinedVoiceChannel]]:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id)}",
|
||||
)
|
||||
result = List(UserJoinedVoiceChannel)
|
||||
db_results = self._context.select(UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id))
|
||||
db_results = self._context.select(
|
||||
UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id)
|
||||
)
|
||||
|
||||
for db_result in db_results:
|
||||
result.append(UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(db_result[1]),
|
||||
db_result[2],
|
||||
db_result[3],
|
||||
db_result[4],
|
||||
db_result[5],
|
||||
id=db_result[0]
|
||||
))
|
||||
result.append(
|
||||
UserJoinedVoiceChannel(
|
||||
self._users.get_user_by_id(db_result[1]),
|
||||
db_result[2],
|
||||
db_result[3],
|
||||
db_result[4],
|
||||
db_result[5],
|
||||
id=db_result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
def add_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user_joined_voice_channel.insert_string}')
|
||||
|
||||
def add_user_joined_voice_channel(
|
||||
self, user_joined_voice_channel: UserJoinedVoiceChannel
|
||||
):
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {user_joined_voice_channel.insert_string}"
|
||||
)
|
||||
self._context.cursor.execute(user_joined_voice_channel.insert_string)
|
||||
|
||||
def update_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user_joined_voice_channel.udpate_string}')
|
||||
|
||||
def update_user_joined_voice_channel(
|
||||
self, user_joined_voice_channel: UserJoinedVoiceChannel
|
||||
):
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {user_joined_voice_channel.udpate_string}"
|
||||
)
|
||||
self._context.cursor.execute(user_joined_voice_channel.udpate_string)
|
||||
|
||||
def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user_joined_voice_channel.delete_string}')
|
||||
|
||||
def delete_user_joined_voice_channel(
|
||||
self, user_joined_voice_channel: UserJoinedVoiceChannel
|
||||
):
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {user_joined_voice_channel.delete_string}"
|
||||
)
|
||||
self._context.cursor.execute(user_joined_voice_channel.delete_string)
|
||||
|
||||
def delete_user_joined_voice_channel_by_user_id(self, user_id: int):
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.delete_by_user_id_string}')
|
||||
self._context.cursor.execute(UserJoinedVoiceChannel.delete_by_user_id_string(user_id))
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserJoinedVoiceChannel.delete_by_user_id_string}",
|
||||
)
|
||||
self._context.cursor.execute(
|
||||
UserJoinedVoiceChannel.delete_by_user_id_string(user_id)
|
||||
)
|
||||
|
@@ -5,18 +5,19 @@ from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.user_message_count_per_hour_repository_abc import UserMessageCountPerHourRepositoryABC
|
||||
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.model.user_message_count_per_hour import UserMessageCountPerHour
|
||||
|
||||
|
||||
class UserMessageCountPerHourRepositoryService(UserMessageCountPerHourRepositoryABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
):
|
||||
UserMessageCountPerHourRepositoryABC.__init__(self)
|
||||
|
||||
@@ -26,7 +27,7 @@ class UserMessageCountPerHourRepositoryService(UserMessageCountPerHourRepository
|
||||
|
||||
@staticmethod
|
||||
def _get_value_from_result(value: any) -> Optional[any]:
|
||||
if isinstance(value, str) and 'NULL' in value:
|
||||
if isinstance(value, str) and "NULL" in value:
|
||||
return None
|
||||
|
||||
return value
|
||||
@@ -39,44 +40,59 @@ class UserMessageCountPerHourRepositoryService(UserMessageCountPerHourRepository
|
||||
self._users.get_user_by_id(self._get_value_from_result(result[4])),
|
||||
self._get_value_from_result(result[5]),
|
||||
self._get_value_from_result(result[6]),
|
||||
id=self._get_value_from_result(result[0])
|
||||
id=self._get_value_from_result(result[0]),
|
||||
)
|
||||
|
||||
def get_user_message_count_per_hours(self) -> List[UserMessageCountPerHour]:
|
||||
umcphs = List(UserMessageCountPerHour)
|
||||
self._logger.trace(__name__, f'Send SQL command: {UserMessageCountPerHour.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {UserMessageCountPerHour.get_select_all_string()}",
|
||||
)
|
||||
results = self._context.select(UserMessageCountPerHour.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get user message count per hour with id {result[0]}')
|
||||
self._logger.trace(
|
||||
__name__, f"Get user message count per hour with id {result[0]}"
|
||||
)
|
||||
umcphs.append(self._from_result(result))
|
||||
|
||||
return umcphs
|
||||
|
||||
def find_user_message_count_per_hour_by_user_id(self, user_id: int) -> List[Optional[UserMessageCountPerHour]]:
|
||||
def find_user_message_count_per_hour_by_user_id(
|
||||
self, user_id: int
|
||||
) -> List[Optional[UserMessageCountPerHour]]:
|
||||
umcphs = List(UserMessageCountPerHour)
|
||||
sql = UserMessageCountPerHour.get_select_by_user_id_string(user_id)
|
||||
self._logger.trace(__name__, f'Send SQL command: {sql}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
||||
results = self._context.select(sql)
|
||||
if results is None or len(results) == 0:
|
||||
return umcphs
|
||||
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get user message count per hour with id {result[0]}')
|
||||
self._logger.trace(
|
||||
__name__, f"Get user message count per hour with id {result[0]}"
|
||||
)
|
||||
umcphs.append(self._from_result(result))
|
||||
|
||||
return umcphs
|
||||
|
||||
def get_user_message_count_per_hour_by_user_id_and_date(self, user_id: int, date: datetime) -> \
|
||||
UserMessageCountPerHour:
|
||||
sql = UserMessageCountPerHour.get_select_by_user_id_and_date_string(user_id, date)
|
||||
self._logger.trace(__name__, f'Send SQL command: {sql}')
|
||||
def get_user_message_count_per_hour_by_user_id_and_date(
|
||||
self, user_id: int, date: datetime
|
||||
) -> UserMessageCountPerHour:
|
||||
sql = UserMessageCountPerHour.get_select_by_user_id_and_date_string(
|
||||
user_id, date
|
||||
)
|
||||
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
||||
result = self._context.select(sql)[0]
|
||||
return self._from_result(result)
|
||||
|
||||
def find_user_message_count_per_hour_by_user_id_and_date(self, user_id: int, date: datetime) -> \
|
||||
Optional[UserMessageCountPerHour]:
|
||||
sql = UserMessageCountPerHour.get_select_by_user_id_and_date_string(user_id, date)
|
||||
self._logger.trace(__name__, f'Send SQL command: {sql}')
|
||||
def find_user_message_count_per_hour_by_user_id_and_date(
|
||||
self, user_id: int, date: datetime
|
||||
) -> Optional[UserMessageCountPerHour]:
|
||||
sql = UserMessageCountPerHour.get_select_by_user_id_and_date_string(
|
||||
user_id, date
|
||||
)
|
||||
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
||||
result = self._context.select(sql)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
@@ -84,18 +100,18 @@ class UserMessageCountPerHourRepositoryService(UserMessageCountPerHourRepository
|
||||
return self._from_result(result[0])
|
||||
|
||||
def add_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
self._logger.trace(__name__, f'Send SQL command: {umcph.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {umcph.insert_string}")
|
||||
self._context.cursor.execute(umcph.insert_string)
|
||||
|
||||
def update_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
self._logger.trace(__name__, f'Send SQL command: {umcph.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {umcph.udpate_string}")
|
||||
self._context.cursor.execute(umcph.udpate_string)
|
||||
|
||||
def delete_user_message_count_per_hour(self, umcph: UserMessageCountPerHour):
|
||||
self._logger.trace(__name__, f'Send SQL command: {umcph.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {umcph.delete_string}")
|
||||
self._context.cursor.execute(umcph.delete_string)
|
||||
|
||||
def delete_user_message_count_per_hour_by_user_id(self, user_id: int):
|
||||
sql = UserMessageCountPerHour.delete_by_user_id_string(user_id)
|
||||
self._logger.trace(__name__, f'Send SQL command: {sql}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
||||
self._context.cursor.execute(sql)
|
||||
|
@@ -10,8 +10,12 @@ from bot_data.model.user import User
|
||||
|
||||
|
||||
class UserRepositoryService(UserRepositoryABC):
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
servers: ServerRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
@@ -21,32 +25,40 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
|
||||
def get_users(self) -> List[User]:
|
||||
users = List(User)
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_all_string()}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {User.get_select_all_string()}"
|
||||
)
|
||||
results = self._context.select(User.get_select_all_string())
|
||||
for result in results:
|
||||
self._logger.trace(__name__, f'Get user with id {result[0]}')
|
||||
users.append(User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
))
|
||||
self._logger.trace(__name__, f"Get user with id {result[0]}")
|
||||
users.append(
|
||||
User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return users
|
||||
|
||||
def get_user_by_id(self, id: int) -> User:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {User.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(User.get_select_by_id_string(id))[0]
|
||||
|
||||
return User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_user_by_id(self, id: int) -> Optional[User]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_id_string(id)}')
|
||||
self._logger.trace(
|
||||
__name__, f"Send SQL command: {User.get_select_by_id_string(id)}"
|
||||
)
|
||||
result = self._context.select(User.get_select_by_id_string(id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
@@ -57,59 +69,78 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
||||
users = List(User)
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}')
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {User.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
results = self._context.select(User.get_select_by_discord_id_string(discord_id))
|
||||
for result in results:
|
||||
users.append(User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
))
|
||||
users.append(
|
||||
User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return users
|
||||
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}')
|
||||
result = self._context.select(User.get_select_by_discord_id_and_server_id_string(discord_id, server_id))[0]
|
||||
|
||||
def get_user_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> User:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)
|
||||
)[0]
|
||||
|
||||
return User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[User]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}')
|
||||
result = self._context.select(User.get_select_by_discord_id_and_server_id_string(discord_id, server_id))
|
||||
def find_user_by_discord_id_and_server_id(
|
||||
self, discord_id: int, server_id: int
|
||||
) -> Optional[User]:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}",
|
||||
)
|
||||
result = self._context.select(
|
||||
User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)
|
||||
)
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
result[4],
|
||||
result[5],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
|
||||
def add_user(self, user: User):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.insert_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {user.insert_string}")
|
||||
self._context.cursor.execute(user.insert_string)
|
||||
|
||||
|
||||
def update_user(self, user: User):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.udpate_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {user.udpate_string}")
|
||||
self._context.cursor.execute(user.udpate_string)
|
||||
|
||||
|
||||
def delete_user(self, user: User):
|
||||
self._logger.trace(__name__, f'Send SQL command: {user.delete_string}')
|
||||
self._logger.trace(__name__, f"Send SQL command: {user.delete_string}")
|
||||
self._context.cursor.execute(user.delete_string)
|
||||
|
Reference in New Issue
Block a user