Compare commits
213 Commits
0.3.1
...
54b0086a14
Author | SHA1 | Date | |
---|---|---|---|
54b0086a14 | |||
f404287cc1 | |||
7966ca16e5 | |||
c0e5f0d4b0 | |||
80769a1bf0 | |||
bc92dc4536 | |||
16ef29999c | |||
33279b7053 | |||
04fcfddbd9 | |||
21f0f32322 | |||
d1420d18c0 | |||
22d26bf032 | |||
a701807831 | |||
3324cf3ac3 | |||
1664c67763 | |||
bddcd3929a | |||
23e17c1f38 | |||
883811d156 | |||
4d0e8898fe | |||
505c87b996 | |||
18fe6ecb86 | |||
f02268c1a1 | |||
1b328dc20e | |||
34c362a391 | |||
15dfc3f47c | |||
91b2cf7546 | |||
a8dad6b223 | |||
124209c371 | |||
d24c8e40de | |||
54004d10a5 | |||
a510cf731f | |||
23b7e4f59c | |||
24f90657e1 | |||
454fabb3e3 | |||
a588f8bf72 | |||
d75503569e | |||
5b265488df | |||
2d995544c3 | |||
e5fb9fd504 | |||
a80bbc33cf | |||
6915515932 | |||
42b71525bd | |||
2674af64e9 | |||
1eb625fe7a | |||
19f47a01e5 | |||
8ff21debf0 | |||
89bcb655d2 | |||
b9d33c5fd0 | |||
9ea1b14852 | |||
2763f254af | |||
f7dc8d135a | |||
d42b76ba87 | |||
0f26db3d74 | |||
d9d3f8c8b0 | |||
23ee963d65 | |||
f3024d2ea5 | |||
|
e463b19a73 | ||
15214b1c99 | |||
|
dfcd958965 | ||
9274be6bb7 | |||
ac1affa937 | |||
4e722d9c47 | |||
6585576266 | |||
8937243725 | |||
c841f39a03 | |||
a3fa7cb7b9 | |||
f38b517b98 | |||
7d450a12ac | |||
0ea1edff4d | |||
70775111c5 | |||
f42f2086e7 | |||
1f3b12501b | |||
c0882a8ad3 | |||
75ab159539 | |||
ec9bc80392 | |||
02d04725bd | |||
10d79f8c2c | |||
a2dcbbc465 | |||
81fe7433bd | |||
ed5564dc7c | |||
e0ca057399 | |||
8f95e196ec | |||
16b2deec6b | |||
85e664e642 | |||
64985f5983 | |||
|
02ed6eb75b | ||
|
b615f2608f | ||
|
bf776177d4 | ||
|
a2a0056873 | ||
|
eb18fdea46 | ||
|
6945cd2eac | ||
ef040f2b91 | |||
ba4ef693da | |||
07f2c4921c | |||
96339ed168 | |||
9667f40730 | |||
5a9ad77761 | |||
e4d1e229eb | |||
299fc65d1f | |||
aa38623633 | |||
fd9d938b8a | |||
efbe6efc20 | |||
da3680a83e | |||
610ce42fa2 | |||
6149825101 | |||
7193e58ba1 | |||
38417bd712 | |||
43b6df2ba3 | |||
7d67b08ce6 | |||
afff27b273 | |||
de8262dae1 | |||
b96288f4a3 | |||
1ca6debc59 | |||
dfe4f28e24 | |||
fea259fa3b | |||
85452c9a74 | |||
f44f77d7e5 | |||
b15bcec20a | |||
ee351ee749 | |||
f847841582 | |||
e2ef4f3bde | |||
3456c5f021 | |||
065e8b0645 | |||
f04a6066a1 | |||
c0d1288aef | |||
c4507d3aa1 | |||
1039a58d4f | |||
ed4d41d424 | |||
645e84a8fa | |||
b9087dccb3 | |||
4bb486f1d5 | |||
8efd0fc993 | |||
6c0b48a941 | |||
77946cb3a8 | |||
5953c82a9b | |||
6bf73fcf91 | |||
3844240930 | |||
efa18944fe | |||
f435d779a7 | |||
cd34d18205 | |||
9e2a0441d3 | |||
898e27550e | |||
60990db88d | |||
ce1cdd4017 | |||
9a8f8a13f6 | |||
667bb708d9 | |||
54cb6cf8a0 | |||
aa16847fbf | |||
2ef4d079ed | |||
bd4e088032 | |||
1e74584e71 | |||
0b5acdea58 | |||
91bbb2f2e9 | |||
dd64435c65 | |||
84937dde0a | |||
ca5744ea39 | |||
f68bd875b5 | |||
429f8b2819 | |||
7fb8b521e4 | |||
936b8e9cb6 | |||
1fa6f44f76 | |||
f04d40ce75 | |||
45a6b49cf5 | |||
4822348e01 | |||
1d1fc8a876 | |||
a6df06f13a | |||
7f14aff1bd | |||
d03ea1d970 | |||
f144564806 | |||
f7c27b77ee | |||
6aca981fd1 | |||
4266db7e35 | |||
667b9fa87e | |||
79837afdfb | |||
8273b2b98e | |||
eaa22efd08 | |||
b33c5dc9bf | |||
e9559dec08 | |||
5d470be583 | |||
1dfe7edcba | |||
af8c2dea60 | |||
23e238b7d5 | |||
fde318b85d | |||
93c60b9176 | |||
12f8f669ed | |||
36fd3c73b9 | |||
3f7cfc47af | |||
eb58c34c4d | |||
e3c0a0dea3 | |||
dbfae8d8a4 | |||
16066864ed | |||
807827e30f | |||
c75cc54d16 | |||
6a1ad1ec9f | |||
8256ebed71 | |||
eb7fce140a | |||
ebcf876457 | |||
5efb1da0b8 | |||
b9e66bba9d | |||
b8484185e9 | |||
552e686aeb | |||
efb772094b | |||
95b9eea236 | |||
b95a951a1b | |||
df42acec26 | |||
44204f5b94 | |||
ce85bb332a | |||
7a836a7f59 | |||
dacb429d9b | |||
77e18027a0 | |||
b13695b018 | |||
75500076a7 | |||
5455a6b359 |
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",
|
||||
"get-version": "tools/get_version/get-version.json",
|
||||
"post-build": "tools/post_build/post-build.json",
|
||||
|
Submodule kdb-bot/docker updated: 6b25cc87fc...22b8bce69b
@@ -15,7 +15,7 @@ __title__ = "bot"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -16,22 +16,24 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core==2022.12.1.post2",
|
||||
"cpl-core==2022.12.1.post3",
|
||||
"cpl-translation==2022.12.1",
|
||||
"cpl-query==2022.12.2.post1",
|
||||
"cpl-discord==2022.12.1.post2",
|
||||
"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",
|
||||
"cpl-discord==2022.12.2"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.12.1.post2"
|
||||
"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"
|
||||
]
|
||||
}
|
||||
|
Submodule kdb-bot/src/bot/config updated: 54b1b3860c...781aa3f6ab
@@ -15,7 +15,7 @@ __title__ = "bot.extension"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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,19 @@ 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.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 +36,7 @@ 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
|
||||
|
@@ -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!"
|
||||
}
|
||||
"already_exists": "auto-role für die Nachricht {} existiert bereits!",
|
||||
"not_found": "Nachricht {} in {} nicht gefunden!"
|
||||
},
|
||||
"remove": {
|
||||
"success": "auto-role {} wurde entfernt :D",
|
||||
"error": {
|
||||
"not_found": "auto-role {} nicht gefunden!"
|
||||
}
|
||||
"success": "auto-role für die Nachricht {} wurde hinzugefügt :D"
|
||||
},
|
||||
"error": {
|
||||
"nothing_found": "Keine auto-role Einträge gefunden."
|
||||
},
|
||||
"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!",
|
||||
"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!"
|
||||
}
|
||||
"auto_role_id": "auto-role Id",
|
||||
"description": "Von auto-role beobachtete Nachrichten:",
|
||||
"message_id": "Nachricht-Id",
|
||||
"title": "Beobachtete Nachrichten:"
|
||||
},
|
||||
"remove": {
|
||||
"success": "Regel für auto-role {} wurde entfernt :D",
|
||||
"error": {
|
||||
"not_found": "Regel für auto-role {} nicht gefunden!"
|
||||
}
|
||||
"not_found": "auto-role {} nicht gefunden!"
|
||||
},
|
||||
"success": "auto-role {} wurde entfernt :D"
|
||||
},
|
||||
"rule": {
|
||||
"add": {
|
||||
"error": {
|
||||
"already_exists": "Regel für auto-role {} existiert bereits!",
|
||||
"emoji_not_found": "Emoji {} für auto-role Regel {} 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!"
|
||||
}
|
||||
}
|
||||
},
|
||||
"moderator": {
|
||||
"purge_message": "Na gut..., ich lösche alle Nachrichten wenns sein muss."
|
||||
"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"
|
||||
}
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"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",
|
||||
"moved_users_count": "Verschobene Benutzer",
|
||||
"modules": "Module"
|
||||
},
|
||||
"footer": ""
|
||||
},
|
||||
"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."
|
||||
},
|
||||
"presence": {
|
||||
"changed": "Presence wurde geändert.",
|
||||
"removed": "Presence wurde entfernt.",
|
||||
"max_char_count_exceeded": "Der Text darf nicht mehr als 128 Zeichen lang sein!"
|
||||
},
|
||||
"user": {
|
||||
"atr": {
|
||||
"id": "Id",
|
||||
"name": "Name",
|
||||
"discord_join": "Discord beigetreten am",
|
||||
"last_join": "Server beigetreten am",
|
||||
"xp": "XP",
|
||||
"ontime": "Ontime",
|
||||
"roles": "Rollen",
|
||||
"joins": "Beitritte",
|
||||
"lefts": "Abgänge",
|
||||
"warnings": "Verwarnungen"
|
||||
},
|
||||
"info": {
|
||||
"footer": ""
|
||||
},
|
||||
"get": {
|
||||
"xp": "{} hat {} xp",
|
||||
"ontime": "{} war insgesamt {} Stunden aktiv in einem Sprachkanal"
|
||||
},
|
||||
"set": {
|
||||
"xp": "{} hat nun {} xp",
|
||||
"game_server": {
|
||||
"error": {
|
||||
"value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(",
|
||||
"type_error": "Der angegebene Wert ist keine Zahl! :("
|
||||
}
|
||||
"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": {
|
||||
"description": "Informationen über mich",
|
||||
"fields": {
|
||||
"deleted_message_count": "Gelöschte Nachrichten",
|
||||
"modules": "Module",
|
||||
"moved_users_count": "Verschobene Benutzer",
|
||||
"ontime": "Ontime",
|
||||
"received_command_count": "Empfangene Befehle",
|
||||
"received_message_count": "Empfangene Nachrichten",
|
||||
"sent_message_count": "Gesendete Nachrichten",
|
||||
"version": "Version"
|
||||
},
|
||||
"footer": "",
|
||||
"title": "Krümelmonster"
|
||||
},
|
||||
"mass_move": {
|
||||
"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.",
|
||||
"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": {
|
||||
"discord_join": "Discord beigetreten am",
|
||||
"id": "Id",
|
||||
"joins": "Beitritte",
|
||||
"last_join": "Server beigetreten am",
|
||||
"lefts": "Abgänge",
|
||||
"name": "Name",
|
||||
"ontime": "Ontime",
|
||||
"roles": "Rollen",
|
||||
"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": ""
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"set": {
|
||||
"error": {
|
||||
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :("
|
||||
}
|
||||
"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": {
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"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 :)",
|
||||
"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/{}"
|
||||
},
|
||||
"forgot_password": {
|
||||
"subject": "Passwort für {} {} zurücksetzen",
|
||||
"message": "Öffne den Link um das Passwort zu ändern:\n{}auth/forgot-password/{}"
|
||||
}
|
||||
"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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
|
Submodule kdb-bot/src/bot_api/config updated: e6046881b5...c712f856eb
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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>")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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,33 @@ 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")
|
||||
|
||||
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)
|
||||
self.add_auth_user(user_dto)
|
||||
added_user = True
|
||||
# raise ServiceException(ServiceErrorCode.InvalidUser, f'User not found')
|
||||
|
||||
db_user = self._auth_users.get_auth_user_by_email(user_dto.email)
|
||||
if db_user.users.count() == 0:
|
||||
self._users.get_users_by_discord_id(dc_id).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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-core",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -15,7 +15,6 @@ class FeatureFlagsEnum(Enum):
|
||||
level_module = "LevelModule"
|
||||
moderator_module = "ModeratorModule"
|
||||
permission_module = "PermissionModule"
|
||||
stats_module = "StatsModule"
|
||||
# features
|
||||
api_only = "ApiOnly"
|
||||
presence = "Presence"
|
||||
|
@@ -24,7 +24,6 @@ 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
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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:
|
||||
@@ -138,7 +138,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 +151,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 +183,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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
@@ -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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
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
|
@@ -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
|
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"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
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_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)
|
||||
|
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_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_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_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"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
116
kdb-bot/src/bot_data/model/api_key.py
Normal file
116
kdb-bot/src/bot_data/model/api_key.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class ApiKey(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
identifier: str,
|
||||
key: str,
|
||||
creator: Optional[User],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._identifier = identifier
|
||||
self._key = key
|
||||
self._creator = creator
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return self._identifier
|
||||
|
||||
@property
|
||||
def key(self) -> str:
|
||||
return self._key
|
||||
|
||||
@property
|
||||
def creator(self) -> Optional[User]:
|
||||
return self._creator
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_string(identifier: str, key: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`
|
||||
WHERE `Identifier` = '{identifier}'
|
||||
AND `Key` = '{key}';
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_key(key: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `ApiKeys`
|
||||
WHERE `Key` = '{key}';
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `ApiKeys` (
|
||||
`Identifier`, `Key`, `CreatorId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
'{self._identifier}',
|
||||
'{self._key}',
|
||||
{"NULL" if self._creator is None else f"'{self._creator.id}'"},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `ApiKeys`
|
||||
SET `Identifier` = '{self._identifier}',
|
||||
`Key` = '{self._key}',
|
||||
`CreatorId` = {"NULL" if self._creator is None else f"'{self._creator.id}'"},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `ApiKeys`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
@@ -2,6 +2,5 @@ from enum import Enum
|
||||
|
||||
|
||||
class AuthRoleEnum(Enum):
|
||||
|
||||
normal = 0
|
||||
admin = 1
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ class AuthUser(TableABC):
|
||||
|
||||
if users is None:
|
||||
self._users = List(User)
|
||||
else:
|
||||
self._users = users
|
||||
|
||||
self._auth_role_id = auth_role
|
||||
|
||||
@@ -228,10 +230,10 @@ class AuthUser(TableABC):
|
||||
'{self._email}',
|
||||
'{self._password}',
|
||||
'{self._password_salt}',
|
||||
'{"NULL" if self._refresh_token is None else self._refresh_token}',
|
||||
'{"NULL" if self._confirmation_id is None else self._confirmation_id}',
|
||||
'{"NULL" if self._forgot_password_id is None else self._forgot_password_id}',
|
||||
'{"NULL" if self._oauth_id is None else self._oauth_id}',
|
||||
{"NULL" if self._refresh_token is None else f"'{self._refresh_token}'"},
|
||||
{"NULL" if self._confirmation_id is None else f"'{self._confirmation_id}'"},
|
||||
{"NULL" if self._forgot_password_id is None else f"'{self._forgot_password_id}'"},
|
||||
{"NULL" if self._oauth_id is None else f"'{self._oauth_id}'"},
|
||||
'{self._refresh_token_expire_time.isoformat()}',
|
||||
{self._auth_role_id.value},
|
||||
'{self._created_at}',
|
||||
@@ -250,10 +252,10 @@ class AuthUser(TableABC):
|
||||
`EMail` = '{self._email}',
|
||||
`Password` = '{self._password}',
|
||||
`PasswordSalt` = '{self._password_salt}',
|
||||
`RefreshToken` = '{"NULL" if self._refresh_token is None else self._refresh_token}',
|
||||
`ConfirmationId` = '{"NULL" if self._confirmation_id is None else self._confirmation_id}',
|
||||
`ForgotPasswordId` = '{"NULL" if self._forgot_password_id is None else self._forgot_password_id}',
|
||||
`OAuthId` = '{"NULL" if self._oauth_id is None else self._oauth_id}',
|
||||
`RefreshToken` = {"NULL" if self._refresh_token is None else f"'{self._refresh_token}'"},
|
||||
`ConfirmationId` = {"NULL" if self._confirmation_id is None else f"'{self._confirmation_id}'"},
|
||||
`ForgotPasswordId` = {"NULL" if self._forgot_password_id is None else f"'{self._forgot_password_id}'"},
|
||||
`OAuthId` = {"NULL" if self._oauth_id is None else f"'{self._oauth_id}'"},
|
||||
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
||||
`AuthRole` = {self._auth_role_id.value},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
|
@@ -71,7 +71,7 @@ class AuthUserUsersRelation(TableABC):
|
||||
`AuthUserId`, `UserId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._auth_user.id},
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
@@ -84,10 +84,10 @@ class AuthUserUsersRelation(TableABC):
|
||||
f"""
|
||||
UPDATE `AuthUserUsersRelations`
|
||||
SET `AuthUserId` = '{self._auth_user.id}',,
|
||||
`UserId` = '{self._user.user_id}'
|
||||
`UserId` = '{self._user.id}'
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -97,6 +97,6 @@ class AuthUserUsersRelation(TableABC):
|
||||
f"""
|
||||
DELETE FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
@@ -2,21 +2,25 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class AutoRole(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
server_id: int,
|
||||
dc_channel_id: int,
|
||||
server: Optional[Server],
|
||||
channel_id: int,
|
||||
dc_message_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._auto_role_id = id
|
||||
self._server_id = server_id
|
||||
self._discord_channel_id = dc_channel_id
|
||||
self._server = server
|
||||
self._discord_channel_id = channel_id
|
||||
self._discord_message_id = dc_message_id
|
||||
|
||||
TableABC.__init__(self)
|
||||
@@ -24,21 +28,35 @@ class AutoRole(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def auto_role_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._auto_role_id
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
return self._server_id
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
def discord_channel_id(self) -> int:
|
||||
return self._discord_channel_id
|
||||
|
||||
@discord_channel_id.setter
|
||||
def discord_channel_id(self, value: int):
|
||||
self._discord_channel_id = value
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def discord_channel_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
channel = bot.get_channel(self.discord_channel_id)
|
||||
return None if channel is None else channel.name
|
||||
|
||||
@property
|
||||
def discord_message_id(self) -> int:
|
||||
return self._discord_message_id
|
||||
|
||||
@discord_message_id.setter
|
||||
def discord_message_id(self, value: int):
|
||||
self._discord_message_id = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
@@ -81,7 +99,7 @@ class AutoRole(TableABC):
|
||||
INSERT INTO `AutoRoles` (
|
||||
`ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._server_id},
|
||||
{self._server.id},
|
||||
{self._discord_channel_id},
|
||||
{self._discord_message_id},
|
||||
'{self._created_at}',
|
||||
@@ -95,7 +113,7 @@ class AutoRole(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoles`
|
||||
SET `ServerId` = {self._server_id},
|
||||
SET `ServerId` = {self._server.id},
|
||||
`DiscordChannelId` = {self._discord_channel_id},
|
||||
`DiscordMessageId` = {self._discord_message_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
|
@@ -1,13 +1,16 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.auto_role import AutoRole
|
||||
|
||||
|
||||
class AutoRoleRule(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
auto_role_id: int,
|
||||
auto_role: AutoRole,
|
||||
discord_emoji_name: str,
|
||||
discord_role_id: int,
|
||||
created_at: datetime = None,
|
||||
@@ -15,7 +18,7 @@ class AutoRoleRule(TableABC):
|
||||
id=0,
|
||||
):
|
||||
self._auto_role_rule_id = id
|
||||
self._auto_role_id = auto_role_id
|
||||
self._auto_role = auto_role
|
||||
self._discord_emoji_name = discord_emoji_name
|
||||
self._discord_role_id = discord_role_id
|
||||
|
||||
@@ -24,21 +27,35 @@ class AutoRoleRule(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def auto_role_rule_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._auto_role_rule_id
|
||||
|
||||
@property
|
||||
def auto_role_id(self) -> int:
|
||||
return self._auto_role_id
|
||||
def auto_role(self) -> AutoRole:
|
||||
return self._auto_role
|
||||
|
||||
@property
|
||||
def emoji_name(self) -> str:
|
||||
return self._discord_emoji_name
|
||||
|
||||
@emoji_name.setter
|
||||
def emoji_name(self, value: str):
|
||||
self._discord_emoji_name = value
|
||||
|
||||
@property
|
||||
def role_id(self) -> int:
|
||||
return self._discord_role_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def role_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.auto_role.server.discord_id)
|
||||
return guild.get_role(self.role_id).name
|
||||
|
||||
@role_id.setter
|
||||
def role_id(self, value: int):
|
||||
self._discord_role_id = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
@@ -72,7 +89,7 @@ class AutoRoleRule(TableABC):
|
||||
INSERT INTO `AutoRoleRules` (
|
||||
`AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._auto_role_id},
|
||||
{self._auto_role.id},
|
||||
'{self._discord_emoji_name}',
|
||||
{self._discord_role_id},
|
||||
'{self._created_at}',
|
||||
@@ -86,8 +103,8 @@ class AutoRoleRule(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoleRules`
|
||||
SET `AutoRoleId` = {self._auto_role_id},
|
||||
`DiscordEmojiName` = {self._discord_emoji_name},
|
||||
SET `AutoRoleId` = {self._auto_role.id},
|
||||
`DiscordEmojiName` = '{self._discord_emoji_name}',
|
||||
`DiscordRoleId` = {self._discord_role_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
|
@@ -1,5 +1,8 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
@@ -32,13 +35,18 @@ class Client(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def client_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._client_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_client_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
return bot.user.name
|
||||
|
||||
@property
|
||||
def sent_message_count(self) -> int:
|
||||
return self._sent_message_count
|
||||
@@ -154,7 +162,7 @@ class Client(TableABC):
|
||||
{self._deleted_message_count},
|
||||
{self._received_message_count},
|
||||
{self._moved_users_count},
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@@ -1,27 +1,25 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.utils import CredentialManager
|
||||
|
||||
from bot_data.model.api_key import ApiKey
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class Statistic(TableABC):
|
||||
class GameServer(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
description: str,
|
||||
code: str,
|
||||
server: Server,
|
||||
api_key: ApiKey,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._description = description
|
||||
self._code = CredentialManager.encrypt(code)
|
||||
self._server = server
|
||||
self._api_key = api_key
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
@@ -35,31 +33,31 @@ class Statistic(TableABC):
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
@description.setter
|
||||
def description(self, value: str):
|
||||
self._description = value
|
||||
|
||||
@property
|
||||
def code(self) -> str:
|
||||
return CredentialManager.decrypt(self._code)
|
||||
|
||||
@code.setter
|
||||
def code(self, value: str):
|
||||
self._code = CredentialManager.encrypt(value)
|
||||
@name.setter
|
||||
def name(self, value: str):
|
||||
self._name = value
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
||||
|
||||
@server.setter
|
||||
def server(self, value: Server):
|
||||
self._server = value
|
||||
|
||||
@property
|
||||
def api_key(self) -> ApiKey:
|
||||
return self._api_key
|
||||
|
||||
@api_key.setter
|
||||
def api_key(self, value: ApiKey):
|
||||
self._api_key = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`;
|
||||
SELECT * FROM `GameServers`;
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -67,27 +65,35 @@ class Statistic(TableABC):
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_name_string(name: str, s_id: int) -> str:
|
||||
def get_select_by_api_key_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`
|
||||
WHERE `ServerId` = {s_id}
|
||||
AND `Name` = '{name}';
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `ApiKeyId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_string(s_id: int) -> str:
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Statistics`
|
||||
WHERE `ServerId` = {s_id};
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `GameServers`
|
||||
WHERE `UserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -95,13 +101,12 @@ class Statistic(TableABC):
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Statistics` (
|
||||
`Name`, `Description`, `Code`, `ServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
INSERT INTO `GameServers` (
|
||||
`Name`, `ServerId`, `ApiKeyId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
'{self._name}',
|
||||
'{self._description}',
|
||||
'{self._code}',
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
{self._api_key.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
@@ -112,11 +117,8 @@ class Statistic(TableABC):
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Statistics`
|
||||
SET `Name` = '{self._name}',
|
||||
`Description` = '{self._description}',
|
||||
`Code` = '{self._code}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
UPDATE `GameServers`
|
||||
SET `LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
@@ -125,7 +127,16 @@ class Statistic(TableABC):
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `Statistics`
|
||||
DELETE FROM `GameServers`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `GameServers`
|
||||
WHERE `UserId` = {id}
|
||||
"""
|
||||
)
|
@@ -1,8 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class KnownUser(TableABC):
|
||||
@@ -21,7 +19,7 @@ class KnownUser(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def known_user_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._known_user_id
|
||||
|
||||
@property
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
@@ -114,7 +115,7 @@ class Level(TableABC):
|
||||
'{self._color}',
|
||||
{self._min_xp},
|
||||
{self._permissions},
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@@ -1,7 +1,8 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
|
||||
class Server(TableABC):
|
||||
@@ -20,13 +21,25 @@ class Server(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._server_id
|
||||
|
||||
@property
|
||||
def discord_server_id(self) -> int:
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_server_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.name
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def icon_url(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.icon.url
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
|
@@ -1,7 +1,12 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.level import Level
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
@@ -25,13 +30,27 @@ class User(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def user_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._user_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.server.discord_id)
|
||||
user = guild.get_member(self.discord_id)
|
||||
return None if user is None else user.name
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def icon_url(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.server.discord_id)
|
||||
user = guild.get_member(self.discord_id)
|
||||
return None if user is None else user.display_icon
|
||||
|
||||
@property
|
||||
def xp(self) -> int:
|
||||
return self._xp
|
||||
@@ -41,10 +60,48 @@ class User(TableABC):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._xp = value
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def ontime(self, services: ServiceProviderABC) -> float:
|
||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
|
||||
client_utils: ClientUtilsABC = services.get_service(ClientUtilsABC)
|
||||
return client_utils.get_ontime_for_user(self)
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def level(self, services: ServiceProviderABC) -> Level:
|
||||
from modules.level.service.level_service import LevelService
|
||||
|
||||
levels: LevelService = services.get_service(LevelService)
|
||||
return levels.get_level(self)
|
||||
|
||||
@property
|
||||
def server(self) -> Optional[Server]:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def left_server(
|
||||
self,
|
||||
services: ServiceProviderABC,
|
||||
) -> bool:
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
|
||||
ujs: UserJoinedServerRepositoryABC = services.get_service(UserJoinedServerRepositoryABC)
|
||||
return ujs.find_active_user_joined_server_by_user_id(self.id) is None
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def game_idents(
|
||||
self,
|
||||
services: ServiceProviderABC,
|
||||
) -> List["UserGameIdent"]:
|
||||
from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC
|
||||
|
||||
game_idents_repo: UserGameIdentRepositoryABC = services.get_service(UserGameIdentRepositoryABC)
|
||||
return game_idents_repo.get_user_game_idents_by_user_id(self.id)
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
@@ -62,6 +119,15 @@ class User(TableABC):
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(server_id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Users`
|
||||
WHERE `ServerId` = {server_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(
|
||||
@@ -90,7 +156,7 @@ class User(TableABC):
|
||||
) VALUES (
|
||||
{self._discord_id},
|
||||
{self._xp},
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
131
kdb-bot/src/bot_data/model/user_game_ident.py
Normal file
131
kdb-bot/src/bot_data/model/user_game_ident.py
Normal file
@@ -0,0 +1,131 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.game_server import GameServer
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class UserGameIdent(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
user: User,
|
||||
game_server: GameServer,
|
||||
ident: str,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._user = user
|
||||
self._game_server = game_server
|
||||
self._ident = ident
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
return self._user
|
||||
|
||||
@property
|
||||
def game_server(self) -> GameServer:
|
||||
return self._game_server
|
||||
|
||||
@property
|
||||
def ident(self) -> str:
|
||||
return self._ident
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserGameIdents`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserGameIdents`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_ident_string(ident: str) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserGameIdents`
|
||||
WHERE `Ident` = '{ident}';
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserGameIdents`
|
||||
WHERE `UserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_active_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserGameIdents`
|
||||
WHERE `UserId` = {id}
|
||||
AND `LeavedOn` IS NULL;
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserGameIdents` (
|
||||
`UserId`, `GameServerId`, `Ident`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.id},
|
||||
'{self._game_server.id}',
|
||||
'{self._ident}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserGameIdents`
|
||||
SET `LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserGameIdents`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserGameIdents`
|
||||
WHERE `UserId` = {id}
|
||||
"""
|
||||
)
|
146
kdb-bot/src/bot_data/model/user_joined_game_server.py
Normal file
146
kdb-bot/src/bot_data/model/user_joined_game_server.py
Normal file
@@ -0,0 +1,146 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.game_server import GameServer
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class UserJoinedGameServer(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
user: User,
|
||||
game_server: GameServer,
|
||||
joined_on: datetime,
|
||||
leaved_on: datetime = None,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._user = user
|
||||
self._game_server = game_server
|
||||
self._joined_on = joined_on
|
||||
self._leaved_on = leaved_on
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
return self._user
|
||||
|
||||
@property
|
||||
def game_server(self) -> GameServer:
|
||||
return self._game_server
|
||||
|
||||
@property
|
||||
def time(self) -> float:
|
||||
if self._leaved_on is None or self._joined_on is None:
|
||||
return 0
|
||||
return round((self.leaved_on - self.joined_on).total_seconds() / 3600, 2)
|
||||
|
||||
@property
|
||||
def joined_on(self) -> datetime:
|
||||
return self._joined_on
|
||||
|
||||
@joined_on.setter
|
||||
def joined_on(self, value: datetime):
|
||||
self._modified_at = datetime.now()
|
||||
self.joined_on = value
|
||||
|
||||
@property
|
||||
def leaved_on(self) -> datetime:
|
||||
return self._leaved_on
|
||||
|
||||
@leaved_on.setter
|
||||
def leaved_on(self, value: datetime):
|
||||
self._modified_at = datetime.now()
|
||||
self._leaved_on = value
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedGameServer`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedGameServer`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedGameServer`
|
||||
WHERE `UserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_active_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedGameServer`
|
||||
WHERE `UserId` = {id}
|
||||
AND `LeavedOn` IS NULL;
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedGameServer` (
|
||||
`UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.id},
|
||||
'{self._game_server.id}',
|
||||
'{self._joined_on}',
|
||||
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserJoinedGameServer`
|
||||
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserJoinedGameServer`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def delete_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserJoinedGameServer`
|
||||
WHERE `UserId` = {id}
|
||||
"""
|
||||
)
|
@@ -1,10 +1,8 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class UserJoinedServer(TableABC):
|
||||
@@ -27,7 +25,7 @@ class UserJoinedServer(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._join_id
|
||||
|
||||
@property
|
||||
@@ -69,6 +67,15 @@ class UserJoinedServer(TableABC):
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserJoinedServers`
|
||||
WHERE `ServerId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
@@ -90,28 +97,14 @@ class UserJoinedServer(TableABC):
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
if self._leaved_on is not None:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
else:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._joined_on}',
|
||||
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
@@ -123,9 +116,9 @@ class UserJoinedServer(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserJoinedServers`
|
||||
SET `LeavedOn` = '{self._leaved_on}',
|
||||
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `UserId` = {self._user.user_id};
|
||||
WHERE `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.user import User
|
||||
|
||||
@@ -9,7 +11,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
user: User,
|
||||
dc_channel_id: int,
|
||||
channel_id: int,
|
||||
joined_on: datetime,
|
||||
leaved_on: datetime = None,
|
||||
created_at: datetime = None,
|
||||
@@ -17,7 +19,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
id=0,
|
||||
):
|
||||
self._join_id = id
|
||||
self._dc_channel_id = dc_channel_id
|
||||
self._channel_id = channel_id
|
||||
self._user = user
|
||||
self._joined_on = joined_on
|
||||
self._leaved_on = leaved_on
|
||||
@@ -27,17 +29,28 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._join_id
|
||||
|
||||
@property
|
||||
def dc_channel_id(self) -> int:
|
||||
return self._dc_channel_id
|
||||
def channel_id(self) -> int:
|
||||
return self._channel_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def channel_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
return bot.get_channel(self.channel_id).name
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
return self._user
|
||||
|
||||
@property
|
||||
def time(self) -> float:
|
||||
if self._leaved_on is None or self._joined_on is None:
|
||||
return 0
|
||||
return round((self.leaved_on - self.joined_on).total_seconds() / 3600, 2)
|
||||
|
||||
@property
|
||||
def joined_on(self) -> datetime:
|
||||
return self._joined_on
|
||||
@@ -94,30 +107,15 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
if self._leaved_on is not None:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._dc_channel_id},
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
else:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._dc_channel_id},
|
||||
{self._user.id},
|
||||
{self._channel_id},
|
||||
'{self._joined_on}',
|
||||
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
@@ -129,7 +127,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserJoinedVoiceChannel`
|
||||
SET `LeavedOn` = '{self._leaved_on}',
|
||||
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `JoinId` = {self._join_id};
|
||||
"""
|
||||
|
@@ -97,7 +97,7 @@ class UserMessageCountPerHour(TableABC):
|
||||
INSERT INTO `UserMessageCountPerHour` (
|
||||
`UserId`, `Date`, `Hour`, `XPCount`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._date}',
|
||||
{self._hour},
|
||||
{self._xp_count},
|
||||
|
8
kdb-bot/src/bot_data/model/user_role_enum.py
Normal file
8
kdb-bot/src/bot_data/model/user_role_enum.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class UserRoleEnum(Enum):
|
||||
member = 0
|
||||
moderator = 1
|
||||
admin = 2
|
||||
technician = 3
|
105
kdb-bot/src/bot_data/model/user_warnings.py
Normal file
105
kdb-bot/src/bot_data/model/user_warnings.py
Normal file
@@ -0,0 +1,105 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
# had to name it UserWarnings instead of UserWarning because UserWarning is a builtin class
|
||||
class UserWarnings(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
description: str,
|
||||
user: User,
|
||||
author: Optional[User],
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
id=0,
|
||||
):
|
||||
self._id = id
|
||||
self._description = description
|
||||
self._user = user
|
||||
self._author = author
|
||||
|
||||
TableABC.__init__(self)
|
||||
self._created_at = created_at if created_at is not None else self._created_at
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
return self._user
|
||||
|
||||
@property
|
||||
def author(self) -> Optional[User]:
|
||||
return self._author
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserWarnings`;
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserWarnings`
|
||||
WHERE `Id` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_user_id_string(id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `UserWarnings`
|
||||
WHERE `UserId` = {id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserWarnings` (
|
||||
`Description`, `UserId`, {"" if self._author is None else f"`Author`,"} `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
'{self._description}',
|
||||
{self._user.id},
|
||||
{"" if self._author is None else f"{self._author.id},"}
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserWarnings`
|
||||
SET `Description` = '{self._description}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `UserWarnings`
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
@@ -15,7 +15,7 @@ __title__ = "bot_data.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.0rc1"
|
||||
|
||||
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")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
|
77
kdb-bot/src/bot_data/service/api_key_repository_service.py
Normal file
77
kdb-bot/src/bot_data/service/api_key_repository_service.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.api_key import ApiKey
|
||||
|
||||
|
||||
class ApiKeyRepositoryService(ApiKeyRepositoryABC):
|
||||
def __init__(
|
||||
self,
|
||||
logger: DatabaseLogger,
|
||||
db_context: DatabaseContextABC,
|
||||
users: UserRepositoryABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._context = db_context
|
||||
|
||||
self._users = users
|
||||
|
||||
ApiKeyRepositoryABC.__init__(self)
|
||||
|
||||
@staticmethod
|
||||
def _get_value_from_result(value: any) -> Optional[any]:
|
||||
if isinstance(value, str) and "NULL" in value:
|
||||
return None
|
||||
|
||||
return value
|
||||
|
||||
def _api_key_from_result(self, sql_result: tuple) -> ApiKey:
|
||||
creator = self._get_value_from_result(sql_result[3])
|
||||
api_key = ApiKey(
|
||||
self._get_value_from_result(sql_result[1]),
|
||||
self._get_value_from_result(sql_result[2]),
|
||||
None if creator is None else self._users.get_user_by_id(int(creator)),
|
||||
self._get_value_from_result(sql_result[4]),
|
||||
self._get_value_from_result(sql_result[5]),
|
||||
id=self._get_value_from_result(sql_result[0]),
|
||||
)
|
||||
|
||||
return api_key
|
||||
|
||||
def get_api_keys(self) -> List[ApiKey]:
|
||||
api_keys = List(ApiKey)
|
||||
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_all_string()}")
|
||||
results = self._context.select(ApiKey.get_select_all_string())
|
||||
for result in results:
|
||||
api_keys.append(self._api_key_from_result(result))
|
||||
|
||||
return api_keys
|
||||
|
||||
def get_api_key(self, identifier: str, key: str) -> ApiKey:
|
||||
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_string(identifier, key)}")
|
||||
return self._api_key_from_result(self._context.select(ApiKey.get_select_string(identifier, key))[0])
|
||||
|
||||
def get_api_key_by_id(self, id: int) -> ApiKey:
|
||||
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_by_id(id)}")
|
||||
return self._api_key_from_result(self._context.select(ApiKey.get_select_by_id(id))[0])
|
||||
|
||||
def get_api_key_by_key(self, key: str) -> ApiKey:
|
||||
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_by_key(key)}")
|
||||
return self._api_key_from_result(self._context.select(ApiKey.get_select_by_key(key))[0])
|
||||
|
||||
def add_api_key(self, api_key: ApiKey):
|
||||
self._logger.trace(__name__, f"Send SQL command: {api_key.insert_string}")
|
||||
self._context.cursor.execute(api_key.insert_string)
|
||||
|
||||
def update_api_key(self, api_key: ApiKey):
|
||||
self._logger.trace(__name__, f"Send SQL command: {api_key.udpate_string}")
|
||||
self._context.cursor.execute(api_key.udpate_string)
|
||||
|
||||
def delete_api_key(self, api_key: ApiKey):
|
||||
self._logger.trace(__name__, f"Send SQL command: {api_key.delete_string}")
|
||||
self._context.cursor.execute(api_key.delete_string)
|
@@ -11,7 +11,6 @@ from bot_data.filtered_result import FilteredResult
|
||||
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
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user