Merge pull request '1.0.0' (#253) from 1.0.0 into master
Reviewed-on: sh-edraft.de/kd_discord_bot#253 Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com> Reviewed-by: edraft-dev <dev.sven.heidemann@sh-edraft.de>
This commit is contained in:
commit
75ad07477a
34
kdb-bot/.cpl/schematic_query.py
Normal file
34
kdb-bot/.cpl/schematic_query.py
Normal file
@ -0,0 +1,34 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class query(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
code = textwrap.dedent(
|
||||
"""\
|
||||
from bot_graphql.abc.data_query_abc import DataQueryABC
|
||||
|
||||
|
||||
class $ClassName(DataQueryABC):
|
||||
def __init__(self):
|
||||
DataQueryABC.__init__(self, "Name")
|
||||
|
||||
self.set_field("id", self.resolve_id)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x, *_):
|
||||
return x.id
|
||||
"""
|
||||
)
|
||||
return self.build_code_str(
|
||||
code,
|
||||
ClassName=self._class_name,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "query", [])
|
@ -6,13 +6,13 @@
|
||||
"bot-api": "src/bot_api/bot-api.json",
|
||||
"bot-core": "src/bot_core/bot-core.json",
|
||||
"bot-data": "src/bot_data/bot-data.json",
|
||||
"bot-graphql": "src/bot_graphql/bot-graphql.json",
|
||||
"auto-role": "src/modules/auto_role/auto-role.json",
|
||||
"base": "src/modules/base/base.json",
|
||||
"boot-log": "src/modules/boot_log/boot-log.json",
|
||||
"database": "src/modules/database/database.json",
|
||||
"level": "src/modules/level/level.json",
|
||||
"permission": "src/modules/permission/permission.json",
|
||||
"stats": "src/modules/stats/stats.json",
|
||||
"technician": "src/modules/technician/technician.json",
|
||||
"checks": "tools/checks/checks.json",
|
||||
"get-version": "tools/get_version/get-version.json",
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 6b25cc87fced30b5846505d95f20285a3e4d7adf
|
||||
Subproject commit 62475d65465f289604c7a32d23b5c29bb8cd38a4
|
@ -14,6 +14,8 @@ RUN apk add nano
|
||||
|
||||
RUN pip install -r requirements.txt --extra-index-url https://pip.sh-edraft.de
|
||||
RUN pip install flask[async]
|
||||
RUN pip install dnspython==2.2.1 # https://stackoverflow.com/questions/75137717/eventlet-dns-python-attribute-error-module-dns-rdtypes-has-no-attribute-any
|
||||
|
||||
# RUN pip install dnspython==2.2.1 # https://stackoverflow.com/questions/75137717/eventlet-dns-python-attribute-error-module-dns-rdtypes-has-no-attribute-any
|
||||
# ^ probably fixed py package updates
|
||||
|
||||
CMD [ "bash", "/app/bot/bot"]
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1.post1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@ -18,20 +18,22 @@
|
||||
"Dependencies": [
|
||||
"cpl-core==2022.12.1.post3",
|
||||
"cpl-translation==2022.12.1",
|
||||
"cpl-query==2022.12.2.post1",
|
||||
"cpl-discord==2022.12.1.post2",
|
||||
"cpl-query==2022.12.2.post2",
|
||||
"cpl-discord==2022.12.2.post1",
|
||||
"Flask==2.2.2",
|
||||
"Flask-Classful==0.14.2",
|
||||
"Flask-Cors==3.0.10",
|
||||
"PyJWT==2.6.0",
|
||||
"waitress==2.1.2",
|
||||
"Flask-SocketIO==5.3.2",
|
||||
"eventlet==0.33.2",
|
||||
"eventlet==0.33.3",
|
||||
"requests-oauthlib==1.3.1",
|
||||
"icmplib==3.0.3"
|
||||
"icmplib==3.0.3",
|
||||
"ariadne==0.17.1"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.12.1.post3"
|
||||
"cpl-cli==2022.12.1.post3",
|
||||
"pygount==1.5.1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
@ -55,13 +57,13 @@
|
||||
"../bot_api/bot-api.json",
|
||||
"../bot_core/bot-core.json",
|
||||
"../bot_data/bot-data.json",
|
||||
"../bot_graphql/bot-graphql.json",
|
||||
"../modules/auto_role/auto-role.json",
|
||||
"../modules/base/base.json",
|
||||
"../modules/boot_log/boot-log.json",
|
||||
"../modules/database/database.json",
|
||||
"../modules/level/level.json",
|
||||
"../modules/permission/permission.json",
|
||||
"../modules/stats/stats.json",
|
||||
"../modules/technician/technician.json"
|
||||
]
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit b0ae87621bbe54fd9c5650071ec8c1c9ec32df48
|
||||
Subproject commit 0c9463753731ab1f5d0f916d21ac7ea304742995
|
@ -15,7 +15,7 @@ __title__ = "bot.extension"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -4,13 +4,13 @@ from bot_api.api_module import ApiModule
|
||||
from bot_core.core_extension.core_extension_module import CoreExtensionModule
|
||||
from bot_core.core_module import CoreModule
|
||||
from bot_data.data_module import DataModule
|
||||
from bot_graphql.graphql_module import GraphQLModule
|
||||
from modules.auto_role.auto_role_module import AutoRoleModule
|
||||
from modules.base.base_module import BaseModule
|
||||
from modules.boot_log.boot_log_module import BootLogModule
|
||||
from modules.database.database_module import DatabaseModule
|
||||
from modules.level.level_module import LevelModule
|
||||
from modules.permission.permission_module import PermissionModule
|
||||
from modules.stats.stats_module import StatsModule
|
||||
from modules.technician.technician_module import TechnicianModule
|
||||
|
||||
|
||||
@ -23,13 +23,13 @@ class ModuleList:
|
||||
[
|
||||
CoreModule, # has to be first!
|
||||
DataModule,
|
||||
GraphQLModule,
|
||||
PermissionModule,
|
||||
LevelModule,
|
||||
DatabaseModule,
|
||||
AutoRoleModule,
|
||||
BaseModule,
|
||||
LevelModule,
|
||||
ApiModule,
|
||||
StatsModule,
|
||||
TechnicianModule,
|
||||
# has to be last!
|
||||
BootLogModule,
|
||||
|
@ -4,15 +4,20 @@ from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.migration.api_key_migration import ApiKeyMigration
|
||||
from bot_data.migration.api_migration import ApiMigration
|
||||
from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration
|
||||
from bot_data.migration.auto_role_migration import AutoRoleMigration
|
||||
from bot_data.migration.db_history_migration import DBHistoryMigration
|
||||
from bot_data.migration.initial_migration import InitialMigration
|
||||
from bot_data.migration.level_migration import LevelMigration
|
||||
from bot_data.migration.remove_stats_migration import RemoveStatsMigration
|
||||
from bot_data.migration.stats_migration import StatsMigration
|
||||
from bot_data.migration.user_joined_game_server_migration import UserJoinedGameServerMigration
|
||||
from bot_data.migration.user_message_count_per_hour_migration import (
|
||||
UserMessageCountPerHourMigration,
|
||||
)
|
||||
from bot_data.migration.user_warning_migration import UserWarningMigration
|
||||
from bot_data.service.migration_service import MigrationService
|
||||
|
||||
|
||||
@ -32,3 +37,8 @@ class StartupMigrationExtension(StartupExtensionABC):
|
||||
services.add_transient(MigrationABC, StatsMigration) # 09.11.2022 #46 - 0.3.0
|
||||
services.add_transient(MigrationABC, AutoRoleFix1Migration) # 30.12.2022 #151 - 0.3.0
|
||||
services.add_transient(MigrationABC, UserMessageCountPerHourMigration) # 11.01.2023 #168 - 0.3.1
|
||||
services.add_transient(MigrationABC, ApiKeyMigration) # 09.02.2023 #162 - 1.0.0
|
||||
services.add_transient(MigrationABC, UserJoinedGameServerMigration) # 12.02.2023 #181 - 1.0.0
|
||||
services.add_transient(MigrationABC, RemoveStatsMigration) # 19.02.2023 #190 - 1.0.0
|
||||
services.add_transient(MigrationABC, UserWarningMigration) # 21.02.2023 #35 - 1.0.0
|
||||
services.add_transient(MigrationABC, DBHistoryMigration) # 06.03.2023 #246 - 1.0.0
|
||||
|
@ -1,51 +1,27 @@
|
||||
{
|
||||
"api": {
|
||||
"api": {
|
||||
"test_mail": {
|
||||
"message": "Dies ist eine Test-Mail vom Krümelmonster Web Interface\nGesendet von {}-{}",
|
||||
"subject": "Krümelmonster Web Interface Test-Mail"
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
"confirmation": {
|
||||
"message": "Öffne den Link, um die E-Mail zu bestätigen:\n{}auth/register/{}",
|
||||
"subject": "E-Mail für {} {} bestätigen"
|
||||
},
|
||||
"forgot_password": {
|
||||
"message": "Öffne den Link, um das Passwort zu ändern:\n{}auth/forgot-password/{}",
|
||||
"subject": "Passwort für {} {} zurücksetzen"
|
||||
}
|
||||
},
|
||||
"mail": {
|
||||
"automatic_mail": "\n\nDies ist eine automatische E-Mail.\nGesendet von {}-{}@{}"
|
||||
}
|
||||
},
|
||||
"common": {
|
||||
"hello_world": "Hallo Welt",
|
||||
"bot_has_no_permission_message": "Ey!!!\nWas soll das?\nIch habe keine Berechtigungen :(\nScheiß System...",
|
||||
"no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯",
|
||||
"not_implemented_yet": "Ey Alter, das kann ich noch nicht...",
|
||||
"presence": {
|
||||
"booting": "{} Ich fahre gerade hoch...",
|
||||
"running": "{} Ich esse Kekse :D",
|
||||
"restart": "{} Muss neue Kekse holen...",
|
||||
"shutdown": "{} Ich werde bestimmt wieder kommen..."
|
||||
},
|
||||
"errors": {
|
||||
"error": "Es gab einen Fehler. Meld dich bitte bei einem Admin.",
|
||||
"command_error": "Es gab einen Fehler beim bearbeiten des Befehls. Meld dich bitte bei einem Admin.",
|
||||
"missing_required_argument": "Fehler: Ein benötigter Parameter fehlt!",
|
||||
"argument_parsing_error": "Fehler: Parameter konnte nicht gelesen werden!",
|
||||
"unexpected_quote_error": "Fehler: Unerwarteter Zitat Fehler!",
|
||||
"invalid_end_of_quoted_string_error": "Fehler: Ungültiges Zitatende!",
|
||||
"expected_closing_quote_error": "Fehler: Erwarte Zitatende!",
|
||||
"bad_argument": "Fehler: Ungültiger Parameter!",
|
||||
"bad_union_argument": "Fehler: Ungültiger Union Parameter!",
|
||||
"private_message_only": "Fehler: Nur private Nachrichten sind erlaubt!",
|
||||
"no_private_message": "Fehler: Private Nachrichten sind nicht erlaubt!",
|
||||
"check_failure": "Fehler: Du hast nicht die benötigte Berechtigung!",
|
||||
"check_any_failure": "Fehler: Alle checks sind Fehlgeschlagen!",
|
||||
"command_not_found": "Fehler: Befehl konnte nicht gefunden werden!",
|
||||
"disabled_command": "Fehler: Befehl wurde deaktiviert!",
|
||||
"command_invoke_error": "Fehler: Befehl konnte nicht aufgerufen werden!",
|
||||
"too_many_arguments": "Fehler: Zu viele Parameter!",
|
||||
"user_input_error": "Fehler: Eingabefehler!",
|
||||
"command_on_cooldown": "Fehler: Befehl befindet sich im cooldown!",
|
||||
"max_concurrency_reached": "Fehler: Maximale Parallelität erreicht!",
|
||||
"not_owner": "Fehler: Du bist nicht mein besitzer!",
|
||||
"missing_permissions": "Fehler: Berechtigungen fehlen!",
|
||||
"bot_missing_permissions": "Fehler: Mir fehlen Berechtigungen!",
|
||||
"missing_role": "Fehler: Benötigte Rolle fehlt!",
|
||||
"bot_missing_role": "Fehler: Mir fehlt eine benötigte Rolle!",
|
||||
"missing_any_role": "Fehler: Alle benötigten Rollen fehlen!",
|
||||
"bot_missing_any_role": "Fehler: Mir fehlen alle benötigten Rollen!",
|
||||
"nsfw_channel_required": "Fehler: NSFW Kanal benötigt!",
|
||||
"extension_error": "Fehler: Erweiterungsfehler!",
|
||||
"extension_already_loaded": "Fehler: Erweiterung wurde bereits geladen!",
|
||||
"extension_not_loaded": "Fehler: Erweiterung wurde nicht geladen!",
|
||||
"no_entry_point_error": "Fehler: Kein Eintrittspunkt!",
|
||||
"extension_failed": "Fehler: Erweiterung ist fehlgeschlagen!",
|
||||
"bot_not_ready_yet": "Ey Alter! Gedulde dich doch mal! ..."
|
||||
},
|
||||
"colors": {
|
||||
"blue": "Blau",
|
||||
"dark_blue": "Dunkelblau",
|
||||
@ -69,242 +45,296 @@
|
||||
"red": "Rot",
|
||||
"teal": "Blaugrün",
|
||||
"yellow": "Gelb"
|
||||
},
|
||||
"errors": {
|
||||
"argument_parsing_error": "Fehler: Parameter konnte nicht gelesen werden!",
|
||||
"bad_argument": "Fehler: Ungültiger Parameter!",
|
||||
"bad_union_argument": "Fehler: Ungültiger Union Parameter!",
|
||||
"bot_missing_any_role": "Fehler: Mir fehlen alle benötigten Rollen!",
|
||||
"bot_missing_permissions": "Fehler: Mir fehlen Berechtigungen!",
|
||||
"bot_missing_role": "Fehler: Mir fehlt eine benötigte Rolle!",
|
||||
"bot_not_ready_yet": "Ey Alter! Gedulde dich doch mal! ...",
|
||||
"check_any_failure": "Fehler: Alle Checks sind Fehlgeschlagen!",
|
||||
"check_failure": "Fehler: Du hast nicht die benötigte Berechtigung!",
|
||||
"command_error": "Es gab einen Fehler beim Bearbeiten des Befehls. Melde dich bitte bei einem Admin.",
|
||||
"command_invoke_error": "Fehler: Befehl konnte nicht aufgerufen werden!",
|
||||
"command_not_found": "Fehler: Befehl konnte nicht gefunden werden!",
|
||||
"command_on_cooldown": "Fehler: Befehl befindet sich im Cooldown!",
|
||||
"disabled_command": "Fehler: Befehl wurde deaktiviert!",
|
||||
"error": "Es gab einen Fehler. Melde dich bitte bei einem Admin.",
|
||||
"expected_closing_quote_error": "Fehler: Erwarte Zitatende!",
|
||||
"extension_already_loaded": "Fehler: Erweiterung wurde bereits geladen!",
|
||||
"extension_error": "Fehler: Erweiterungsfehler!",
|
||||
"extension_failed": "Fehler: Erweiterung ist fehlgeschlagen!",
|
||||
"extension_not_loaded": "Fehler: Erweiterung wurde nicht geladen!",
|
||||
"invalid_end_of_quoted_string_error": "Fehler: Ungültiges Zitatende!",
|
||||
"max_concurrency_reached": "Fehler: Maximale Parallelität erreicht!",
|
||||
"missing_any_role": "Fehler: Alle benötigten Rollen fehlen!",
|
||||
"missing_permissions": "Fehler: Berechtigungen fehlen!",
|
||||
"missing_required_argument": "Fehler: Ein benötigter Parameter fehlt!",
|
||||
"missing_role": "Fehler: Benötigte Rolle fehlt!",
|
||||
"no_entry_point_error": "Fehler: Kein Eintrittspunkt!",
|
||||
"no_private_message": "Fehler: Private Nachrichten sind nicht erlaubt!",
|
||||
"not_owner": "Fehler: Du bist nicht mein besitzer!",
|
||||
"nsfw_channel_required": "Fehler: NSFW Kanal benötigt!",
|
||||
"private_message_only": "Fehler: Nur private Nachrichten sind erlaubt!",
|
||||
"too_many_arguments": "Fehler: Zu viele Parameter!",
|
||||
"unexpected_quote_error": "Fehler: Unerwarteter Fehler beim Anführungszeichen!",
|
||||
"user_input_error": "Fehler: Eingabefehler!"
|
||||
},
|
||||
"hello_world": "Hallo Welt",
|
||||
"no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯",
|
||||
"not_implemented_yet": "Ey Alter, das kann ich noch nicht...",
|
||||
"presence": {
|
||||
"booting": "Ich fahre gerade hoch...",
|
||||
"restart": "Muss neue Kekse holen...",
|
||||
"running": "Ich esse Kekse :D",
|
||||
"shutdown": "Ich werde bestimmt wieder kommen..."
|
||||
}
|
||||
},
|
||||
"modules": {
|
||||
"auto_role": {
|
||||
"list": {
|
||||
"title": "Beobachtete Nachrichten:",
|
||||
"description": "Von auto-role beobachtete Nachrichten:",
|
||||
"auto_role_id": "auto-role Id",
|
||||
"message_id": "Nachricht-Id"
|
||||
},
|
||||
"add": {
|
||||
"success": "auto-role für die Nachricht {} wurde hinzugefügt :D",
|
||||
"error": {
|
||||
"not_found": "Nachricht {} in {} nicht gefunden!",
|
||||
"already_exists": "auto-role für die Nachricht {} existiert bereits!"
|
||||
}
|
||||
},
|
||||
"remove": {
|
||||
"success": "auto-role {} wurde entfernt :D",
|
||||
"error": {
|
||||
"not_found": "auto-role {} nicht gefunden!"
|
||||
}
|
||||
"already_exists": "auto-role für die Nachricht {} existiert bereits!",
|
||||
"not_found": "Nachricht {} in {} nicht gefunden!"
|
||||
},
|
||||
"success": "auto-role für die Nachricht {} wurde hinzugefügt :D"
|
||||
},
|
||||
"error": {
|
||||
"nothing_found": "Keine auto-role Einträge gefunden."
|
||||
},
|
||||
"list": {
|
||||
"auto_role_id": "auto-role Id",
|
||||
"description": "Von auto-role beobachtete Nachrichten:",
|
||||
"message_id": "Nachricht-Id",
|
||||
"title": "Beobachtete Nachrichten:"
|
||||
},
|
||||
"remove": {
|
||||
"error": {
|
||||
"not_found": "auto-role {} nicht gefunden!"
|
||||
},
|
||||
"success": "auto-role {} wurde entfernt :D"
|
||||
},
|
||||
"rule": {
|
||||
"list": {
|
||||
"title": "auto-role Regeln:",
|
||||
"description": "Von auto-role angewendete Regeln:",
|
||||
"auto_role_rule_id": "auto-role Regel Id",
|
||||
"emoji": "Emoji",
|
||||
"role": "Rolle"
|
||||
},
|
||||
"add": {
|
||||
"success": "Regel {} -> {} für auto-role {} wurde hinzugefügt :D",
|
||||
"error": {
|
||||
"not_found": "Regel für auto-role {} nicht gefunden!",
|
||||
"already_exists": "Regel für auto-role {} existiert bereits!",
|
||||
"emoji_not_found": "Emoji {} für auto-role Regel {} nicht gefunden!",
|
||||
"role_not_found": "Rolle {} für auto-role Regel {} nicht gefunden!",
|
||||
"already_exists": "Regel für auto-role {} existiert bereits!"
|
||||
}
|
||||
},
|
||||
"remove": {
|
||||
"success": "Regel für auto-role {} wurde entfernt :D",
|
||||
"error": {
|
||||
"not_found": "Regel für auto-role {} nicht gefunden!"
|
||||
}
|
||||
"not_found": "Regel für auto-role {} nicht gefunden!",
|
||||
"role_not_found": "Rolle {} für auto-role Regel {} nicht gefunden!"
|
||||
},
|
||||
"success": "Regel {} -> {} für auto-role {} wurde hinzugefügt :D"
|
||||
},
|
||||
"error": {
|
||||
"id_not_found": "Kein auto-role Eintrag mit der Id gefunden!"
|
||||
},
|
||||
"list": {
|
||||
"auto_role_rule_id": "auto-role Regel Id",
|
||||
"description": "Von auto-role angewendete Regeln:",
|
||||
"emoji": "Emoji",
|
||||
"role": "Rolle",
|
||||
"title": "auto-role Regeln:"
|
||||
},
|
||||
"remove": {
|
||||
"error": {
|
||||
"not_found": "Regel für auto-role {} nicht gefunden!"
|
||||
},
|
||||
"success": "Regel für auto-role {} wurde entfernt :D"
|
||||
}
|
||||
}
|
||||
},
|
||||
"moderator": {
|
||||
"purge_message": "Na gut..., ich lösche alle Nachrichten wenns sein muss."
|
||||
},
|
||||
"base": {
|
||||
"technician_error_message": "Es gab ein Fehler mit dem Event: {}\nDatum und Zeit: {}\nSchau bitte ins log für Details.\nUUID: {}",
|
||||
"technician_command_error_message": "Es gab ein Fehler mit dem Befehl: {} ausgelöst von {} -> {}\nDatum und Zeit: {}\nSchau bitte ins log für Details.\nUUID: {}",
|
||||
"welcome_message": "Hello There!\nIch heiße dich bei {} herzlichst Willkommen!",
|
||||
"welcome_message_for_team": "{} hat gerade das Irrenhaus betreten.",
|
||||
"goodbye_message": "Schade, dass du uns so schnell verlässt :(",
|
||||
"afk_command_channel_missing_message": "Zu unfähig einem Sprachkanal beizutreten?",
|
||||
"afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)",
|
||||
"member_joined_help_voice_channel": "{} braucht hilfe, bitte kümmer dich drum :D",
|
||||
"pong": "Pong",
|
||||
"game_server": {
|
||||
"error": {
|
||||
"nothing_found": "Keine Gameserver gefunden."
|
||||
},
|
||||
"list": {
|
||||
"title": "Gameserver",
|
||||
"description": "Konfigurierte Gameserver:",
|
||||
"name": "Name",
|
||||
"api_key": "API Key"
|
||||
},
|
||||
"add": {
|
||||
"success": "Gameserver {} wurde hinzugefügt :)"
|
||||
},
|
||||
"remove": {
|
||||
"success": "Gameserver wurde entfernt :D"
|
||||
}
|
||||
},
|
||||
"goodbye_message": "Schade, dass du uns so schnell verlässt :(",
|
||||
"info": {
|
||||
"title": "Krümmelmonster",
|
||||
"description": "Informationen über mich",
|
||||
"fields": {
|
||||
"version": "Version",
|
||||
"ontime": "Ontime",
|
||||
"sent_message_count": "Gesendete Nachrichten",
|
||||
"received_message_count": "Empfangene Nachrichten",
|
||||
"deleted_message_count": "Gelöschte Nachrichten",
|
||||
"received_command_count": "Empfangene Befehle",
|
||||
"modules": "Module",
|
||||
"moved_users_count": "Verschobene Benutzer",
|
||||
"modules": "Module"
|
||||
"ontime": "Ontime",
|
||||
"received_command_count": "Empfangene Befehle",
|
||||
"received_message_count": "Empfangene Nachrichten",
|
||||
"sent_message_count": "Gesendete Nachrichten",
|
||||
"version": "Version"
|
||||
},
|
||||
"footer": ""
|
||||
"footer": "",
|
||||
"title": "Krümelmonster"
|
||||
},
|
||||
"mass_move": {
|
||||
"moved": "Alle Personen aus {} wurden nach {} verschoben.",
|
||||
"channel_from_error": "Du musst dich in einem Voicechannel befinden oder die Option \"channel_from\" mit angeben."
|
||||
"channel_from_error": "Du musst dich in einem Voicechannel befinden oder die Option \"channel_from\" mit angeben.",
|
||||
"moved": "Alle Personen aus {} wurden nach {} verschoben."
|
||||
},
|
||||
"member_joined_help_voice_channel": "{} braucht Hilfe, bitte kümmere dich drum :D",
|
||||
"pong": "Pong",
|
||||
"presence": {
|
||||
"changed": "Presence wurde geändert.",
|
||||
"removed": "Presence wurde entfernt.",
|
||||
"max_char_count_exceeded": "Der Text darf nicht mehr als 128 Zeichen lang sein!"
|
||||
"max_char_count_exceeded": "Der Text darf nicht mehr als 128 Zeichen lang sein!",
|
||||
"removed": "Presence wurde entfernt."
|
||||
},
|
||||
"register": {
|
||||
"not_found": "Benutzer konnte nicht gefunden werden!",
|
||||
"success": "Spieler wurde mit dem Mitglied verlinkt :D"
|
||||
},
|
||||
"technician_command_error_message": "Es gab ein Fehler mit dem Befehl: {} ausgelöst von {} -> {}\nDatum und Zeit: {}\nSchau bitte ins Log für Details.\nUUID: {}",
|
||||
"technician_error_message": "Es gab ein Fehler mit dem Event: {}\nDatum und Zeit: {}\nSchau bitte ins Log für Details.\nUUID: {}",
|
||||
"unregister": {
|
||||
"success": "Verlinkung wurde entfernt :D"
|
||||
},
|
||||
"user": {
|
||||
"add": {
|
||||
"xp": "Die {} von {} wurden um {} erhöht"
|
||||
},
|
||||
"atr": {
|
||||
"id": "Id",
|
||||
"name": "Name",
|
||||
"discord_join": "Discord beigetreten am",
|
||||
"id": "Id",
|
||||
"joins": "Beitritte",
|
||||
"last_join": "Server beigetreten am",
|
||||
"xp": "XP",
|
||||
"lefts": "Abgänge",
|
||||
"name": "Name",
|
||||
"ontime": "Ontime",
|
||||
"roles": "Rollen",
|
||||
"joins": "Beitritte",
|
||||
"lefts": "Abgänge",
|
||||
"warnings": "Verwarnungen"
|
||||
"warnings": "Verwarnungen",
|
||||
"xp": "XP"
|
||||
},
|
||||
"error": {
|
||||
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :("
|
||||
},
|
||||
"get": {
|
||||
"ontime": "{} war insgesamt {} Stunden aktiv in einem Sprachkanal",
|
||||
"xp": "{} hat {} xp"
|
||||
},
|
||||
"info": {
|
||||
"footer": ""
|
||||
},
|
||||
"get": {
|
||||
"xp": "{} hat {} xp",
|
||||
"ontime": "{} war insgesamt {} Stunden aktiv in einem Sprachkanal"
|
||||
},
|
||||
"set": {
|
||||
"xp": "{} hat nun {} xp",
|
||||
"error": {
|
||||
"value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(",
|
||||
"type_error": "Der angegebene Wert ist keine Zahl! :("
|
||||
}
|
||||
},
|
||||
"add": {
|
||||
"xp": "Die {} von {} wurden um {} erhöht"
|
||||
},
|
||||
"remove": {
|
||||
"xp": "Die {} von {} wurden um {} verringert"
|
||||
},
|
||||
"reset": {
|
||||
"xp": "Die {} von {} wurden entfernt",
|
||||
"ontime": "Die {} von {} wurden entfernt"
|
||||
"ontime": "Die {} von {} wurden entfernt",
|
||||
"xp": "Die {} von {} wurden entfernt"
|
||||
},
|
||||
"error": {
|
||||
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :("
|
||||
"set": {
|
||||
"error": {
|
||||
"type_error": "Der angegebene Wert ist keine Zahl! :(",
|
||||
"value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :("
|
||||
},
|
||||
"xp": "{} hat nun {} xp"
|
||||
}
|
||||
}
|
||||
},
|
||||
"warnings": {
|
||||
"add": {
|
||||
"failed": "Verwarnung konnte nicht hinzugefügt werden :(",
|
||||
"success": "Verwarnung wurde hinzugefügt :)"
|
||||
},
|
||||
"first": "Bei der nächsten Verwarnung wirst du auf das vorherige Level zurückgesetzt!",
|
||||
"kick": "Ich musste {} aufgrund zu vieler Verwarnungen kicken",
|
||||
"remove": {
|
||||
"failed": "Verwarnung konnte nicht entfernt werden :(",
|
||||
"success": "Verwarnung wurde entfernt :)"
|
||||
},
|
||||
"removed": "Die Verwarnung '{}' wurde entfernt.",
|
||||
"second": "Bei der nächsten verwarnung wirst du auf das erste Level zurückgesetzt!",
|
||||
"show": {
|
||||
"description": "Beschreibung",
|
||||
"id": "Id"
|
||||
},
|
||||
"team_removed": "Die Verwarnung '{}' an {} wurde entfernt.",
|
||||
"team_warned": "{} wurde verwarnt. Der Grund ist: {}",
|
||||
"third": "Bei der nächsten verwarnung wirst du gekickt und zurückgesetzt!",
|
||||
"warned": "Du wurdest verwarnt. Der Grund ist: {}"
|
||||
},
|
||||
"welcome_message": "Hello There!\nIch heiße dich bei {} herzlichst Willkommen!",
|
||||
"welcome_message_for_team": "{} hat gerade das Irrenhaus betreten."
|
||||
},
|
||||
"boot_log": {
|
||||
"login_message": "Ich bin on the line :D\nDer Scheiß hat {} Sekunden gedauert"
|
||||
},
|
||||
"level": {
|
||||
"new_level_message": "{} ist nun Level {}",
|
||||
"seeding_started": "Levelsystem wird neu geladen...",
|
||||
"seeding_failed": "Levelsystem konnte nicht neu geladen werden :(",
|
||||
"seeding_finished": "Levelsystem wurde Erfolgreich neu geladen :)",
|
||||
"error": {
|
||||
"nothing_found": "Keine Level Einträge gefunden.",
|
||||
"level_with_name_already_exists": "Ein Level mit dem Namen {} existiert bereits!",
|
||||
"level_with_xp_already_exists": "Das Level {} hat bereits die Mindest-XP {}!"
|
||||
},
|
||||
"list": {
|
||||
"title": "Level:",
|
||||
"description": "Konfigurierte Level:",
|
||||
"name": "Name",
|
||||
"min_xp": "Mindest-XP",
|
||||
"permission_int": "Berechtigungen"
|
||||
},
|
||||
"create": {
|
||||
"created": "Level {} mit Berechtigungen {} wurde erstellt :D"
|
||||
},
|
||||
"edit": {
|
||||
"edited": "Level {} wurde bearbeitet :D",
|
||||
"color_invalid": "Die Farbe {} ist ungültig!",
|
||||
"permission_invalid": "Der Berechtigungswert {} ist ungültig!",
|
||||
"not_found": "Level {} nicht gefunden!"
|
||||
},
|
||||
"remove": {
|
||||
"success": "Level {} wurde entfernt :D",
|
||||
"error": {
|
||||
"not_found": "Level {} nicht gefunden!"
|
||||
}
|
||||
},
|
||||
"down": {
|
||||
"already_first": "{} hat bereits das erste Level.",
|
||||
"success": "{} wurde auf Level {} runtergesetzt :)",
|
||||
"failed": "{} konnte nicht runtergesetzt werden :("
|
||||
"failed": "{} konnte nicht runtergesetzt werden :(",
|
||||
"success": "{} wurde auf Level {} runtergesetzt :)"
|
||||
},
|
||||
"edit": {
|
||||
"color_invalid": "Die Farbe {} ist ungültig!",
|
||||
"edited": "Level {} wurde bearbeitet :D",
|
||||
"not_found": "Level {} nicht gefunden!",
|
||||
"permission_invalid": "Der Berechtigungswert {} ist ungültig!"
|
||||
},
|
||||
"error": {
|
||||
"level_with_name_already_exists": "Ein Level mit dem Namen {} existiert bereits!",
|
||||
"level_with_xp_already_exists": "Das Level {} hat bereits die Mindest-XP {}!",
|
||||
"nothing_found": "Keine Einträge gefunden."
|
||||
},
|
||||
"list": {
|
||||
"description": "Konfigurierte Level:",
|
||||
"min_xp": "Mindest-XP",
|
||||
"name": "Name",
|
||||
"permission_int": "Berechtigungen",
|
||||
"title": "Level:"
|
||||
},
|
||||
"new_level_message": "{} ist nun Level {}",
|
||||
"remove": {
|
||||
"error": {
|
||||
"not_found": "Level {} nicht gefunden!"
|
||||
},
|
||||
"success": "Level {} wurde entfernt :D"
|
||||
},
|
||||
"seeding_failed": "Levelsystem konnte nicht neu geladen werden :(",
|
||||
"seeding_finished": "Levelsystem wurde erfolgreich neu geladen :)",
|
||||
"seeding_started": "Levelsystem wird neu geladen...",
|
||||
"set": {
|
||||
"already_level": "{} hat bereits das Level {} :/",
|
||||
"failed": "Das Level von {} konnte nicht auf {} gesetzt werden :(",
|
||||
"not_found": "Das Level {} konnte nicht gefunden werden :(",
|
||||
"success": "{} ist nun Level {} :)"
|
||||
},
|
||||
"up": {
|
||||
"already_last": "{} hat bereits das höchste Level.",
|
||||
"success": "{} wurde auf Level {} hochgesetzt :)",
|
||||
"failed": "{} konnte nicht hochgesetzt werden :("
|
||||
},
|
||||
"set": {
|
||||
"already_level": "{} hat bereits das Level {} :/",
|
||||
"success": "{} ist nun Level {} :)",
|
||||
"failed": "Das Level von {} konnte nicht auf {} gesetzt werden :(",
|
||||
"not_found": "Das Level {} konnte nicht gefunden werden :("
|
||||
"failed": "{} konnte nicht hochgesetzt werden :(",
|
||||
"success": "{} wurde auf Level {} hochgesetzt :)"
|
||||
}
|
||||
},
|
||||
"database": {},
|
||||
"permission": {},
|
||||
"stats": {
|
||||
"list": {
|
||||
"statistic": "Statistik",
|
||||
"description": "Beschreibung",
|
||||
"nothing_found": "Keine Statistiken gefunden."
|
||||
},
|
||||
"view": {
|
||||
"statistic": "Statistik",
|
||||
"description": "Beschreibung",
|
||||
"failed": "Statistik kann nicht gezeigt werden :("
|
||||
},
|
||||
"add": {
|
||||
"failed": "Statistik kann nicht hinzugefügt werden :(",
|
||||
"success": "Statistik wurde hinzugefügt :D"
|
||||
},
|
||||
"edit": {
|
||||
"failed": "Statistik kann nicht bearbeitet werden :(",
|
||||
"success": "Statistik wurde gespeichert :D"
|
||||
},
|
||||
"remove": {
|
||||
"failed": "Statistik kann nicht gelöscht werden :(",
|
||||
"success": "Statistik wurde gelöscht :D"
|
||||
}
|
||||
"moderator": {
|
||||
"purge_message": "Na gut..., ich lösche alle Nachrichten wenns sein muss."
|
||||
},
|
||||
"technician": {
|
||||
"restart_message": "Bin gleich wieder da :D",
|
||||
"shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, Euer Freund. Lebt lange und in Frieden :)",
|
||||
"log_message": "Hier sind deine Logdateien! :)"
|
||||
}
|
||||
},
|
||||
"api": {
|
||||
"mail": {
|
||||
"automatic_mail": "\n\nDies ist eine automatische E-Mail.\nGesendet von {}-{}@{}"
|
||||
},
|
||||
"api": {
|
||||
"test_mail": {
|
||||
"subject": "Krümmelmonster Web Interface Test-Mail",
|
||||
"message": "Dies ist eine Test-Mail vom Krümmelmonster Web Interface\nGesendet von {}-{}"
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
"confirmation": {
|
||||
"subject": "E-Mail für {} {} bestätigen",
|
||||
"message": "Öffne den Link um die E-Mail zu bestätigen:\n{}auth/register/{}"
|
||||
"api_key": {
|
||||
"add": {
|
||||
"success": "API-Schlüssel für {} wurde erstellt: {}"
|
||||
},
|
||||
"get": "API-Schlüssel für {}: {}",
|
||||
"remove": {
|
||||
"not_found": "API-Schlüssel konnte nicht gefunden werden!",
|
||||
"success": "API-Schlüssel wurde entfernt :D"
|
||||
}
|
||||
},
|
||||
"forgot_password": {
|
||||
"subject": "Passwort für {} {} zurücksetzen",
|
||||
"message": "Öffne den Link um das Passwort zu ändern:\n{}auth/forgot-password/{}"
|
||||
}
|
||||
"log_message": "Hier sind deine Logdateien! :)",
|
||||
"restart_message": "Bin gleich wieder da :D",
|
||||
"shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, euer Freund. Lebt lange und in Frieden :)"
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ __title__ = "bot_api"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -52,17 +52,13 @@ class AuthServiceABC(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def add_auth_user_async(self, user_dto: AuthUserDTO):
|
||||
def add_auth_user(self, user_dto: AuthUserDTO):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def add_auth_user_by_oauth_async(self, dto: OAuthDTO):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def add_auth_user_by_discord_async(self, user_dto: AuthUserDTO, dc_id: int) -> OAuthDTO:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def update_user_async(self, update_user_dto: UpdateAuthUserDTO):
|
||||
pass
|
||||
@ -83,12 +79,16 @@ class AuthServiceABC(ABC):
|
||||
async def verify_login(self, token_str: str) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def verify_api_key(self, api_key: str) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def login_async(self, user_dto: AuthUserDTO) -> TokenDTO:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def login_discord_async(self, oauth_dto: AuthUserDTO) -> TokenDTO:
|
||||
async def login_discord_async(self, oauth_dto: AuthUserDTO, dc_id: int) -> TokenDTO:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
|
@ -1,4 +1,3 @@
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
import uuid
|
||||
@ -16,7 +15,6 @@ from werkzeug.exceptions import NotFound
|
||||
|
||||
from bot_api.configuration.api_settings import ApiSettings
|
||||
from bot_api.configuration.authentication_settings import AuthenticationSettings
|
||||
from bot_api.configuration.frontend_settings import FrontendSettings
|
||||
from bot_api.exception.service_error_code_enum import ServiceErrorCode
|
||||
from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
@ -30,7 +28,6 @@ class Api(Flask):
|
||||
logger: ApiLogger,
|
||||
services: ServiceProviderABC,
|
||||
api_settings: ApiSettings,
|
||||
frontend_settings: FrontendSettings,
|
||||
auth_settings: AuthenticationSettings,
|
||||
*args,
|
||||
**kwargs,
|
||||
@ -146,20 +143,13 @@ class Api(Flask):
|
||||
return response
|
||||
|
||||
def start(self):
|
||||
self._logger.info(
|
||||
__name__,
|
||||
f"Starting API {self._api_settings.host}:{self._api_settings.port}",
|
||||
)
|
||||
self._logger.info(__name__, f"Starting API {self._api_settings.host}:{self._api_settings.port}")
|
||||
self._register_routes()
|
||||
self.secret_key = CredentialManager.decrypt(self._auth_settings.secret_key)
|
||||
# from waitress import serve
|
||||
# https://docs.pylonsproject.org/projects/waitress/en/stable/arguments.html
|
||||
# serve(self, host=self._apt_settings.host, port=self._apt_settings.port, threads=10, connection_limit=1000, channel_timeout=10)
|
||||
wsgi.server(
|
||||
eventlet.listen((self._api_settings.host, self._api_settings.port)),
|
||||
self,
|
||||
log_output=False,
|
||||
)
|
||||
wsgi.server(eventlet.listen((self._api_settings.host, self._api_settings.port)), self, log_output=False)
|
||||
|
||||
def on_connect(self):
|
||||
self._logger.info(__name__, f"Client connected")
|
||||
|
@ -13,7 +13,7 @@ from bot_api.api import Api
|
||||
from bot_api.api_thread import ApiThread
|
||||
from bot_api.controller.auth_controller import AuthController
|
||||
from bot_api.controller.auth_discord_controller import AuthDiscordController
|
||||
from bot_api.controller.discord.server_controller import ServerController
|
||||
from bot_api.controller.graphql_controller import GraphQLController
|
||||
from bot_api.controller.gui_controller import GuiController
|
||||
from bot_api.event.bot_api_on_ready_event import BotApiOnReadyEvent
|
||||
from bot_api.service.auth_service import AuthService
|
||||
@ -45,7 +45,7 @@ class ApiModule(ModuleABC):
|
||||
services.add_transient(AuthDiscordController)
|
||||
services.add_transient(GuiController)
|
||||
services.add_transient(DiscordService)
|
||||
services.add_transient(ServerController)
|
||||
services.add_transient(GraphQLController)
|
||||
|
||||
# cpl-discord
|
||||
self._dc.add_event(DiscordEventTypesEnum.on_ready.value, BotApiOnReadyEvent)
|
||||
|
@ -2,12 +2,9 @@ from cpl_core.application import ApplicationExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||
from bot_api.configuration.authentication_settings import AuthenticationSettings
|
||||
from bot_api.route.route import Route
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
|
||||
|
||||
class AppApiExtension(ApplicationExtensionABC):
|
||||
@ -19,7 +16,4 @@ class AppApiExtension(ApplicationExtensionABC):
|
||||
if not feature_flags.get_flag(FeatureFlagsEnum.api_module):
|
||||
return
|
||||
|
||||
auth_settings: AuthenticationSettings = config.get_configuration(AuthenticationSettings)
|
||||
auth_users: AuthUserRepositoryABC = services.get_service(AuthUserRepositoryABC)
|
||||
auth: AuthServiceABC = services.get_service(AuthServiceABC)
|
||||
Route.init_authorize(auth_users, auth)
|
||||
Route.init_authorize()
|
||||
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-api",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1.post1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e6046881b562982008583afa973b39ff08b6a3c7
|
||||
Subproject commit c712f856ebe30c71ac0b144045599ed2f91a1cba
|
@ -15,7 +15,7 @@ __title__ = "bot_api.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.controller"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -6,8 +6,6 @@ from flask import request, jsonify, Response
|
||||
|
||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||
from bot_api.api import Api
|
||||
from bot_api.exception.service_error_code_enum import ServiceErrorCode
|
||||
from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.filter.auth_user_select_criteria import AuthUserSelectCriteria
|
||||
from bot_api.json_processor import JSONProcessor
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
@ -73,7 +71,7 @@ class AuthController:
|
||||
@Route.post(f"{BasePath}/register")
|
||||
async def register(self):
|
||||
dto: AuthUserDTO = JSONProcessor.process(AuthUserDTO, request.get_json(force=True, silent=True))
|
||||
await self._auth_service.add_auth_user_async(dto)
|
||||
self._auth_service.add_auth_user(dto)
|
||||
return "", 200
|
||||
|
||||
@Route.post(f"{BasePath}/register-by-id/<id>")
|
||||
@ -131,7 +129,6 @@ class AuthController:
|
||||
return "", 200
|
||||
|
||||
@Route.post(f"{BasePath}/refresh")
|
||||
@Route.authorize
|
||||
async def refresh(self) -> Response:
|
||||
dto: TokenDTO = JSONProcessor.process(TokenDTO, request.get_json(force=True, silent=True))
|
||||
result = await self._auth_service.refresh_async(dto)
|
||||
|
@ -8,7 +8,7 @@ from cpl_core.utils import CredentialManager
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_translation import TranslatePipe
|
||||
from flask import jsonify, Response
|
||||
from flask import request, session
|
||||
from flask import request
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||
@ -16,10 +16,8 @@ from bot_api.api import Api
|
||||
from bot_api.configuration.discord_authentication_settings import (
|
||||
DiscordAuthenticationSettings,
|
||||
)
|
||||
from bot_api.json_processor import JSONProcessor
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.model.auth_user_dto import AuthUserDTO
|
||||
from bot_api.model.o_auth_dto import OAuthDTO
|
||||
from bot_api.route.route import Route
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
|
||||
@ -59,7 +57,7 @@ class AuthDiscordController:
|
||||
self._bot.user.id,
|
||||
redirect_uri=self._auth_settings.redirect_url,
|
||||
state=request.args.get("state"),
|
||||
scope=self._auth_settings.scope,
|
||||
scope=self._auth_settings.scope.to_list(),
|
||||
)
|
||||
token = discord.fetch_token(
|
||||
self._auth_settings.token_url,
|
||||
@ -74,28 +72,11 @@ class AuthDiscordController:
|
||||
oauth = OAuth2Session(
|
||||
self._bot.user.id,
|
||||
redirect_uri=self._auth_settings.redirect_url,
|
||||
scope=self._auth_settings.scope,
|
||||
scope=self._auth_settings.scope.to_list(),
|
||||
)
|
||||
login_url, state = oauth.authorization_url(self._auth_settings.auth_url)
|
||||
return jsonify({"loginUrl": login_url})
|
||||
|
||||
@Route.get(f"{BasePath}/create-user")
|
||||
async def discord_create_user(self) -> Response:
|
||||
response = self._get_user_from_discord_response()
|
||||
result = await self._auth_service.add_auth_user_by_discord_async(
|
||||
AuthUserDTO(
|
||||
0,
|
||||
response["username"],
|
||||
response["discriminator"],
|
||||
response["email"],
|
||||
str(uuid.uuid4()),
|
||||
None,
|
||||
AuthRoleEnum.normal,
|
||||
),
|
||||
response["id"],
|
||||
)
|
||||
return jsonify(result.to_dict())
|
||||
|
||||
@Route.get(f"{BasePath}/login")
|
||||
async def discord_login(self) -> Response:
|
||||
response = self._get_user_from_discord_response()
|
||||
@ -109,5 +90,5 @@ class AuthDiscordController:
|
||||
AuthRoleEnum.normal,
|
||||
)
|
||||
|
||||
result = await self._auth_service.login_discord_async(dto)
|
||||
result = await self._auth_service.login_discord_async(dto, response["id"])
|
||||
return jsonify(result.to_dict())
|
||||
|
@ -1,67 +0,0 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_core.mailing import EMailClientABC, EMailClientSettings
|
||||
from cpl_translation import TranslatePipe
|
||||
from flask import Response, jsonify, request
|
||||
|
||||
from bot_api.api import Api
|
||||
from bot_api.filter.discord.server_select_criteria import ServerSelectCriteria
|
||||
from bot_api.json_processor import JSONProcessor
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.route.route import Route
|
||||
from bot_api.service.discord_service import DiscordService
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
|
||||
|
||||
class ServerController:
|
||||
BasePath = f"/api/discord/server"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
env: ApplicationEnvironmentABC,
|
||||
logger: ApiLogger,
|
||||
t: TranslatePipe,
|
||||
api: Api,
|
||||
mail_settings: EMailClientSettings,
|
||||
mailer: EMailClientABC,
|
||||
discord_service: DiscordService,
|
||||
):
|
||||
self._config = config
|
||||
self._env = env
|
||||
self._logger = logger
|
||||
self._t = t
|
||||
self._api = api
|
||||
self._mail_settings = mail_settings
|
||||
self._mailer = mailer
|
||||
self._discord_service = discord_service
|
||||
|
||||
@Route.get(f"{BasePath}/get/servers")
|
||||
@Route.authorize(role=AuthRoleEnum.admin)
|
||||
async def get_all_servers(self) -> Response:
|
||||
result = await self._discord_service.get_all_servers()
|
||||
result = result.select(lambda x: x.to_dict()).to_list()
|
||||
return jsonify(result)
|
||||
|
||||
@Route.get(f"{BasePath}/get/servers-by-user")
|
||||
@Route.authorize
|
||||
async def get_all_servers_by_user(self) -> Response:
|
||||
result = await self._discord_service.get_all_servers_by_user()
|
||||
result = result.select(lambda x: x.to_dict()).to_list()
|
||||
return jsonify(result)
|
||||
|
||||
@Route.post(f"{BasePath}/get/filtered")
|
||||
@Route.authorize
|
||||
async def get_filtered_servers(self) -> Response:
|
||||
dto: ServerSelectCriteria = JSONProcessor.process(
|
||||
ServerSelectCriteria, request.get_json(force=True, silent=True)
|
||||
)
|
||||
result = await self._discord_service.get_filtered_servers_async(dto)
|
||||
result.result = result.result.select(lambda x: x.to_dict()).to_list()
|
||||
return jsonify(result.to_dict())
|
||||
|
||||
@Route.get(f"{BasePath}/get/<id>")
|
||||
@Route.authorize
|
||||
async def get_server_by_id(self, id: int) -> Response:
|
||||
result = await self._discord_service.get_server_by_id_async(id).to_list()
|
||||
return jsonify(result.to_dict())
|
44
kdb-bot/src/bot_api/controller/graphql_controller.py
Normal file
44
kdb-bot/src/bot_api/controller/graphql_controller.py
Normal file
@ -0,0 +1,44 @@
|
||||
from ariadne import graphql_sync
|
||||
from ariadne.constants import PLAYGROUND_HTML
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from flask import request, jsonify
|
||||
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.route.route import Route
|
||||
from bot_graphql.schema import Schema
|
||||
|
||||
|
||||
class GraphQLController:
|
||||
BasePath = f"/api/graphql"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
env: ApplicationEnvironmentABC,
|
||||
logger: ApiLogger,
|
||||
schema: Schema,
|
||||
):
|
||||
self._config = config
|
||||
self._env = env
|
||||
self._logger = logger
|
||||
self._schema = schema
|
||||
|
||||
@Route.get(f"{BasePath}/playground")
|
||||
@Route.authorize(skip_in_dev=True)
|
||||
async def playground(self):
|
||||
if self._env.environment_name != "development":
|
||||
return "", 403
|
||||
|
||||
return PLAYGROUND_HTML, 200
|
||||
|
||||
@Route.post(f"{BasePath}")
|
||||
@Route.authorize(by_api_key=True)
|
||||
async def graphql(self):
|
||||
data = request.get_json()
|
||||
|
||||
# Note: Passing the request to the context is optional.
|
||||
# In Flask, the current request is always accessible as flask.request
|
||||
success, result = graphql_sync(self._schema.schema, data, context_value=request)
|
||||
|
||||
return jsonify(result), 200 if success else 400
|
@ -15,7 +15,7 @@ __title__ = "bot_api.event"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.exception"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -4,7 +4,6 @@ from werkzeug.exceptions import Unauthorized
|
||||
|
||||
|
||||
class ServiceErrorCode(Enum):
|
||||
|
||||
Unknown = 0
|
||||
|
||||
InvalidDependencies = 1
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.filter"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.filter.discord"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.logging"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -1,6 +1,10 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.abc.dto_abc import DtoABC
|
||||
from bot_api.model.user_dto import UserDTO
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
|
||||
|
||||
@ -14,6 +18,9 @@ class AuthUserDTO(DtoABC):
|
||||
password: str = None,
|
||||
confirmation_id: Optional[str] = None,
|
||||
auth_role: AuthRoleEnum = None,
|
||||
users: List[UserDTO] = None,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
):
|
||||
DtoABC.__init__(self)
|
||||
|
||||
@ -24,6 +31,13 @@ class AuthUserDTO(DtoABC):
|
||||
self._password = password
|
||||
self._is_confirmed = confirmation_id is None
|
||||
self._auth_role = auth_role
|
||||
self._created_at = created_at
|
||||
self._modified_at = modified_at
|
||||
|
||||
if users is None:
|
||||
self._users = List(UserDTO)
|
||||
else:
|
||||
self._users = users
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
@ -77,6 +91,18 @@ class AuthUserDTO(DtoABC):
|
||||
def auth_role(self, value: AuthRoleEnum):
|
||||
self._auth_role = value
|
||||
|
||||
@property
|
||||
def users(self) -> List[UserDTO]:
|
||||
return self._users
|
||||
|
||||
@property
|
||||
def created_at(self) -> datetime:
|
||||
return self._created_at
|
||||
|
||||
@property
|
||||
def modified_at(self) -> datetime:
|
||||
return self._modified_at
|
||||
|
||||
def from_dict(self, values: dict):
|
||||
self._id = values["id"]
|
||||
self._first_name = values["firstName"]
|
||||
@ -85,6 +111,15 @@ class AuthUserDTO(DtoABC):
|
||||
self._password = values["password"]
|
||||
self._is_confirmed = values["isConfirmed"]
|
||||
self._auth_role = AuthRoleEnum(values["authRole"])
|
||||
if "users" in values:
|
||||
self._users = List(UserDTO)
|
||||
for u in values["users"]:
|
||||
user = UserDTO()
|
||||
user.from_dict(u)
|
||||
self._users.add(user)
|
||||
|
||||
self._created_at = values["createdAt"]
|
||||
self._modified_at = values["modifiedAt"]
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
@ -95,4 +130,7 @@ class AuthUserDTO(DtoABC):
|
||||
"password": self._password,
|
||||
"isConfirmed": self._is_confirmed,
|
||||
"authRole": self._auth_role.value,
|
||||
"users": self._users.select(lambda u: u.to_dict()).to_list(),
|
||||
"createdAt": self._created_at,
|
||||
"modifiedAt": self._modified_at,
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.model.discord"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -1,16 +1,13 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.console import Console
|
||||
|
||||
from bot_api.abc.dto_abc import DtoABC
|
||||
|
||||
|
||||
class TokenDTO(DtoABC):
|
||||
def __init__(self, token: str, refresh_token: str):
|
||||
def __init__(self, token: str, refresh_token: str, first_login: bool = False):
|
||||
DtoABC.__init__(self)
|
||||
|
||||
self._token = token
|
||||
self._refresh_token = refresh_token
|
||||
self._first_login = first_login
|
||||
|
||||
@property
|
||||
def token(self) -> str:
|
||||
@ -20,9 +17,14 @@ class TokenDTO(DtoABC):
|
||||
def refresh_token(self) -> str:
|
||||
return self._refresh_token
|
||||
|
||||
@property
|
||||
def first_login(self) -> bool:
|
||||
return self._first_login
|
||||
|
||||
def from_dict(self, values: dict):
|
||||
self._token = values["token"]
|
||||
self._refresh_token = values["refreshToken"]
|
||||
self._first_login = values["firstLogin"]
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {"token": self._token, "refreshToken": self._refresh_token}
|
||||
return {"token": self._token, "refreshToken": self._refresh_token, "firstLogin": self._first_login}
|
||||
|
76
kdb-bot/src/bot_api/model/user_dto.py
Normal file
76
kdb-bot/src/bot_api/model/user_dto.py
Normal file
@ -0,0 +1,76 @@
|
||||
from typing import Optional
|
||||
|
||||
from bot_api.abc.dto_abc import DtoABC
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class UserDTO(DtoABC):
|
||||
def __init__(
|
||||
self,
|
||||
id: int = None,
|
||||
dc_id: int = None,
|
||||
xp: int = None,
|
||||
server: Optional[Server] = None,
|
||||
is_technician: Optional[bool] = None,
|
||||
is_admin: Optional[bool] = None,
|
||||
is_moderator: Optional[bool] = None,
|
||||
):
|
||||
DtoABC.__init__(self)
|
||||
|
||||
self._user_id = id
|
||||
self._discord_id = dc_id
|
||||
self._xp = xp
|
||||
self._server = server
|
||||
|
||||
self._is_technician = is_technician
|
||||
self._is_admin = is_admin
|
||||
self._is_moderator = is_moderator
|
||||
|
||||
@property
|
||||
def user_id(self) -> int:
|
||||
return self._user_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_id
|
||||
|
||||
@property
|
||||
def xp(self) -> int:
|
||||
return self._xp
|
||||
|
||||
@xp.setter
|
||||
def xp(self, value: int):
|
||||
self._xp = value
|
||||
|
||||
@property
|
||||
def server(self) -> Optional[Server]:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
def is_technician(self) -> bool:
|
||||
return self._is_technician if self._is_technician is not None else False
|
||||
|
||||
@property
|
||||
def is_admin(self) -> bool:
|
||||
return self._is_admin if self._is_admin is not None else False
|
||||
|
||||
@property
|
||||
def is_moderator(self) -> bool:
|
||||
return self._is_moderator if self._is_moderator is not None else False
|
||||
|
||||
def from_dict(self, values: dict):
|
||||
self._user_id = values["id"]
|
||||
self._discord_id = values["dcId"]
|
||||
self._xp = values["xp"]
|
||||
self._server = values["server"]
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"id": self._user_id,
|
||||
"dcId": self._discord_id,
|
||||
"xp": self._xp,
|
||||
"server": self._server.id,
|
||||
"isTechnician": self.is_technician,
|
||||
"isAdmin": self.is_admin,
|
||||
"isModerator": self.is_moderator,
|
||||
}
|
@ -15,7 +15,7 @@ __title__ = "bot_api.route"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -1,7 +1,9 @@
|
||||
import functools
|
||||
from functools import wraps
|
||||
from typing import Optional, Callable
|
||||
from typing import Optional, Callable, Union
|
||||
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from flask import request, jsonify
|
||||
from flask_cors import cross_origin
|
||||
|
||||
@ -11,6 +13,7 @@ from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.model.error_dto import ErrorDTO
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.auth_user import AuthUser
|
||||
|
||||
|
||||
class Route:
|
||||
@ -18,23 +21,77 @@ class Route:
|
||||
|
||||
_auth_users: Optional[AuthUserRepositoryABC] = None
|
||||
_auth: Optional[AuthServiceABC] = None
|
||||
_env = "production"
|
||||
|
||||
@classmethod
|
||||
def init_authorize(cls, auth_users: AuthUserRepositoryABC, auth: AuthServiceABC):
|
||||
@ServiceProviderABC.inject
|
||||
def init_authorize(cls, env: ApplicationEnvironmentABC, auth_users: AuthUserRepositoryABC, auth: AuthServiceABC):
|
||||
cls._auth_users = auth_users
|
||||
cls._auth = auth
|
||||
cls._env = env.environment_name
|
||||
|
||||
@classmethod
|
||||
def authorize(cls, f: Callable = None, role: AuthRoleEnum = None):
|
||||
def get_user(cls) -> Optional[Union[str, AuthUser]]:
|
||||
token = None
|
||||
api_key = None
|
||||
authorization = request.headers.get("Authorization").split()
|
||||
match authorization[0]:
|
||||
case "Bearer":
|
||||
token = authorization[1]
|
||||
case "API-Key":
|
||||
api_key = authorization[1]
|
||||
|
||||
if api_key is not None:
|
||||
return "system"
|
||||
|
||||
if token is None:
|
||||
return None
|
||||
|
||||
jwt = cls._auth.decode_token(token)
|
||||
user = cls._auth_users.get_auth_user_by_email(jwt["email"])
|
||||
return user
|
||||
|
||||
@classmethod
|
||||
def authorize(cls, f: Callable = None, role: AuthRoleEnum = None, skip_in_dev=False, by_api_key=False):
|
||||
if f is None:
|
||||
return functools.partial(cls.authorize, role=role)
|
||||
return functools.partial(cls.authorize, role=role, skip_in_dev=skip_in_dev, by_api_key=by_api_key)
|
||||
|
||||
@wraps(f)
|
||||
async def decorator(*args, **kwargs):
|
||||
if skip_in_dev and cls._env == "development":
|
||||
return await f(*args, **kwargs)
|
||||
|
||||
token = None
|
||||
api_key = None
|
||||
if "Authorization" in request.headers:
|
||||
bearer = request.headers.get("Authorization")
|
||||
token = bearer.split()[1]
|
||||
if " " not in request.headers.get("Authorization"):
|
||||
ex = ServiceException(ServiceErrorCode.Unauthorized, f"Token not set")
|
||||
error = ErrorDTO(ex.error_code, ex.message)
|
||||
return jsonify(error.to_dict()), 401
|
||||
|
||||
authorization = request.headers.get("Authorization").split()
|
||||
match authorization[0]:
|
||||
case "Bearer":
|
||||
token = authorization[1]
|
||||
case "API-Key":
|
||||
api_key = authorization[1]
|
||||
|
||||
if api_key is not None:
|
||||
valid = False
|
||||
try:
|
||||
valid = cls._auth.verify_api_key(api_key)
|
||||
except ServiceException as e:
|
||||
error = ErrorDTO(e.error_code, e.message)
|
||||
return jsonify(error.to_dict()), 403
|
||||
except Exception as e:
|
||||
return jsonify(e), 500
|
||||
|
||||
if not valid:
|
||||
ex = ServiceException(ServiceErrorCode.Unauthorized, f"API-Key invalid")
|
||||
error = ErrorDTO(ex.error_code, ex.message)
|
||||
return jsonify(error.to_dict()), 401
|
||||
|
||||
return await f(*args, **kwargs)
|
||||
|
||||
if token is None:
|
||||
ex = ServiceException(ServiceErrorCode.Unauthorized, f"Token not set")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -31,9 +31,11 @@ from bot_api.model.reset_password_dto import ResetPasswordDTO
|
||||
from bot_api.model.token_dto import TokenDTO
|
||||
from bot_api.model.update_auth_user_dto import UpdateAuthUserDTO
|
||||
from bot_api.transformer.auth_user_transformer import AuthUserTransformer as AUT
|
||||
from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.api_key import ApiKey
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.auth_user import AuthUser
|
||||
from bot_data.model.auth_user_users_relation import AuthUserUsersRelation
|
||||
@ -49,9 +51,9 @@ class AuthService(AuthServiceABC):
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
auth_users: AuthUserRepositoryABC,
|
||||
api_keys: ApiKeyRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
servers: ServerRepositoryABC,
|
||||
# mailer: MailThread,
|
||||
mailer: EMailClientABC,
|
||||
t: TranslatePipe,
|
||||
auth_settings: AuthenticationSettings,
|
||||
@ -64,6 +66,7 @@ class AuthService(AuthServiceABC):
|
||||
self._bot = bot
|
||||
self._db = db
|
||||
self._auth_users = auth_users
|
||||
self._api_keys = api_keys
|
||||
self._users = users
|
||||
self._servers = servers
|
||||
self._mailer = mailer
|
||||
@ -77,11 +80,19 @@ class AuthService(AuthServiceABC):
|
||||
|
||||
@staticmethod
|
||||
def _is_email_valid(email: str) -> bool:
|
||||
if email is None:
|
||||
raise False
|
||||
|
||||
if re.fullmatch(_email_regex, email) is not None:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def _get_api_key_str(self, api_key: ApiKey) -> str:
|
||||
return hashlib.sha256(
|
||||
f"{api_key.identifier}:{api_key.key}+{self._auth_settings.secret_key}".encode("utf-8")
|
||||
).hexdigest()
|
||||
|
||||
def generate_token(self, user: AuthUser) -> str:
|
||||
token = jwt.encode(
|
||||
payload={
|
||||
@ -215,7 +226,7 @@ class AuthService(AuthServiceABC):
|
||||
user = self._auth_users.find_auth_user_by_email(email)
|
||||
return AUT.to_dto(user) if user is not None else None
|
||||
|
||||
async def add_auth_user_async(self, user_dto: AuthUserDTO):
|
||||
def add_auth_user(self, user_dto: AuthUserDTO):
|
||||
db_user = self._auth_users.find_auth_user_by_email(user_dto.email)
|
||||
if db_user is not None:
|
||||
raise ServiceException(ServiceErrorCode.InvalidUser, "User already exists")
|
||||
@ -264,51 +275,6 @@ class AuthService(AuthServiceABC):
|
||||
|
||||
self._db.save_changes()
|
||||
|
||||
async def add_auth_user_by_discord_async(self, user_dto: AuthUserDTO, dc_id: int) -> OAuthDTO:
|
||||
db_auth_user = self._auth_users.find_auth_user_by_email(user_dto.email)
|
||||
|
||||
# user exists
|
||||
if db_auth_user is not None and db_auth_user.users.count() > 0:
|
||||
# raise ServiceException(ServiceErrorCode.InvalidUser, 'User already exists')
|
||||
self._logger.debug(__name__, f"Discord user already exists")
|
||||
return OAuthDTO(AUT.to_dto(db_auth_user), None)
|
||||
|
||||
# user exists but discord user id not set
|
||||
elif db_auth_user is not None and db_auth_user.users.count() == 0:
|
||||
self._logger.debug(__name__, f"Auth user exists but not linked with discord")
|
||||
# users = self._users.get_users_by_discord_id(user_dto.user_id)
|
||||
# add auth_user to user refs
|
||||
db_auth_user.oauth_id = None
|
||||
|
||||
else:
|
||||
# user does not exists
|
||||
self._logger.debug(__name__, f"Auth user does not exist")
|
||||
try:
|
||||
user_dto.user_id = self._users.get_users_by_discord_id(user_dto.user_id).single().user_id
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"User not found")
|
||||
user_dto.user_id = None
|
||||
|
||||
await self.add_auth_user_async(user_dto)
|
||||
db_auth_user = self._auth_users.get_auth_user_by_email(user_dto.email)
|
||||
db_auth_user.oauth_id = uuid.uuid4()
|
||||
|
||||
for g in self._bot.guilds:
|
||||
member = g.get_member(int(dc_id))
|
||||
if member is None:
|
||||
continue
|
||||
|
||||
server = self._servers.get_server_by_discord_id(g.id)
|
||||
users = self._users.get_users_by_discord_id(dc_id)
|
||||
for user in users:
|
||||
if user.server.server_id != server.server_id:
|
||||
continue
|
||||
self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_auth_user, user))
|
||||
|
||||
self._auth_users.update_auth_user(db_auth_user)
|
||||
self._db.save_changes()
|
||||
return OAuthDTO(AUT.to_dto(db_auth_user), db_auth_user.oauth_id)
|
||||
|
||||
async def update_user_async(self, update_user_dto: UpdateAuthUserDTO):
|
||||
if update_user_dto is None:
|
||||
raise ServiceException(ServiceErrorCode.InvalidData, f"User is empty")
|
||||
@ -478,6 +444,18 @@ class AuthService(AuthServiceABC):
|
||||
|
||||
return True
|
||||
|
||||
def verify_api_key(self, api_key: str) -> bool:
|
||||
try:
|
||||
keys = self._api_keys.get_api_keys().select(self._get_api_key_str)
|
||||
|
||||
if not keys.contains(api_key):
|
||||
raise ServiceException(ServiceErrorCode.InvalidData, "API-Key invalid")
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"API-Key invalid", e)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def login_async(self, user_dto: AuthUser) -> TokenDTO:
|
||||
if user_dto is None:
|
||||
raise ServiceException(ServiceErrorCode.InvalidData, "User not set")
|
||||
@ -490,6 +468,9 @@ class AuthService(AuthServiceABC):
|
||||
if db_user.password != user_dto.password:
|
||||
raise ServiceException(ServiceErrorCode.InvalidUser, "Wrong password")
|
||||
|
||||
if db_user.confirmation_id is not None:
|
||||
raise ServiceException(ServiceErrorCode.Forbidden, "E-Mail not verified")
|
||||
|
||||
token = self.generate_token(db_user)
|
||||
refresh_token = self._create_and_save_refresh_token(db_user)
|
||||
if db_user.forgot_password_id is not None:
|
||||
@ -498,23 +479,34 @@ class AuthService(AuthServiceABC):
|
||||
self._db.save_changes()
|
||||
return TokenDTO(token, refresh_token)
|
||||
|
||||
async def login_discord_async(self, user_dto: AuthUserDTO) -> TokenDTO:
|
||||
async def login_discord_async(self, user_dto: AuthUserDTO, dc_id: int) -> TokenDTO:
|
||||
if user_dto is None:
|
||||
raise ServiceException(ServiceErrorCode.InvalidData, "User not set")
|
||||
|
||||
members = self._users.get_users_by_discord_id(dc_id)
|
||||
if members.count() == 0:
|
||||
raise ServiceException(ServiceErrorCode.InvalidUser, f"Member not found")
|
||||
|
||||
added_user = False
|
||||
db_user = self._auth_users.find_auth_user_by_email(user_dto.email)
|
||||
if db_user is None:
|
||||
await self.add_auth_user_async(user_dto)
|
||||
# raise ServiceException(ServiceErrorCode.InvalidUser, f'User not found')
|
||||
self.add_auth_user(user_dto)
|
||||
added_user = True
|
||||
|
||||
db_user = self._auth_users.get_auth_user_by_email(user_dto.email)
|
||||
if db_user.users.count() == 0:
|
||||
members.for_each(lambda x: self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_user, x)))
|
||||
|
||||
if db_user.confirmation_id is not None and not added_user:
|
||||
raise ServiceException(ServiceErrorCode.Forbidden, "E-Mail not verified")
|
||||
|
||||
token = self.generate_token(db_user)
|
||||
refresh_token = self._create_and_save_refresh_token(db_user)
|
||||
if db_user.forgot_password_id is not None:
|
||||
db_user.forgot_password_id = None
|
||||
|
||||
self._db.save_changes()
|
||||
return TokenDTO(token, refresh_token)
|
||||
return TokenDTO(token, refresh_token, first_login=added_user)
|
||||
|
||||
async def refresh_async(self, token_dto: TokenDTO) -> TokenDTO:
|
||||
if token_dto is None:
|
||||
|
@ -2,7 +2,6 @@ from typing import Optional
|
||||
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from flask import jsonify
|
||||
|
||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||
from bot_api.exception.service_error_code_enum import ServiceErrorCode
|
||||
@ -10,7 +9,6 @@ from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.filter.discord.server_select_criteria import ServerSelectCriteria
|
||||
from bot_api.model.discord.server_dto import ServerDTO
|
||||
from bot_api.model.discord.server_filtered_result_dto import ServerFilteredResultDTO
|
||||
from bot_api.model.error_dto import ErrorDTO
|
||||
from bot_api.transformer.server_transformer import ServerTransformer
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
@ -35,7 +33,7 @@ class DiscordService:
|
||||
self._users = users
|
||||
|
||||
def _to_dto(self, x: Server) -> Optional[ServerDTO]:
|
||||
guild = self._bot.get_guild(x.discord_server_id)
|
||||
guild = self._bot.get_guild(x.discord_id)
|
||||
if guild is None:
|
||||
return ServerTransformer.to_dto(x, "", 0, None)
|
||||
|
||||
@ -55,8 +53,8 @@ class DiscordService:
|
||||
if role != AuthRoleEnum.admin:
|
||||
auth_user = self._auth_users.find_auth_user_by_email(token["email"])
|
||||
if auth_user is not None:
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id)
|
||||
servers = servers.where(lambda x: x.server_id in user_ids)
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.id)
|
||||
servers = servers.where(lambda x: x.id in user_ids)
|
||||
|
||||
servers = List(ServerDTO, servers)
|
||||
return servers.select(self._to_dto).where(lambda x: x.name != "")
|
||||
@ -72,8 +70,8 @@ class DiscordService:
|
||||
if role != AuthRoleEnum.admin:
|
||||
auth_user = self._auth_users.find_auth_user_by_email(token["email"])
|
||||
if auth_user is not None:
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id)
|
||||
filtered_result.result = filtered_result.result.where(lambda x: x.server_id in user_ids)
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.id)
|
||||
filtered_result.result = filtered_result.result.where(lambda x: x.id in user_ids)
|
||||
|
||||
servers: List = filtered_result.result.select(self._to_dto).where(lambda x: x.name != "")
|
||||
result = List(ServerDTO, servers)
|
||||
@ -87,7 +85,7 @@ class DiscordService:
|
||||
|
||||
async def get_server_by_id_async(self, id: int) -> ServerDTO:
|
||||
server = self._servers.get_server_by_id(id)
|
||||
guild = self._bot.get_guild(server.discord_server_id)
|
||||
guild = self._bot.get_guild(server.discord_id)
|
||||
|
||||
server_dto = ServerTransformer.to_dto(server, guild.name, guild.member_count, guild.icon)
|
||||
return server_dto
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.transformer"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -1,9 +1,16 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.abc.transformer_abc import TransformerABC
|
||||
from bot_api.model.auth_user_dto import AuthUserDTO
|
||||
from bot_api.model.user_dto import UserDTO
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.auth_user import AuthUser
|
||||
from bot_data.model.user import User
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class AuthUserTransformer(TransformerABC):
|
||||
@ -25,7 +32,28 @@ class AuthUserTransformer(TransformerABC):
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_dto(db: AuthUser, password: str = None) -> AuthUserDTO:
|
||||
@ServiceProviderABC.inject
|
||||
def _is_technician(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_technician(member)
|
||||
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _is_admin(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_admin(member)
|
||||
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _is_moderator(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_moderator(member)
|
||||
|
||||
@classmethod
|
||||
def to_dto(cls, db: AuthUser, password: str = None) -> AuthUserDTO:
|
||||
return AuthUserDTO(
|
||||
db.id,
|
||||
db.first_name,
|
||||
@ -34,4 +62,20 @@ class AuthUserTransformer(TransformerABC):
|
||||
"" if password is None else password,
|
||||
db.confirmation_id,
|
||||
db.auth_role,
|
||||
List(
|
||||
UserDTO,
|
||||
db.users.select(
|
||||
lambda u: UserDTO(
|
||||
u.id,
|
||||
u.discord_id,
|
||||
u.xp,
|
||||
u.server,
|
||||
cls._is_technician(u),
|
||||
cls._is_admin(u),
|
||||
cls._is_moderator(u),
|
||||
)
|
||||
),
|
||||
),
|
||||
db.created_at,
|
||||
db.modified_at,
|
||||
)
|
||||
|
@ -15,8 +15,8 @@ class ServerTransformer(TransformerABC):
|
||||
@staticmethod
|
||||
def to_dto(db: Server, name: str, member_count: int, icon_url: Optional[discord.Asset]) -> ServerDTO:
|
||||
return ServerDTO(
|
||||
db.server_id,
|
||||
db.discord_server_id,
|
||||
db.id,
|
||||
db.discord_id,
|
||||
name,
|
||||
member_count,
|
||||
icon_url.url if icon_url is not None else None,
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-core",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1.post1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -10,12 +10,12 @@ class FeatureFlagsEnum(Enum):
|
||||
boot_log_module = "BootLogModule"
|
||||
core_module = "CoreModule"
|
||||
core_extension_module = "CoreExtensionModule"
|
||||
data_module = ("DataModule",)
|
||||
database_module = ("DatabaseModule",)
|
||||
data_module = "DataModule"
|
||||
database_module = "DatabaseModule"
|
||||
level_module = "LevelModule"
|
||||
moderator_module = "ModeratorModule"
|
||||
permission_module = "PermissionModule"
|
||||
stats_module = "StatsModule"
|
||||
# features
|
||||
api_only = "ApiOnly"
|
||||
presence = "Presence"
|
||||
version_in_presence = "VersionInPresence"
|
||||
|
@ -1,5 +1,4 @@
|
||||
import traceback
|
||||
from typing import Optional, Callable
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
@ -24,10 +23,10 @@ class FeatureFlagsSettings(ConfigurationModelABC):
|
||||
FeatureFlagsEnum.database_module.value: True, # 02.10.2022 #48
|
||||
FeatureFlagsEnum.moderator_module.value: False, # 02.10.2022 #48
|
||||
FeatureFlagsEnum.permission_module.value: True, # 02.10.2022 #48
|
||||
FeatureFlagsEnum.stats_module.value: True, # 08.11.2022 #46
|
||||
# features
|
||||
FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70
|
||||
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
|
||||
FeatureFlagsEnum.version_in_presence.value: False, # 21.03.2023 #253
|
||||
}
|
||||
|
||||
def get_flag(self, key: FeatureFlagsEnum) -> bool:
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.core_extension"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.events"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.exception"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.helper"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.logging"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.pipes"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -60,28 +60,28 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
def received_command(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.received_command_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def moved_user(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.moved_users_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def moved_users(self, guild_id: int, count: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.moved_users_count += count
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def get_client(self, dc_ic: int, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
return client
|
||||
|
||||
async def check_if_bot_is_ready_yet(self) -> bool:
|
||||
@ -111,7 +111,11 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
import bot
|
||||
|
||||
name = self._t.transform(t_key).format(bot.__version__)
|
||||
if self._feature_flags.get_flag(FeatureFlagsEnum.version_in_presence):
|
||||
name = f"{bot.__version__} {self._t.transform(t_key)}"
|
||||
else:
|
||||
name = self._t.transform(t_key)
|
||||
|
||||
await self._bot.change_presence(activity=discord.Game(name=name))
|
||||
self._logger.info(__name__, f"Set presence {name}")
|
||||
|
||||
@ -138,7 +142,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
) -> bool:
|
||||
umcph = None
|
||||
try:
|
||||
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.user_id, created_at)
|
||||
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||
if umcph is None:
|
||||
self._umcphs.add_user_message_count_per_hour(
|
||||
UserMessageCountPerHour(
|
||||
@ -151,7 +155,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
self._db.save_changes()
|
||||
|
||||
umcph = self._umcphs.get_user_message_count_per_hour_by_user_id_and_date(user.user_id, created_at)
|
||||
umcph = self._umcphs.get_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||
except Exception as e:
|
||||
self._logger.error(
|
||||
__name__,
|
||||
@ -183,7 +187,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
def get_ontime_for_user(self, user: User) -> float:
|
||||
return round(
|
||||
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.user_id)
|
||||
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.id)
|
||||
.where(lambda x: x.leaved_on is not None and x.joined_on is not None)
|
||||
.sum(lambda join: (join.leaved_on - join.joined_on).total_seconds() / 3600),
|
||||
2,
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
39
kdb-bot/src/bot_data/abc/api_key_repository_abc.py
Normal file
39
kdb-bot/src/bot_data/abc/api_key_repository_abc.py
Normal file
@ -0,0 +1,39 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.api_key import ApiKey
|
||||
|
||||
|
||||
class ApiKeyRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_keys(self) -> List[ApiKey]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_key(self, identifier: str, key: str) -> ApiKey:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_key_by_id(self, id: int) -> ApiKey:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_api_key_by_key(self, key: str) -> ApiKey:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_api_key(self, api_key: ApiKey):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_api_key(self, api_key: ApiKey):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_api_key(self, api_key: ApiKey):
|
||||
pass
|
@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.client import Client
|
||||
|
||||
|
||||
@ -22,6 +23,10 @@ class ClientRepositoryABC(ABC):
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_clients_by_server_id(self, server_id: int) -> List[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
||||
pass
|
||||
|
39
kdb-bot/src/bot_data/abc/game_server_repository_abc.py
Normal file
39
kdb-bot/src/bot_data/abc/game_server_repository_abc.py
Normal file
@ -0,0 +1,39 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.game_server import GameServer
|
||||
|
||||
|
||||
class GameServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_servers(self) -> List[GameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_server_by_id(self, id: int) -> GameServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_servers_by_server_id(self, id: int) -> List[GameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_game_server_by_api_key_id(self, id: int) -> GameServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_game_server(self, game_server: GameServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_game_server(self, game_server: GameServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_game_server(self, game_server: GameServer):
|
||||
pass
|
27
kdb-bot/src/bot_data/abc/history_table_abc.py
Normal file
27
kdb-bot/src/bot_data/abc/history_table_abc.py
Normal file
@ -0,0 +1,27 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class HistoryTableABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self._id = 0
|
||||
self._deleted = False
|
||||
self._date_from = datetime.now().isoformat()
|
||||
self._date_to = datetime.now().isoformat()
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def deleted(self) -> bool:
|
||||
return self._deleted
|
||||
|
||||
@property
|
||||
def date_from(self) -> str:
|
||||
return self._date_from
|
||||
|
||||
@property
|
||||
def date_to(self) -> str:
|
||||
return self._date_to
|
@ -3,6 +3,7 @@ from abc import ABC, abstractmethod
|
||||
|
||||
class MigrationABC(ABC):
|
||||
name = None
|
||||
prio = 0
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
|
@ -1,44 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.statistic import Statistic
|
||||
|
||||
|
||||
class StatisticRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistics(self) -> List[Statistic]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistics_by_server_id(self, server_id: int) -> List[Statistic]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistic_by_id(self, id: int) -> Statistic:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_statistic_by_name(self, name: str, server_id: int) -> Statistic:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_statistic_by_name(self, name: str, server_id: int) -> Optional[Statistic]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_statistic(self, statistic: Statistic):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_statistic(self, statistic: Statistic):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_statistic(self, statistic: Statistic):
|
||||
pass
|
15
kdb-bot/src/bot_data/abc/table_with_id_abc.py
Normal file
15
kdb-bot/src/bot_data/abc/table_with_id_abc.py
Normal file
@ -0,0 +1,15 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class TableWithIdABC(TableABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self.__init__()
|
||||
|
||||
self._id = 0
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
47
kdb-bot/src/bot_data/abc/user_game_ident_repository_abc.py
Normal file
47
kdb-bot/src/bot_data/abc/user_game_ident_repository_abc.py
Normal file
@ -0,0 +1,47 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_game_ident import UserGameIdent
|
||||
|
||||
|
||||
class UserGameIdentRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_idents(self) -> List[UserGameIdent]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_ident_by_ident(self, ident: str) -> UserGameIdent:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_game_ident_by_ident(self, ident: str) -> UserGameIdent:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_game_idents_by_user_id(self, user_id: int) -> List[UserGameIdent]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_game_ident(self, user_game_ident: UserGameIdent):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_game_ident(self, user_game_ident: UserGameIdent):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_game_ident(self, user_game_ident: UserGameIdent):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_game_ident_by_user_id(self, user_id: int):
|
||||
pass
|
@ -0,0 +1,52 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_joined_game_server import UserJoinedGameServer
|
||||
|
||||
|
||||
class UserJoinedGameServerRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_game_servers(self) -> List[UserJoinedGameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_game_server_by_id(self, id: int) -> UserJoinedGameServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_game_servers_by_user_id(self, user_id: int) -> List[UserJoinedGameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_active_user_joined_game_server_by_user_id(self, user_id: int) -> UserJoinedGameServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_game_server_by_user_id(self, user_id: int) -> Optional[UserJoinedGameServer]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_game_servers_by_user_id(self, user_id: int) -> List[Optional[UserJoinedGameServer]]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_joined_game_server(self, user_joined_game_server: UserJoinedGameServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_joined_game_server(self, user_joined_game_server: UserJoinedGameServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_game_server(self, user_joined_game_server: UserJoinedGameServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_game_server_by_user_id(self, user_id: int):
|
||||
pass
|
@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_joined_server import UserJoinedServer
|
||||
|
||||
|
||||
@ -18,6 +19,10 @@ class UserJoinedServerRepositoryABC(ABC):
|
||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_server_by_server_id(self, server_id: int) -> UserJoinedServer:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> list[UserJoinedServer]:
|
||||
pass
|
||||
|
@ -27,6 +27,10 @@ class UserRepositoryABC(ABC):
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
||||
pass
|
||||
|
35
kdb-bot/src/bot_data/abc/user_warnings_repository_abc.py
Normal file
35
kdb-bot/src/bot_data/abc/user_warnings_repository_abc.py
Normal file
@ -0,0 +1,35 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.user_warnings import UserWarnings
|
||||
|
||||
|
||||
class UserWarningsRepositoryABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_warnings(self) -> List[UserWarnings]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_warnings_by_id(self, id: int) -> UserWarnings:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_warnings_by_user_id(self, user_id: int) -> List[UserWarnings]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_warnings(self, user_warnings: UserWarnings):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_warnings(self, user_warnings: UserWarnings):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_warnings(self, user_warnings: UserWarnings):
|
||||
pass
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-data",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1.post1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@ -5,13 +5,16 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
||||
|
||||
from bot_core.abc.module_abc import ModuleABC
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
|
||||
from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC
|
||||
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import (
|
||||
UserJoinedVoiceChannelRepositoryABC,
|
||||
@ -20,14 +23,18 @@ from bot_data.abc.user_message_count_per_hour_repository_abc import (
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
)
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.service.api_key_repository_service import ApiKeyRepositoryService
|
||||
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
||||
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||
from bot_data.service.client_repository_service import ClientRepositoryService
|
||||
from bot_data.service.game_server_repository_service import GameServerRepositoryService
|
||||
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
||||
from bot_data.service.level_repository_service import LevelRepositoryService
|
||||
from bot_data.service.seeder_service import SeederService
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
from bot_data.service.statistic_repository_service import StatisticRepositoryService
|
||||
from bot_data.service.user_game_ident_repository_service import UserGameIdentRepositoryService
|
||||
from bot_data.service.user_joined_game_server_repository_service import UserJoinedGameServerRepositoryService
|
||||
from bot_data.service.user_joined_server_repository_service import (
|
||||
UserJoinedServerRepositoryService,
|
||||
)
|
||||
@ -38,6 +45,7 @@ from bot_data.service.user_message_count_per_hour_repository_service import (
|
||||
UserMessageCountPerHourRepositoryService,
|
||||
)
|
||||
from bot_data.service.user_repository_service import UserRepositoryService
|
||||
from bot_data.service.user_warnings_repository_service import UserWarningsRepositoryService
|
||||
|
||||
|
||||
class DataModule(ModuleABC):
|
||||
@ -48,6 +56,7 @@ class DataModule(ModuleABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_transient(ApiKeyRepositoryABC, ApiKeyRepositoryService)
|
||||
services.add_transient(AuthUserRepositoryABC, AuthUserRepositoryService)
|
||||
services.add_transient(ServerRepositoryABC, ServerRepositoryService)
|
||||
services.add_transient(UserRepositoryABC, UserRepositoryService)
|
||||
@ -55,12 +64,15 @@ class DataModule(ModuleABC):
|
||||
services.add_transient(KnownUserRepositoryABC, KnownUserRepositoryService)
|
||||
services.add_transient(UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService)
|
||||
services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService)
|
||||
services.add_transient(UserJoinedGameServerRepositoryABC, UserJoinedGameServerRepositoryService)
|
||||
services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService)
|
||||
services.add_transient(LevelRepositoryABC, LevelRepositoryService)
|
||||
services.add_transient(StatisticRepositoryABC, StatisticRepositoryService)
|
||||
services.add_transient(UserWarningsRepositoryABC, UserWarningsRepositoryService)
|
||||
services.add_transient(
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
UserMessageCountPerHourRepositoryService,
|
||||
)
|
||||
services.add_transient(GameServerRepositoryABC, GameServerRepositoryService)
|
||||
services.add_transient(UserGameIdentRepositoryABC, UserGameIdentRepositoryService)
|
||||
|
||||
services.add_transient(SeederService)
|
||||
|
@ -6,7 +6,6 @@ from bot_core.logging.database_logger import DatabaseLogger
|
||||
|
||||
class DBContext(DatabaseContext):
|
||||
def __init__(self, logger: DatabaseLogger):
|
||||
|
||||
self._logger = logger
|
||||
|
||||
DatabaseContext.__init__(self)
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.migration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
38
kdb-bot/src/bot_data/migration/api_key_migration.py
Normal file
38
kdb-bot/src/bot_data/migration/api_key_migration.py
Normal file
@ -0,0 +1,38 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ApiKeyMigration(MigrationABC):
|
||||
name = "1.0.0_ApiKeyMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `ApiKeys` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Identifier` VARCHAR(255) NOT NULL,
|
||||
`Key` VARCHAR(255) NOT NULL,
|
||||
`CreatorId` BIGINT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`CreatorId`) REFERENCES `Users`(`UserId`),
|
||||
CONSTRAINT UC_Identifier_Key UNIQUE (`Identifier`,`Key`),
|
||||
CONSTRAINT UC_Key UNIQUE (`Key`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `ApiKeys`;")
|
@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class AutoRoleFix1Migration(MigrationABC):
|
||||
name = "0.3.0_AutoRoleMigration"
|
||||
name = "0.3.0_AutoRoleFixMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
|
65
kdb-bot/src/bot_data/migration/db_history_migration.py
Normal file
65
kdb-bot/src/bot_data/migration/db_history_migration.py
Normal file
@ -0,0 +1,65 @@
|
||||
import os
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class DBHistoryMigration(MigrationABC):
|
||||
name = "1.0.0_DBHistoryMigration"
|
||||
prio = 1
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
def _exec(self, file: str):
|
||||
path = f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts"
|
||||
sql = open(f"{path}/{file}").read()
|
||||
|
||||
for statement in sql.split("\n\n"):
|
||||
self._cursor.execute(statement + ";")
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._exec("api_keys.sql")
|
||||
self._exec("auth_users.sql")
|
||||
self._exec("auth_user_users_relation.sql")
|
||||
self._exec("auto_role_rules.sql")
|
||||
self._exec("auto_roles.sql")
|
||||
self._exec("clients.sql")
|
||||
self._exec("game_servers.sql")
|
||||
self._exec("known_users.sql")
|
||||
self._exec("levels.sql")
|
||||
self._exec("servers.sql")
|
||||
self._exec("user_game_idents.sql")
|
||||
self._exec("user_joined_game_servers.sql")
|
||||
self._exec("user_joined_servers.sql")
|
||||
self._exec("user_joined_voice_channel.sql")
|
||||
self._exec("user_message_count_per_hour.sql")
|
||||
self._exec("users.sql")
|
||||
self._exec("user_warnings.sql")
|
||||
|
||||
self._logger.debug(__name__, "Finished history upgrade")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `ApiKeysHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUserUsersRelationsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRoleRulesHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRolesHistory`;")
|
||||
self._cursor.execute("DROP TABLE `ClientsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `GameServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `KnownUsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `LevelsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `ServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserGameIdentsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedGameServerHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedVoiceChannelHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserMessageCountPerHourHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserWarningsHistory`;")
|
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `ApiKeys`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `ApiKeys`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ApiKeysHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Identifier` VARCHAR(255) NOT NULL,
|
||||
`Key` VARCHAR(255) NOT NULL,
|
||||
`CreatorId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ApiKeysUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ApiKeysUpdate`
|
||||
AFTER UPDATE
|
||||
ON `ApiKeys`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ApiKeysHistory` (
|
||||
`Id`, `Identifier`, `Key`, `CreatorId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Identifier, OLD.Key, OLD.CreatorId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ApiKeysDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ApiKeysDelete`
|
||||
AFTER DELETE
|
||||
ON `ApiKeys`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ApiKeysHistory` (
|
||||
`Id`, `Identifier`, `Key`, `CreatorId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Identifier, OLD.Key, OLD.CreatorId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `AuthUserUsersRelations`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AuthUserUsersRelations`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AuthUserUsersRelationsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`AuthUserId` BIGINT(20) DEFAULT NULL,
|
||||
`UserId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUserUsersRelationsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUserUsersRelationsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AuthUserUsersRelations`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUserUsersRelationsHistory` (
|
||||
`Id`, `AuthUserId`, `UserId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.AuthUserId, OLD.UserId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUserUsersRelationsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUserUsersRelationsDelete`
|
||||
AFTER DELETE
|
||||
ON `AuthUserUsersRelations`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUserUsersRelationsHistory` (
|
||||
`Id`, `AuthUserId`, `UserId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.AuthUserId, OLD.UserId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,62 @@
|
||||
ALTER TABLE `AuthUsers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AuthUsers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AuthUsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`FirstName` VARCHAR(255) DEFAULT NULL,
|
||||
`LastName` VARCHAR(255) DEFAULT NULL,
|
||||
`EMail` VARCHAR(255) DEFAULT NULL,
|
||||
`Password` VARCHAR(255) DEFAULT NULL,
|
||||
`PasswordSalt` VARCHAR(255) DEFAULT NULL,
|
||||
`RefreshToken` VARCHAR(255) DEFAULT NULL,
|
||||
`ConfirmationId` VARCHAR(255) DEFAULT NULL,
|
||||
`ForgotPasswordId` VARCHAR(255) DEFAULT NULL,
|
||||
`OAuthId` VARCHAR(255) DEFAULT NULL,
|
||||
`RefreshTokenExpiryTime` DATETIME(6) NOT NULL,
|
||||
`AuthRole` BIGINT(11) NOT NULL DEFAULT 0,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AuthUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUsersHistory` (
|
||||
`Id`, `FirstName`, `LastName`, `EMail`, `Password`, `PasswordSalt`,
|
||||
`RefreshToken`, `ConfirmationId`, `ForgotPasswordId`, `OAuthId`,
|
||||
`RefreshTokenExpiryTime`, `AuthRole`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.FirstName, OLD.LastName, OLD.EMail, OLD.Password, OLD.PasswordSalt, OLD.RefreshToken,
|
||||
OLD.ConfirmationId, OLD.ForgotPasswordId, OLD.OAuthId, OLD.RefreshTokenExpiryTime, OLD.AuthRole,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUsersDelete`
|
||||
AFTER DELETE
|
||||
ON `AuthUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUsersHistory` (
|
||||
`Id`, `FirstName`, `LastName`, `EMail`, `Password`, `PasswordSalt`, `RefreshToken`,
|
||||
`ConfirmationId`, `ForgotPasswordId`, `OAuthId`, `RefreshTokenExpiryTime`,
|
||||
`AuthRole`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.FirstName, OLD.LastName, OLD.EMail, OLD.Password, OLD.PasswordSalt, OLD.RefreshToken,
|
||||
OLD.ConfirmationId, OLD.ForgotPasswordId, OLD.OAuthId, OLD.RefreshTokenExpiryTime, OLD.AuthRole, TRUE,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `AutoRoleRules`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AutoRoleRules`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AutoRoleRulesHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`AutoRoleId` BIGINT(20) DEFAULT NULL,
|
||||
`DiscordEmojiName` VARCHAR(64) DEFAULT NULL,
|
||||
`DiscordRoleId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRoleRulesUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRoleRulesUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AutoRoleRules`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRoleRulesHistory` (
|
||||
`Id`, `AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleRuleId, OLD.AutoRoleId, OLD.DiscordEmojiName, OLD.DiscordRoleId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRoleRulesDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRoleRulesDelete`
|
||||
AFTER DELETE
|
||||
ON `AutoRoleRules`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRoleRulesHistory` (
|
||||
`Id`, `AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleRuleId, OLD.AutoRoleId, OLD.DiscordEmojiName, OLD.DiscordRoleId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,48 @@
|
||||
ALTER TABLE `AutoRoles`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AutoRoles`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AutoRolesHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`DiscordChannelId` BIGINT(20) NOT NULL,
|
||||
`DiscordMessageId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRolesUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRolesUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AutoRoles`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRolesHistory` (
|
||||
`Id`, `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleId, OLD.ServerId, OLD.DiscordChannelId, OLD.DiscordMessageId, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRolesDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRolesDelete`
|
||||
AFTER DELETE
|
||||
ON `AutoRoles`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRolesHistory` (
|
||||
`Id`, `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleId, OLD.ServerId, OLD.DiscordChannelId, OLD.DiscordMessageId, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,54 @@
|
||||
ALTER TABLE `Clients`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Clients`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ClientsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`SentMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ReceivedMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`DeletedMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ReceivedCommandsCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`MovedUsersCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ClientsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ClientsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Clients`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ClientsHistory` (
|
||||
`Id`, `DiscordId`, `SentMessageCount`, `ReceivedMessageCount`, `DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`, `MovedUsersCount`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ClientId, OLD.DiscordClientId, OLD.SentMessageCount, OLD.ReceivedMessageCount, OLD.DeletedMessageCount,
|
||||
OLD.ReceivedCommandsCount, OLD.MovedUsersCount, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ClientsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ClientsDelete`
|
||||
AFTER DELETE
|
||||
ON `Clients`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ClientsHistory` (
|
||||
`Id`, `DiscordId`, `SentMessageCount`, `ReceivedMessageCount`, `DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`, `MovedUsersCount`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ClientId, OLD.DiscordClientId, OLD.SentMessageCount, OLD.ReceivedMessageCount, OLD.DeletedMessageCount,
|
||||
OLD.ReceivedCommandsCount, OLD.MovedUsersCount, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `GameServers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `GameServers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `GameServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`ServerId` BIGINT(20) NOT NULL,
|
||||
`ApiKeyId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_GameServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_GameServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `GameServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `GameServersHistory` (
|
||||
`Id`, `Name`, `ServerId`, `ApiKeyId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.ServerId, OLD.ApiKeyId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_GameServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_GameServersDelete`
|
||||
AFTER DELETE
|
||||
ON `GameServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `GameServersHistory` (
|
||||
`Id`, `Name`, `ServerId`, `ApiKeyId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.ServerId, OLD.ApiKeyId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,44 @@
|
||||
ALTER TABLE `KnownUsers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `KnownUsers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `KnownUsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_KnownUsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_KnownUsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `KnownUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `KnownUsersHistory` (
|
||||
`Id`, `DiscordId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.KnownUserId, OLD.DiscordId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_KnownUsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_KnownUsersDelete`
|
||||
AFTER DELETE
|
||||
ON `KnownUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `KnownUsersHistory` (
|
||||
`Id`, `DiscordId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.KnownUserId, OLD.DiscordId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
50
kdb-bot/src/bot_data/migration/db_history_scripts/levels.sql
Normal file
50
kdb-bot/src/bot_data/migration/db_history_scripts/levels.sql
Normal file
@ -0,0 +1,50 @@
|
||||
ALTER TABLE `Levels`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Levels`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `LevelsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Color` VARCHAR(8) NOT NULL,
|
||||
`MinXp` BIGINT(20) NOT NULL,
|
||||
`PermissionInt` BIGINT(20) NOT NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_LevelsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_LevelsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Levels`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `LevelsHistory` (
|
||||
`Id`, `Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Color, OLD.MinXp, OLD.PermissionInt, OLD.ServerId, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_LevelsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_LevelsDelete`
|
||||
AFTER DELETE
|
||||
ON `Levels`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `LevelsHistory` (
|
||||
`Id`, `Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Color, OLD.MinXp, OLD.PermissionInt, OLD.ServerId, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,44 @@
|
||||
ALTER TABLE `Servers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Servers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Servers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ServersHistory` (
|
||||
`Id`, `DiscordId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ServerId, OLD.DiscordServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ServersDelete`
|
||||
AFTER DELETE
|
||||
ON `Servers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ServersHistory` (
|
||||
`Id`, `DiscordId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ServerId, OLD.DiscordServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserGameIdents`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserGameIdents`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserGameIdentsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`GameServerId` BIGINT(20) NOT NULL,
|
||||
`Ident` VARCHAR(255) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserGameIdentsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserGameIdentsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserGameIdents`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserGameIdentsHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `Ident`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserGameIdentsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserGameIdentsDelete`
|
||||
AFTER DELETE
|
||||
ON `UserGameIdents`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserGameIdentsHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `Ident`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,47 @@
|
||||
ALTER TABLE `UserJoinedGameServer`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedGameServer`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedGameServerHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`GameServerId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedGameServerUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedGameServer`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedGameServerHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedGameServerDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedGameServer`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedGameServerHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserJoinedServers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedServers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedServersHistory` (
|
||||
`Id`, `UserId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedServersDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedServersHistory` (
|
||||
`Id`, `UserId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,49 @@
|
||||
ALTER TABLE `UserJoinedVoiceChannel`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedVoiceChannel`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedVoiceChannelHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`DiscordChannelId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedVoiceChannelUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedVoiceChannel`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedVoiceChannelHistory` (
|
||||
`Id`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedVoiceChannelDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedVoiceChannel`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedVoiceChannelHistory` (
|
||||
`Id`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,47 @@
|
||||
ALTER TABLE `UserMessageCountPerHour`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserMessageCountPerHour`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserMessageCountPerHourHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Date` DATETIME(6) NOT NULL,
|
||||
`Hour` BIGINT(20) DEFAULT NULL,
|
||||
`XPCount` BIGINT(20) DEFAULT NULL,
|
||||
`UserId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserMessageCountPerHourUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserMessageCountPerHour`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserMessageCountPerHourHistory` (
|
||||
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserMessageCountPerHourDelete`
|
||||
AFTER DELETE
|
||||
ON `UserMessageCountPerHour`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserMessageCountPerHourHistory` (
|
||||
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserWarnings`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserWarnings`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserWarningsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`Author` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserWarningsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserWarningsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserWarnings`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserWarningsHistory` (
|
||||
`Id`, `Description`, `UserId`, `Author`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserWarningsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserWarningsDelete`
|
||||
AFTER DELETE
|
||||
ON `UserWarnings`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserWarningsHistory` (
|
||||
`Id`, `Description`, `UserId`, `Author`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
46
kdb-bot/src/bot_data/migration/db_history_scripts/users.sql
Normal file
46
kdb-bot/src/bot_data/migration/db_history_scripts/users.sql
Normal file
@ -0,0 +1,46 @@
|
||||
ALTER TABLE `Users`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Users`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`XP` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Users`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UsersHistory` (
|
||||
`Id`, `DiscordId`, `XP`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UsersDelete`
|
||||
AFTER DELETE
|
||||
ON `Users`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UsersHistory` (
|
||||
`Id`, `DiscordId`, `XP`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
43
kdb-bot/src/bot_data/migration/remove_stats_migration.py
Normal file
43
kdb-bot/src/bot_data/migration/remove_stats_migration.py
Normal file
@ -0,0 +1,43 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class RemoveStatsMigration(MigrationABC):
|
||||
name = "1.0.0_RemoveStatsMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
DROP TABLE IF EXISTS `Statistics`;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Statistics` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`Code` LONGTEXT NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
@ -0,0 +1,77 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserJoinedGameServerMigration(MigrationABC):
|
||||
name = "1.0.0_UserJoinedGameServerMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `GameServers` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`ServerId` BIGINT NOT NULL,
|
||||
`ApiKeyId` BIGINT NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`),
|
||||
FOREIGN KEY (`ApiKeyId`) REFERENCES ApiKeys(`Id`),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedGameServer` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`GameServerId` BIGINT NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6),
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`UserId`) REFERENCES Users(`UserId`),
|
||||
FOREIGN KEY (`GameServerId`) REFERENCES GameServers(`Id`),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserGameIdents` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`GameServerId` BIGINT NOT NULL,
|
||||
`Ident` VARCHAR(255) NOT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
FOREIGN KEY (`UserId`) REFERENCES Users(`UserId`),
|
||||
FOREIGN KEY (`GameServerId`) REFERENCES GameServers(`Id`),
|
||||
CONSTRAINT UC_UserGameIdent UNIQUE (`GameServerId`,`Ident`),
|
||||
PRIMARY KEY(`Id`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `GameServers`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedGameServer`;")
|
||||
self._cursor.execute("DROP TABLE `UserGameIdents`;")
|
37
kdb-bot/src/bot_data/migration/user_warning_migration.py
Normal file
37
kdb-bot/src/bot_data/migration/user_warning_migration.py
Normal file
@ -0,0 +1,37 @@
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserWarningMigration(MigrationABC):
|
||||
name = "1.0.0_UserWarningMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `UserWarnings` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`UserId` BIGINT NOT NULL,
|
||||
`Author` BIGINT NULL,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`UserId`) REFERENCES `Users`(`UserId`),
|
||||
FOREIGN KEY (`Author`) REFERENCES `Users`(`UserId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `UserWarnings`;")
|
@ -15,7 +15,7 @@ __title__ = "bot_data.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1.post1"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1.post1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0")
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user