Compare commits

...

37 Commits

Author SHA1 Message Date
85e664e642 Removed statistic module #190 2023-02-19 19:46:13 +01:00
64985f5983 Merge pull request 'Client in Webinterface anzeigen #80' (#211) from #80_show_info_of_client into 1.0.0
Reviewed-on: sh-edraft.de/kd_discord_bot#211
Reviewed-by: Sven Heidemann <sven.heidemann@sh-edraft.de>
Closes #80
2023-02-19 18:02:45 +01:00
Jonas Drescher
02ed6eb75b deleted unused comments #80 2023-02-19 18:01:13 +01:00
Jonas Drescher
b615f2608f added translation #80 2023-02-19 17:59:59 +01:00
Jonas Drescher
bf776177d4 added clients to server-dashboard #80 2023-02-19 17:45:50 +01:00
Jonas Drescher
a2a0056873 min = 0 fix on xp inputfield 2023-02-19 14:49:53 +01:00
Jonas Drescher
eb18fdea46 added Jonas to settings 2023-02-19 14:36:07 +01:00
Jonas Drescher
6945cd2eac added Jonas to settings 2023-02-19 14:31:00 +01:00
ef040f2b91 Fixed permission check 2023-02-19 14:25:41 +01:00
ba4ef693da Merge pull request '#130' (#209) from #130 into 1.0.0
Reviewed-on: sh-edraft.de/kd_discord_bot#209
2023-02-19 12:00:14 +01:00
07f2c4921c Merge branch '1.0.0' into #130 2023-02-19 12:00:09 +01:00
96339ed168 Fixed some stuff for deployment #130 2023-02-19 11:59:02 +01:00
9667f40730 Merge pull request 'Set version for stage build #130' (#208) from #130 into 1.0.0
Reviewed-on: sh-edraft.de/kd_discord_bot#208
2023-02-19 11:10:59 +01:00
5a9ad77761 Updated config #130 2023-02-19 11:09:34 +01:00
e4d1e229eb Set version for stage build #130 2023-02-19 10:59:40 +01:00
299fc65d1f Merge pull request 'Set version to build for staging' (#207) from #130 into 1.0.0
Reviewed-on: sh-edraft.de/kd_discord_bot#207
2023-02-19 10:39:45 +01:00
aa38623633 Set version to build for staging 2023-02-19 10:37:56 +01:00
fd9d938b8a Set version to build for staging 2023-02-19 10:29:29 +01:00
efbe6efc20 Merge pull request 'Mitglieder auf einem Server anzeigen #130' (#206) from #130 into 1.0.0
Reviewed-on: sh-edraft.de/kd_discord_bot#206
Reviewed-by: edraft-dev <dev.sven.heidemann@sh-edraft.de>
Closes #130
2023-02-18 14:56:38 +01:00
da3680a83e Improved imports #130 2023-02-18 14:45:51 +01:00
610ce42fa2 Fixed styling & added game server to profile #130 2023-02-18 13:37:03 +01:00
6149825101 Fixed sorting with null values #130 2023-02-18 13:05:45 +01:00
7193e58ba1 Fixed dashboard server filter #130 2023-02-18 12:54:56 +01:00
38417bd712 Fixed auth user confirmed check #130 2023-02-18 12:49:14 +01:00
43b6df2ba3 Improved spinner logic and table design #130 2023-02-18 12:42:51 +01:00
7d67b08ce6 Added leftServer handling to members list #130 2023-02-18 12:14:04 +01:00
afff27b273 Improved db updates #130 2023-02-18 11:44:13 +01:00
de8262dae1 Improved sidebar handling & added minecraftId to profile #130 2023-02-18 11:34:33 +01:00
b96288f4a3 Added member profile #130 2023-02-18 10:44:19 +01:00
1ca6debc59 Fixed server view in sidebar #130 2023-02-18 10:22:31 +01:00
dfe4f28e24 Improved sorting #130 2023-02-18 10:22:31 +01:00
fea259fa3b Renamed type_id to id for sorting #130 2023-02-18 10:22:31 +01:00
85452c9a74 Added members view #130 2023-02-18 10:22:30 +01:00
f44f77d7e5 Improved sidebar #130 2023-02-18 10:20:15 +01:00
b15bcec20a Updated config #130 2023-02-18 10:19:47 +01:00
ee351ee749 Improved routing #130 2023-02-18 10:19:47 +01:00
f847841582 Added routing by permissions #130 2023-02-18 10:19:45 +01:00
223 changed files with 4942 additions and 3968 deletions

View File

@ -15,7 +15,7 @@ __title__ = "bot"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -2,9 +2,9 @@
"ProjectSettings": { "ProjectSettings": {
"Name": "bot", "Name": "bot",
"Version": { "Version": {
"Major": "0", "Major": "1",
"Minor": "3", "Minor": "0",
"Micro": "1" "Micro": "dev130"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -19,7 +19,7 @@
"cpl-core==2022.12.1.post3", "cpl-core==2022.12.1.post3",
"cpl-translation==2022.12.1", "cpl-translation==2022.12.1",
"cpl-query==2022.12.2.post1", "cpl-query==2022.12.2.post1",
"Flask==2.2.2", "Flask==2.2.3",
"Flask-Classful==0.14.2", "Flask-Classful==0.14.2",
"Flask-Cors==3.0.10", "Flask-Cors==3.0.10",
"PyJWT==2.6.0", "PyJWT==2.6.0",
@ -41,15 +41,15 @@
"BuildSettings": { "BuildSettings": {
"ProjectType": "console", "ProjectType": "console",
"SourcePath": "", "SourcePath": "",
"OutputPath": "../../dist", "OutputPath": "..\\..\\dist",
"Main": "bot.main", "Main": "bot.main",
"EntryPoint": "bot", "EntryPoint": "bot",
"IncludePackageData": false, "IncludePackageData": false,
"Included": [], "Included": [],
"Excluded": [ "Excluded": [
"*/__pycache__", "*\\__pycache__",
"*/logs", "*\\logs",
"*/tests" "*\\tests"
], ],
"PackageData": {}, "PackageData": {},
"ProjectReferences": [ "ProjectReferences": [

@ -1 +1 @@
Subproject commit ac7046820f3410f55e779797126d9410c6bcdc9f Subproject commit eff27f42808909a816c37f31d81f085d59d4728c

View File

@ -15,7 +15,7 @@ __title__ = "bot.extension"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -11,7 +11,6 @@ from modules.boot_log.boot_log_module import BootLogModule
from modules.database.database_module import DatabaseModule from modules.database.database_module import DatabaseModule
from modules.level.level_module import LevelModule from modules.level.level_module import LevelModule
from modules.permission.permission_module import PermissionModule from modules.permission.permission_module import PermissionModule
from modules.stats.stats_module import StatsModule
from modules.technician.technician_module import TechnicianModule from modules.technician.technician_module import TechnicianModule
@ -31,7 +30,6 @@ class ModuleList:
BaseModule, BaseModule,
LevelModule, LevelModule,
ApiModule, ApiModule,
StatsModule,
TechnicianModule, TechnicianModule,
# has to be last! # has to be last!
BootLogModule, BootLogModule,

View File

@ -263,30 +263,6 @@
}, },
"database": {}, "database": {},
"permission": {}, "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"
}
},
"technician": { "technician": {
"restart_message": "Bin gleich wieder da :D", "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 :)", "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 :)",

View File

@ -15,7 +15,7 @@ __title__ = "bot_api"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.abc"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -2,9 +2,9 @@
"ProjectSettings": { "ProjectSettings": {
"Name": "bot-api", "Name": "bot-api",
"Version": { "Version": {
"Major": "0", "Major": "1",
"Minor": "3", "Minor": "0",
"Micro": "1" "Micro": "dev130"
}, },
"Author": "", "Author": "",
"AuthorEmail": "", "AuthorEmail": "",

@ -1 +1 @@
Subproject commit 3c2a863022e6656927b9360875695a6bcdc70ac9 Subproject commit c712f856ebe30c71ac0b144045599ed2f91a1cba

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.configuration"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.controller"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.event"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.exception"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.filter"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.filter.discord"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.logging"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.model"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -1,7 +1,10 @@
from datetime import datetime from datetime import datetime
from typing import Optional from typing import Optional
from cpl_query.extension import List
from bot_api.abc.dto_abc import DtoABC 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 from bot_data.model.auth_role_enum import AuthRoleEnum
@ -15,6 +18,7 @@ class AuthUserDTO(DtoABC):
password: str = None, password: str = None,
confirmation_id: Optional[str] = None, confirmation_id: Optional[str] = None,
auth_role: AuthRoleEnum = None, auth_role: AuthRoleEnum = None,
users: List[UserDTO] = None,
created_at: datetime = None, created_at: datetime = None,
modified_at: datetime = None, modified_at: datetime = None,
): ):
@ -30,6 +34,11 @@ class AuthUserDTO(DtoABC):
self._created_at = created_at self._created_at = created_at
self._modified_at = modified_at self._modified_at = modified_at
if users is None:
self._users = List(UserDTO)
else:
self._users = users
@property @property
def id(self) -> int: def id(self) -> int:
return self._id return self._id
@ -82,6 +91,10 @@ class AuthUserDTO(DtoABC):
def auth_role(self, value: AuthRoleEnum): def auth_role(self, value: AuthRoleEnum):
self._auth_role = value self._auth_role = value
@property
def users(self) -> List[UserDTO]:
return self._users
@property @property
def created_at(self) -> datetime: def created_at(self) -> datetime:
return self._created_at return self._created_at
@ -98,6 +111,12 @@ class AuthUserDTO(DtoABC):
self._password = values["password"] self._password = values["password"]
self._is_confirmed = values["isConfirmed"] self._is_confirmed = values["isConfirmed"]
self._auth_role = AuthRoleEnum(values["authRole"]) 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._created_at = values["createdAt"]
self._modified_at = values["modifiedAt"] self._modified_at = values["modifiedAt"]
@ -111,6 +130,7 @@ class AuthUserDTO(DtoABC):
"password": self._password, "password": self._password,
"isConfirmed": self._is_confirmed, "isConfirmed": self._is_confirmed,
"authRole": self._auth_role.value, "authRole": self._auth_role.value,
"users": self._users.select(lambda u: u.to_dict()).to_list(),
"createdAt": self._created_at, "createdAt": self._created_at,
"modifiedAt": self._modified_at, "modifiedAt": self._modified_at,
} }

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.model.discord"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -0,0 +1,88 @@
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,
minecraft_id: Optional[str] = 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._minecraft_id = minecraft_id
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 minecraft_id(self) -> Optional[str]:
return self._minecraft_id
@minecraft_id.setter
def minecraft_id(self, value: str):
self._minecraft_id = 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._minecraft_id = values["minecraftId"]
self._server = values["server"]
def to_dict(self) -> dict:
return {
"id": self._user_id,
"dcId": self._discord_id,
"xp": self._xp,
"minecraftId": self._minecraft_id,
"server": self._server.id,
"isTechnician": self.is_technician,
"isAdmin": self.is_admin,
"isModerator": self.is_moderator,
}

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.route"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.service"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -2,7 +2,6 @@ from typing import Optional
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List from cpl_query.extension import List
from flask import jsonify
from bot_api.abc.auth_service_abc import AuthServiceABC from bot_api.abc.auth_service_abc import AuthServiceABC
from bot_api.exception.service_error_code_enum import ServiceErrorCode 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.filter.discord.server_select_criteria import ServerSelectCriteria
from bot_api.model.discord.server_dto import ServerDTO from bot_api.model.discord.server_dto import ServerDTO
from bot_api.model.discord.server_filtered_result_dto import ServerFilteredResultDTO 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_api.transformer.server_transformer import ServerTransformer
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
@ -35,7 +33,7 @@ class DiscordService:
self._users = users self._users = users
def _to_dto(self, x: Server) -> Optional[ServerDTO]: 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: if guild is None:
return ServerTransformer.to_dto(x, "", 0, None) return ServerTransformer.to_dto(x, "", 0, None)
@ -55,8 +53,8 @@ class DiscordService:
if role != AuthRoleEnum.admin: if role != AuthRoleEnum.admin:
auth_user = self._auth_users.find_auth_user_by_email(token["email"]) auth_user = self._auth_users.find_auth_user_by_email(token["email"])
if auth_user is not None: if auth_user is not None:
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id) user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.id)
servers = servers.where(lambda x: x.server_id in user_ids) servers = servers.where(lambda x: x.id in user_ids)
servers = List(ServerDTO, servers) servers = List(ServerDTO, servers)
return servers.select(self._to_dto).where(lambda x: x.name != "") return servers.select(self._to_dto).where(lambda x: x.name != "")
@ -72,8 +70,8 @@ class DiscordService:
if role != AuthRoleEnum.admin: if role != AuthRoleEnum.admin:
auth_user = self._auth_users.find_auth_user_by_email(token["email"]) auth_user = self._auth_users.find_auth_user_by_email(token["email"])
if auth_user is not None: if auth_user is not None:
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id) 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.server_id in user_ids) 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 != "") servers: List = filtered_result.result.select(self._to_dto).where(lambda x: x.name != "")
result = List(ServerDTO, servers) result = List(ServerDTO, servers)
@ -87,7 +85,7 @@ class DiscordService:
async def get_server_by_id_async(self, id: int) -> ServerDTO: async def get_server_by_id_async(self, id: int) -> ServerDTO:
server = self._servers.get_server_by_id(id) 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) server_dto = ServerTransformer.to_dto(server, guild.name, guild.member_count, guild.icon)
return server_dto return server_dto

View File

@ -15,7 +15,7 @@ __title__ = "bot_api.transformer"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -1,9 +1,16 @@
from datetime import datetime 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.abc.transformer_abc import TransformerABC
from bot_api.model.auth_user_dto import AuthUserDTO 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_role_enum import AuthRoleEnum
from bot_data.model.auth_user import AuthUser 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): class AuthUserTransformer(TransformerABC):
@ -25,7 +32,28 @@ class AuthUserTransformer(TransformerABC):
) )
@staticmethod @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( return AuthUserDTO(
db.id, db.id,
db.first_name, db.first_name,
@ -34,6 +62,21 @@ class AuthUserTransformer(TransformerABC):
"" if password is None else password, "" if password is None else password,
db.confirmation_id, db.confirmation_id,
db.auth_role, db.auth_role,
List(
UserDTO,
db.users.select(
lambda u: UserDTO(
u.id,
u.discord_id,
u.xp,
u.minecraft_id,
u.server,
cls._is_technician(u),
cls._is_admin(u),
cls._is_moderator(u),
)
),
),
db.created_at, db.created_at,
db.modified_at, db.modified_at,
) )

View File

@ -15,8 +15,8 @@ class ServerTransformer(TransformerABC):
@staticmethod @staticmethod
def to_dto(db: Server, name: str, member_count: int, icon_url: Optional[discord.Asset]) -> ServerDTO: def to_dto(db: Server, name: str, member_count: int, icon_url: Optional[discord.Asset]) -> ServerDTO:
return ServerDTO( return ServerDTO(
db.server_id, db.id,
db.discord_server_id, db.discord_id,
name, name,
member_count, member_count,
icon_url.url if icon_url is not None else None, icon_url.url if icon_url is not None else None,

View File

@ -15,7 +15,7 @@ __title__ = "bot_core"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.abc"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -2,9 +2,9 @@
"ProjectSettings": { "ProjectSettings": {
"Name": "bot-core", "Name": "bot-core",
"Version": { "Version": {
"Major": "0", "Major": "1",
"Minor": "3", "Minor": "0",
"Micro": "1" "Micro": "dev130"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.configuration"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.core_extension"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.events"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.exception"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.helper"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.logging"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.pipes"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_core.service"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -60,28 +60,28 @@ class ClientUtilsService(ClientUtilsABC):
def received_command(self, guild_id: int): def received_command(self, guild_id: int):
server = self._servers.get_server_by_discord_id(guild_id) 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 client.received_command_count += 1
self._clients.update_client(client) self._clients.update_client(client)
self._db.save_changes() self._db.save_changes()
def moved_user(self, guild_id: int): def moved_user(self, guild_id: int):
server = self._servers.get_server_by_discord_id(guild_id) 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 client.moved_users_count += 1
self._clients.update_client(client) self._clients.update_client(client)
self._db.save_changes() self._db.save_changes()
def moved_users(self, guild_id: int, count: int): def moved_users(self, guild_id: int, count: int):
server = self._servers.get_server_by_discord_id(guild_id) 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 client.moved_users_count += count
self._clients.update_client(client) self._clients.update_client(client)
self._db.save_changes() self._db.save_changes()
def get_client(self, dc_ic: int, guild_id: int): def get_client(self, dc_ic: int, guild_id: int):
server = self._servers.get_server_by_discord_id(guild_id) 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 return client
async def check_if_bot_is_ready_yet(self) -> bool: async def check_if_bot_is_ready_yet(self) -> bool:
@ -138,7 +138,7 @@ class ClientUtilsService(ClientUtilsABC):
) -> bool: ) -> bool:
umcph = None umcph = None
try: 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: if umcph is None:
self._umcphs.add_user_message_count_per_hour( self._umcphs.add_user_message_count_per_hour(
UserMessageCountPerHour( UserMessageCountPerHour(
@ -151,7 +151,7 @@ class ClientUtilsService(ClientUtilsABC):
self._db.save_changes() 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: except Exception as e:
self._logger.error( self._logger.error(
__name__, __name__,
@ -183,7 +183,7 @@ class ClientUtilsService(ClientUtilsABC):
def get_ontime_for_user(self, user: User) -> float: def get_ontime_for_user(self, user: User) -> float:
return round( 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) .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), .sum(lambda join: (join.leaved_on - join.joined_on).total_seconds() / 3600),
2, 2,

View File

@ -15,7 +15,7 @@ __title__ = "bot_data"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -15,7 +15,7 @@ __title__ = "bot_data.abc"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -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

View File

@ -2,9 +2,9 @@
"ProjectSettings": { "ProjectSettings": {
"Name": "bot-data", "Name": "bot-data",
"Version": { "Version": {
"Major": "0", "Major": "1",
"Minor": "3", "Minor": "0",
"Micro": "1" "Micro": "dev130"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -12,7 +12,6 @@ from bot_data.abc.client_repository_abc import ClientRepositoryABC
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
from bot_data.abc.level_repository_abc import LevelRepositoryABC from bot_data.abc.level_repository_abc import LevelRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC 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_server_repository_abc import UserJoinedServerRepositoryABC
from bot_data.abc.user_joined_voice_channel_repository_abc import ( from bot_data.abc.user_joined_voice_channel_repository_abc import (
@ -30,7 +29,6 @@ from bot_data.service.known_user_repository_service import KnownUserRepositorySe
from bot_data.service.level_repository_service import LevelRepositoryService from bot_data.service.level_repository_service import LevelRepositoryService
from bot_data.service.seeder_service import SeederService from bot_data.service.seeder_service import SeederService
from bot_data.service.server_repository_service import ServerRepositoryService from bot_data.service.server_repository_service import ServerRepositoryService
from bot_data.service.statistic_repository_service import StatisticRepositoryService
from bot_data.service.user_joined_game_server_repository_service import UserJoinedGameServerRepositoryService from bot_data.service.user_joined_game_server_repository_service import UserJoinedGameServerRepositoryService
from bot_data.service.user_joined_server_repository_service import ( from bot_data.service.user_joined_server_repository_service import (
UserJoinedServerRepositoryService, UserJoinedServerRepositoryService,
@ -63,7 +61,6 @@ class DataModule(ModuleABC):
services.add_transient(UserJoinedGameServerRepositoryABC, UserJoinedGameServerRepositoryService) services.add_transient(UserJoinedGameServerRepositoryABC, UserJoinedGameServerRepositoryService)
services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService) services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService)
services.add_transient(LevelRepositoryABC, LevelRepositoryService) services.add_transient(LevelRepositoryABC, LevelRepositoryService)
services.add_transient(StatisticRepositoryABC, StatisticRepositoryService)
services.add_transient( services.add_transient(
UserMessageCountPerHourRepositoryABC, UserMessageCountPerHourRepositoryABC,
UserMessageCountPerHourRepositoryService, UserMessageCountPerHourRepositoryService,

View File

@ -15,7 +15,7 @@ __title__ = "bot_data.migration"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
class StatsMigration(MigrationABC): class StatsMigration(MigrationABC):
name = "0.3_StatsMigration" name = "1.0_RemoveStatsMigration"
def __init__(self, logger: DatabaseLogger, db: DBContext): def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self) MigrationABC.__init__(self)
@ -15,6 +15,15 @@ class StatsMigration(MigrationABC):
def upgrade(self): def upgrade(self):
self._logger.debug(__name__, "Running upgrade") self._logger.debug(__name__, "Running upgrade")
self._cursor.execute(
str(
f"""
DROP TABLE IF EXISTS `Statistics`;
"""
)
)
def downgrade(self):
self._cursor.execute( self._cursor.execute(
str( str(
f""" f"""
@ -32,6 +41,3 @@ class StatsMigration(MigrationABC):
""" """
) )
) )
def downgrade(self):
self._cursor.execute("DROP TABLE `Statistics`;")

View File

@ -15,7 +15,7 @@ __title__ = "bot_data.model"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -73,7 +73,7 @@ class ApiKey(TableABC):
) VALUES ( ) VALUES (
'{self._identifier}', '{self._identifier}',
'{self._key}', '{self._key}',
{"NULL" if self._creator is None else self._creator.user_id}, {"NULL" if self._creator is None else self._creator.id},
'{self._created_at}', '{self._created_at}',
'{self._modified_at}' '{self._modified_at}'
); );

View File

@ -42,6 +42,8 @@ class AuthUser(TableABC):
if users is None: if users is None:
self._users = List(User) self._users = List(User)
else:
self._users = users
self._auth_role_id = auth_role self._auth_role_id = auth_role
@ -250,10 +252,10 @@ class AuthUser(TableABC):
`EMail` = '{self._email}', `EMail` = '{self._email}',
`Password` = '{self._password}', `Password` = '{self._password}',
`PasswordSalt` = '{self._password_salt}', `PasswordSalt` = '{self._password_salt}',
`RefreshToken` = '{"NULL" if self._refresh_token is None else self._refresh_token}', `RefreshToken` = '{'null' if self._refresh_token is None else f'{self._refresh_token}'}',
`ConfirmationId` = '{"NULL" if self._confirmation_id is None else self._confirmation_id}', `ConfirmationId` = '{'null' if self._confirmation_id is None else f'{self._confirmation_id}'}',
`ForgotPasswordId` = '{"NULL" if self._forgot_password_id is None else self._forgot_password_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 self._oauth_id}', `OAuthId` = '{'null' if self._oauth_id is None else f'{self._oauth_id}'}',
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}', `RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
`AuthRole` = {self._auth_role_id.value}, `AuthRole` = {self._auth_role_id.value},
`LastModifiedAt` = '{self._modified_at}' `LastModifiedAt` = '{self._modified_at}'

View File

@ -71,7 +71,7 @@ class AuthUserUsersRelation(TableABC):
`AuthUserId`, `UserId`, `CreatedAt`, `LastModifiedAt` `AuthUserId`, `UserId`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._auth_user.id}, {self._auth_user.id},
{self._user.user_id}, {self._user.id},
'{self._created_at}', '{self._created_at}',
'{self._modified_at}' '{self._modified_at}'
); );
@ -84,10 +84,10 @@ class AuthUserUsersRelation(TableABC):
f""" f"""
UPDATE `AuthUserUsersRelations` UPDATE `AuthUserUsersRelations`
SET `AuthUserId` = '{self._auth_user.id}',, SET `AuthUserId` = '{self._auth_user.id}',,
`UserId` = '{self._user.user_id}' `UserId` = '{self._user.id}'
`LastModifiedAt` = '{self._modified_at}' `LastModifiedAt` = '{self._modified_at}'
WHERE `AuthUserId` = {self._auth_user.id} 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""" f"""
DELETE FROM `AuthUserUsersRelations` DELETE FROM `AuthUserUsersRelations`
WHERE `AuthUserId` = {self._auth_user.id} WHERE `AuthUserId` = {self._auth_user.id}
AND `UserId` = {self._user.user_id}; AND `UserId` = {self._user.id};
""" """
) )

View File

@ -2,6 +2,8 @@ from datetime import datetime
from typing import Optional 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 bot_data.model.server import Server from bot_data.model.server import Server
@ -10,7 +12,7 @@ class AutoRole(TableABC):
def __init__( def __init__(
self, self,
server: Optional[Server], server: Optional[Server],
dc_channel_id: int, channel_id: int,
dc_message_id: int, dc_message_id: int,
created_at: datetime = None, created_at: datetime = None,
modified_at: datetime = None, modified_at: datetime = None,
@ -18,7 +20,7 @@ class AutoRole(TableABC):
): ):
self._auto_role_id = id self._auto_role_id = id
self._server = server self._server = server
self._discord_channel_id = dc_channel_id self._discord_channel_id = channel_id
self._discord_message_id = dc_message_id self._discord_message_id = dc_message_id
TableABC.__init__(self) TableABC.__init__(self)
@ -26,7 +28,7 @@ class AutoRole(TableABC):
self._modified_at = modified_at if modified_at is not None else self._modified_at self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def auto_role_id(self) -> int: def id(self) -> int:
return self._auto_role_id return self._auto_role_id
@property @property
@ -41,6 +43,12 @@ class AutoRole(TableABC):
def discord_channel_id(self, value: int): def discord_channel_id(self, value: int):
self._discord_channel_id = value 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 @property
def discord_message_id(self) -> int: def discord_message_id(self) -> int:
return self._discord_message_id return self._discord_message_id
@ -91,7 +99,7 @@ class AutoRole(TableABC):
INSERT INTO `AutoRoles` ( INSERT INTO `AutoRoles` (
`ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt` `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._server.server_id}, {self._server.id},
{self._discord_channel_id}, {self._discord_channel_id},
{self._discord_message_id}, {self._discord_message_id},
'{self._created_at}', '{self._created_at}',
@ -105,7 +113,7 @@ class AutoRole(TableABC):
return str( return str(
f""" f"""
UPDATE `AutoRoles` UPDATE `AutoRoles`
SET `ServerId` = {self._server.server_id}, SET `ServerId` = {self._server.id},
`DiscordChannelId` = {self._discord_channel_id}, `DiscordChannelId` = {self._discord_channel_id},
`DiscordMessageId` = {self._discord_message_id}, `DiscordMessageId` = {self._discord_message_id},
`LastModifiedAt` = '{self._modified_at}' `LastModifiedAt` = '{self._modified_at}'

View File

@ -1,6 +1,8 @@
from datetime import datetime from datetime import datetime
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 bot_data.model.auto_role import AutoRole from bot_data.model.auto_role import AutoRole
@ -25,7 +27,7 @@ class AutoRoleRule(TableABC):
self._modified_at = modified_at if modified_at is not None else self._modified_at self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def auto_role_rule_id(self) -> int: def id(self) -> int:
return self._auto_role_rule_id return self._auto_role_rule_id
@property @property
@ -44,6 +46,12 @@ class AutoRoleRule(TableABC):
def role_id(self) -> int: def role_id(self) -> int:
return self._discord_role_id 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 @role_id.setter
def role_id(self, value: int): def role_id(self, value: int):
self._discord_role_id = value self._discord_role_id = value

View File

@ -1,5 +1,8 @@
from datetime import datetime from datetime import datetime
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 bot_data.model.server import Server 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 self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def client_id(self) -> int: def id(self) -> int:
return self._client_id return self._client_id
@property @property
def discord_id(self) -> int: def discord_id(self) -> int:
return self._discord_client_id return self._discord_client_id
@property
@ServiceProviderABC.inject
def name(self, bot: DiscordBotServiceABC) -> str:
return bot.user.name
@property @property
def sent_message_count(self) -> int: def sent_message_count(self) -> int:
return self._sent_message_count return self._sent_message_count
@ -154,7 +162,7 @@ class Client(TableABC):
{self._deleted_message_count}, {self._deleted_message_count},
{self._received_message_count}, {self._received_message_count},
{self._moved_users_count}, {self._moved_users_count},
{self._server.server_id}, {self._server.id},
'{self._created_at}', '{self._created_at}',
'{self._modified_at}' '{self._modified_at}'
); );

View File

@ -19,7 +19,7 @@ class KnownUser(TableABC):
self._modified_at = modified_at if modified_at is not None else self._modified_at self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def known_user_id(self) -> int: def id(self) -> int:
return self._known_user_id return self._known_user_id
@property @property

View File

@ -1,5 +1,6 @@
from datetime import datetime from datetime import datetime
from typing import Optional from typing import Optional
from cpl_core.database import TableABC from cpl_core.database import TableABC
from bot_data.model.server import Server from bot_data.model.server import Server
@ -114,7 +115,7 @@ class Level(TableABC):
'{self._color}', '{self._color}',
{self._min_xp}, {self._min_xp},
{self._permissions}, {self._permissions},
{self._server.server_id}, {self._server.id},
'{self._created_at}', '{self._created_at}',
'{self._modified_at}' '{self._modified_at}'
); );

View File

@ -1,7 +1,8 @@
from datetime import datetime 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
class Server(TableABC): 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 self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def server_id(self) -> int: def id(self) -> int:
return self._server_id return self._server_id
@property @property
def discord_server_id(self) -> int: def discord_id(self) -> int:
return self._discord_server_id 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 @staticmethod
def get_select_all_string() -> str: def get_select_all_string() -> str:
return str( return str(

View File

@ -1,131 +0,0 @@
from datetime import datetime
from cpl_core.database import TableABC
from cpl_core.utils import CredentialManager
from bot_data.model.server import Server
class Statistic(TableABC):
def __init__(
self,
name: str,
description: str,
code: str,
server: Server,
created_at: datetime = None,
modified_at: datetime = None,
id=0,
):
self._id = id
self._name = name
self._description = description
self._code = CredentialManager.encrypt(code)
self._server = server
TableABC.__init__(self)
self._created_at = created_at if created_at is not None else self._created_at
self._modified_at = modified_at if modified_at is not None else self._modified_at
@property
def id(self) -> int:
return self._id
@property
def name(self) -> str:
return self._name
@property
def description(self) -> str:
return self._description
@description.setter
def description(self, value: str):
self._description = value
@property
def code(self) -> str:
return CredentialManager.decrypt(self._code)
@code.setter
def code(self, value: str):
self._code = CredentialManager.encrypt(value)
@property
def server(self) -> Server:
return self._server
@staticmethod
def get_select_all_string() -> str:
return str(
f"""
SELECT * FROM `Statistics`;
"""
)
@staticmethod
def get_select_by_id_string(id: int) -> str:
return str(
f"""
SELECT * FROM `Statistics`
WHERE `Id` = {id};
"""
)
@staticmethod
def get_select_by_name_string(name: str, s_id: int) -> str:
return str(
f"""
SELECT * FROM `Statistics`
WHERE `ServerId` = {s_id}
AND `Name` = '{name}';
"""
)
@staticmethod
def get_select_by_server_string(s_id: int) -> str:
return str(
f"""
SELECT * FROM `Statistics`
WHERE `ServerId` = {s_id};
"""
)
@property
def insert_string(self) -> str:
return str(
f"""
INSERT INTO `Statistics` (
`Name`, `Description`, `Code`, `ServerId`, `CreatedAt`, `LastModifiedAt`
) VALUES (
'{self._name}',
'{self._description}',
'{self._code}',
{self._server.server_id},
'{self._created_at}',
'{self._modified_at}'
);
"""
)
@property
def udpate_string(self) -> str:
return str(
f"""
UPDATE `Statistics`
SET `Name` = '{self._name}',
`Description` = '{self._description}',
`Code` = '{self._code}',
`LastModifiedAt` = '{self._modified_at}'
WHERE `Id` = {self._id};
"""
)
@property
def delete_string(self) -> str:
return str(
f"""
DELETE FROM `Statistics`
WHERE `Id` = {self._id};
"""
)

View File

@ -2,7 +2,10 @@ from datetime import datetime
from typing import Optional 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 bot_data.model.level import Level
from bot_data.model.server import Server from bot_data.model.server import Server
@ -28,13 +31,27 @@ class User(TableABC):
self._modified_at = modified_at if modified_at is not None else self._modified_at self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def user_id(self) -> int: def id(self) -> int:
return self._user_id return self._user_id
@property @property
def discord_id(self) -> int: def discord_id(self) -> int:
return self._discord_id 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 @property
def xp(self) -> int: def xp(self) -> int:
return self._xp return self._xp
@ -44,6 +61,22 @@ class User(TableABC):
self._modified_at = datetime.now().isoformat() self._modified_at = datetime.now().isoformat()
self._xp = value 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 @property
def minecraft_id(self) -> Optional[str]: def minecraft_id(self) -> Optional[str]:
return self._minecraft_id return self._minecraft_id
@ -56,6 +89,17 @@ class User(TableABC):
def server(self) -> Optional[Server]: def server(self) -> Optional[Server]:
return self._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
@staticmethod @staticmethod
def get_select_all_string() -> str: def get_select_all_string() -> str:
return str( return str(
@ -110,8 +154,8 @@ class User(TableABC):
) VALUES ( ) VALUES (
{self._discord_id}, {self._discord_id},
{self._xp}, {self._xp},
'{"NULL" if self._minecraft_id is None else self._minecraft_id}', '{self._minecraft_id}',
{self._server.server_id}, {self._server.id},
'{self._created_at}', '{self._created_at}',
'{self._modified_at}' '{self._modified_at}'
); );
@ -124,7 +168,7 @@ class User(TableABC):
f""" f"""
UPDATE `Users` UPDATE `Users`
SET `XP` = {self._xp}, SET `XP` = {self._xp},
`MinecraftId` = '{"NULL" if self._minecraft_id is None else self._minecraft_id}', `MinecraftId` = {'null' if self.minecraft_id is None else f'{self._minecraft_id}'},
`LastModifiedAt` = '{self._modified_at}' `LastModifiedAt` = '{self._modified_at}'
WHERE `UserId` = {self._user_id}; WHERE `UserId` = {self._user_id};
""" """

View File

@ -38,6 +38,10 @@ class UserJoinedGameServer(TableABC):
def game_server(self) -> str: def game_server(self) -> str:
return self._game_server return self._game_server
@property
def time(self) -> float:
return round((self.leaved_on - self.joined_on).total_seconds() / 3600, 2)
@property @property
def joined_on(self) -> datetime: def joined_on(self) -> datetime:
return self._joined_on return self._joined_on
@ -100,7 +104,7 @@ class UserJoinedGameServer(TableABC):
INSERT INTO `UserJoinedGameServer` ( INSERT INTO `UserJoinedGameServer` (
`UserId`, `GameServer`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt` `UserId`, `GameServer`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._user.user_id}, {self._user.id},
'{self._game_server}', '{self._game_server}',
'{self._joined_on}', '{self._joined_on}',
'{self._leaved_on}', '{self._leaved_on}',
@ -115,7 +119,7 @@ class UserJoinedGameServer(TableABC):
INSERT INTO `UserJoinedGameServer` ( INSERT INTO `UserJoinedGameServer` (
`UserId`, `GameServer`, `JoinedOn`, `CreatedAt`, `LastModifiedAt` `UserId`, `GameServer`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._user.user_id}, {self._user.id},
'{self._game_server}', '{self._game_server}',
'{self._joined_on}', '{self._joined_on}',
'{self._created_at}', '{self._created_at}',

View File

@ -25,7 +25,7 @@ class UserJoinedServer(TableABC):
self._modified_at = modified_at if modified_at is not None else self._modified_at self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def join_id(self) -> int: def id(self) -> int:
return self._join_id return self._join_id
@property @property
@ -103,7 +103,7 @@ class UserJoinedServer(TableABC):
INSERT INTO `UserJoinedServers` ( INSERT INTO `UserJoinedServers` (
`UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt` `UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._user.user_id}, {self._user.id},
'{self._joined_on}', '{self._joined_on}',
'{self._leaved_on}', '{self._leaved_on}',
'{self._created_at}', '{self._created_at}',
@ -117,7 +117,7 @@ class UserJoinedServer(TableABC):
INSERT INTO `UserJoinedServers` ( INSERT INTO `UserJoinedServers` (
`UserId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt` `UserId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._user.user_id}, {self._user.id},
'{self._joined_on}', '{self._joined_on}',
'{self._created_at}', '{self._created_at}',
'{self._modified_at}' '{self._modified_at}'
@ -132,7 +132,7 @@ class UserJoinedServer(TableABC):
UPDATE `UserJoinedServers` UPDATE `UserJoinedServers`
SET `LeavedOn` = '{self._leaved_on}', SET `LeavedOn` = '{self._leaved_on}',
`LastModifiedAt` = '{self._modified_at}' `LastModifiedAt` = '{self._modified_at}'
WHERE `UserId` = {self._user.user_id}; WHERE `UserId` = {self._user.id};
""" """
) )

View File

@ -1,6 +1,8 @@
from datetime import datetime from datetime import datetime
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 bot_data.model.user import User from bot_data.model.user import User
@ -9,7 +11,7 @@ class UserJoinedVoiceChannel(TableABC):
def __init__( def __init__(
self, self,
user: User, user: User,
dc_channel_id: int, channel_id: int,
joined_on: datetime, joined_on: datetime,
leaved_on: datetime = None, leaved_on: datetime = None,
created_at: datetime = None, created_at: datetime = None,
@ -17,7 +19,7 @@ class UserJoinedVoiceChannel(TableABC):
id=0, id=0,
): ):
self._join_id = id self._join_id = id
self._dc_channel_id = dc_channel_id self._channel_id = channel_id
self._user = user self._user = user
self._joined_on = joined_on self._joined_on = joined_on
self._leaved_on = leaved_on self._leaved_on = leaved_on
@ -27,17 +29,26 @@ class UserJoinedVoiceChannel(TableABC):
self._modified_at = modified_at if modified_at is not None else self._modified_at self._modified_at = modified_at if modified_at is not None else self._modified_at
@property @property
def join_id(self) -> int: def id(self) -> int:
return self._join_id return self._join_id
@property @property
def dc_channel_id(self) -> int: def channel_id(self) -> int:
return self._dc_channel_id return self._channel_id
@property
@ServiceProviderABC.inject
def channel_name(self, bot: DiscordBotServiceABC) -> str:
return bot.get_channel(self.channel_id).name
@property @property
def user(self) -> User: def user(self) -> User:
return self._user return self._user
@property
def time(self) -> float:
return round((self.leaved_on - self.joined_on).total_seconds() / 3600, 2)
@property @property
def joined_on(self) -> datetime: def joined_on(self) -> datetime:
return self._joined_on return self._joined_on
@ -100,8 +111,8 @@ class UserJoinedVoiceChannel(TableABC):
INSERT INTO `UserJoinedVoiceChannel` ( INSERT INTO `UserJoinedVoiceChannel` (
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt` `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._user.user_id}, {self._user.id},
{self._dc_channel_id}, {self._channel_id},
'{self._joined_on}', '{self._joined_on}',
'{self._leaved_on}', '{self._leaved_on}',
'{self._created_at}', '{self._created_at}',
@ -115,8 +126,8 @@ class UserJoinedVoiceChannel(TableABC):
INSERT INTO `UserJoinedVoiceChannel` ( INSERT INTO `UserJoinedVoiceChannel` (
`UserId`, `DiscordChannelId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt` `UserId`, `DiscordChannelId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._user.user_id}, {self._user.id},
{self._dc_channel_id}, {self._channel_id},
'{self._joined_on}', '{self._joined_on}',
'{self._created_at}', '{self._created_at}',
'{self._modified_at}' '{self._modified_at}'

View File

@ -97,7 +97,7 @@ class UserMessageCountPerHour(TableABC):
INSERT INTO `UserMessageCountPerHour` ( INSERT INTO `UserMessageCountPerHour` (
`UserId`, `Date`, `Hour`, `XPCount`, `CreatedAt`, `LastModifiedAt` `UserId`, `Date`, `Hour`, `XPCount`, `CreatedAt`, `LastModifiedAt`
) VALUES ( ) VALUES (
{self._user.user_id}, {self._user.id},
'{self._date}', '{self._date}',
{self._hour}, {self._hour},
{self._xp_count}, {self._xp_count},

View File

@ -15,7 +15,7 @@ __title__ = "bot_data.service"
__author__ = "Sven Heidemann" __author__ = "Sven Heidemann"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "0.3.1" __version__ = "1.0.dev130"
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro") VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="0", minor="3", micro="1") version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -28,7 +28,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
@staticmethod @staticmethod
def _get_value_from_result(value: any) -> Optional[any]: def _get_value_from_result(value: any) -> Optional[any]:
if isinstance(value, str) and "NULL" in value: if isinstance(value, str) and "null" in value:
return None return None
return value return value

View File

@ -193,9 +193,9 @@ class ClientRepositoryService(ClientRepositoryABC):
self._logger.warn(__name__, f"Cannot find server by id {server_id}") self._logger.warn(__name__, f"Cannot find server by id {server_id}")
raise Exception("Value not found") raise Exception("Value not found")
client = self.find_client_by_discord_id_and_server_id(id, server.server_id) client = self.find_client_by_discord_id_and_server_id(id, server.id)
if client is None: if client is None:
self._logger.warn(__name__, f"Cannot find client by ids {id}@{server.server_id}") self._logger.warn(__name__, f"Cannot find client by ids {id}@{server.id}")
raise Exception("Value not found") raise Exception("Value not found")
return client return client

View File

@ -1,106 +0,0 @@
from typing import Optional
from cpl_core.database.context import DatabaseContextABC
from cpl_core.utils import CredentialManager
from cpl_query.extension import List
from bot_core.logging.database_logger import DatabaseLogger
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
from bot_data.model.statistic import Statistic
class StatisticRepositoryService(StatisticRepositoryABC):
def __init__(
self,
logger: DatabaseLogger,
db_context: DatabaseContextABC,
statistics: ServerRepositoryABC,
):
self._logger = logger
self._context = db_context
self._statistics = statistics
StatisticRepositoryABC.__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 _statistic_from_result(self, sql_result: tuple) -> Statistic:
code = self._get_value_from_result(sql_result[3])
if code is not None:
code = CredentialManager.decrypt(code)
statistic = Statistic(
self._get_value_from_result(sql_result[1]),
self._get_value_from_result(sql_result[2]),
code,
self._statistics.get_server_by_id(sql_result[4]),
id=self._get_value_from_result(sql_result[0]),
)
return statistic
def get_statistics(self) -> List[Statistic]:
statistics = List(Statistic)
self._logger.trace(__name__, f"Send SQL command: {Statistic.get_select_all_string()}")
results = self._context.select(Statistic.get_select_all_string())
for result in results:
statistics.append(self._statistic_from_result(result))
return statistics
def get_statistics_by_server_id(self, server_id: int) -> List[Statistic]:
statistics = List(Statistic)
self._logger.trace(
__name__,
f"Send SQL command: {Statistic.get_select_by_server_string(server_id)}",
)
results = self._context.select(Statistic.get_select_by_server_string(server_id))
for result in results:
statistics.append(self._statistic_from_result(result))
return statistics
def get_statistic_by_id(self, id: int) -> Statistic:
self._logger.trace(__name__, f"Send SQL command: {Statistic.get_select_by_id_string(id)}")
result = self._context.select(Statistic.get_select_by_id_string(id))[0]
return self._statistic_from_result(result)
def get_statistic_by_name(self, name: str, server_id: int) -> Statistic:
self._logger.trace(
__name__,
f"Send SQL command: {Statistic.get_select_by_name_string(name, server_id)}",
)
result = self._context.select(Statistic.get_select_by_name_string(name, server_id))[0]
return self._statistic_from_result(result)
def find_statistic_by_name(self, name: str, server_id: int) -> Optional[Statistic]:
self._logger.trace(
__name__,
f"Send SQL command: {Statistic.get_select_by_name_string(name, server_id)}",
)
result = self._context.select(Statistic.get_select_by_name_string(name, server_id))
if result is None or len(result) == 0:
return None
result = result[0]
return self._statistic_from_result(result)
def add_statistic(self, statistic: Statistic):
self._logger.trace(__name__, f"Send SQL command: {statistic.insert_string}")
self._context.cursor.execute(statistic.insert_string)
def update_statistic(self, statistic: Statistic):
self._logger.trace(__name__, f"Send SQL command: {statistic.udpate_string}")
self._context.cursor.execute(statistic.udpate_string)
def delete_statistic(self, statistic: Statistic):
self._logger.trace(__name__, f"Send SQL command: {statistic.delete_string}")
self._context.cursor.execute(statistic.delete_string)

View File

@ -1 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 - 2023 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = "bot_graphql"
__author__ = "Sven Heidemann"
__license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "1.0.dev130"
from collections import namedtuple
# imports # imports
VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 - 2023 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = "bot_graphql.abc"
__author__ = "Sven Heidemann"
__license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "1.0.dev130"
from collections import namedtuple
# imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -75,9 +75,9 @@ class QueryABC(ObjectType):
element: AutoRole = element element: AutoRole = element
for u in user.users: for u in user.users:
u: User = u u: User = u
guild = bot.get_guild(u.server.discord_server_id) guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id) member = guild.get_member(u.discord_id)
if permissions.is_member_moderator(member) and u.server.server_id == element.server.server_id: if permissions.is_member_moderator(member) and u.server.id == element.server.id:
access = True access = True
break break
@ -85,23 +85,23 @@ class QueryABC(ObjectType):
element: AutoRole = element.auto_role element: AutoRole = element.auto_role
for u in user.users: for u in user.users:
u: User = u u: User = u
guild = bot.get_guild(u.server.discord_server_id) guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id) member = guild.get_member(u.discord_id)
if permissions.is_member_moderator(member) and u.server.server_id == element.server.server_id: if permissions.is_member_moderator(member) and u.server.id == element.server.id:
access = True access = True
break break
elif type(element) == Client: elif type(element) == Client:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.server.server_id == element.server.server_id: if u.server.id == element.server.id:
access = True access = True
break break
elif type(element) == KnownUser: elif type(element) == KnownUser:
for u in user.users: for u in user.users:
u: User = u u: User = u
guild = bot.get_guild(u.server.discord_server_id) guild = bot.get_guild(u.server.discord_id)
member = guild.get_member(u.discord_id) member = guild.get_member(u.discord_id)
if permissions.is_member_moderator(member): if permissions.is_member_moderator(member):
access = True access = True
@ -110,42 +110,42 @@ class QueryABC(ObjectType):
elif type(element) == Level: elif type(element) == Level:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.server.server_id == element.server.server_id: if u.server.id == element.server.id:
access = True access = True
break break
elif type(element) == Server: elif type(element) == Server:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.server.server_id == element.server_id: if u.server.id == element.id:
access = True access = True
break break
elif type(element) == User: elif type(element) == User:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.user_id == element.user_id: if u.id == element.id:
access = True access = True
break break
elif type(element) == UserJoinedServer: elif type(element) == UserJoinedServer:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.user_id == element.user.user_id: if u.id == element.user.id:
access = True access = True
break break
elif type(element) == UserJoinedVoiceChannel: elif type(element) == UserJoinedVoiceChannel:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.user_id == element.user.user_id: if u.id == element.user.id:
access = True access = True
break break
elif type(element) == UserJoinedGameServer: elif type(element) == UserJoinedGameServer:
for u in user.users: for u in user.users:
u: User = u u: User = u
if u.user_id == element.user.user_id: if u.id == element.user.id:
access = True access = True
break break
@ -160,8 +160,8 @@ class QueryABC(ObjectType):
if auth_user == "system" or auth_user.auth_role == AuthRoleEnum.admin: if auth_user == "system" or auth_user.auth_role == AuthRoleEnum.admin:
return return
member = bot.get_guild(server.discord_server_id).get_member( member = bot.get_guild(server.discord_id).get_member(
auth_user.users.where(lambda x: x.server.server_id == server.server_id).single().discord_id auth_user.users.where(lambda x: x.server.id == server.id).single().discord_id
) )
check_perm = lambda x: True check_perm = lambda x: True
@ -180,12 +180,12 @@ class QueryABC(ObjectType):
# @FilterABC.resolve_filter_annotation # @FilterABC.resolve_filter_annotation
def _resolve_collection(self, collection: List, *_, filter: FilterABC = None, page: Page = None, sort: Sort = None): def _resolve_collection(self, collection: List, *_, filter: FilterABC = None, page: Page = None, sort: Sort = None):
if filter is not None: if filter is not None:
return filter.filter(collection) collection = filter.filter(collection)
if page is not None: if page is not None:
return page.filter(collection) collection = page.filter(collection)
if sort is not None: if sort is not None:
return sort.filter(collection) collection = sort.filter(collection)
return collection return collection

View File

@ -2,9 +2,9 @@
"ProjectSettings": { "ProjectSettings": {
"Name": "bot-data", "Name": "bot-data",
"Version": { "Version": {
"Major": "0", "Major": "1",
"Minor": "1", "Minor": "0",
"Micro": "0" "Micro": "dev130"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -16,10 +16,10 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.12.1" "cpl-core>=1.0.dev130"
], ],
"DevDependencies": [ "DevDependencies": [
"cpl-cli>=2022.12.1" "cpl-cli>=1.0.dev130"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 - 2023 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = "bot_graphql.filter"
__author__ = "Sven Heidemann"
__license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "1.0.dev130"
from collections import namedtuple
# imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -42,7 +42,7 @@ class AutoRoleFilter(FilterABC):
def filter(self, query: List[AutoRole]) -> List[AutoRole]: def filter(self, query: List[AutoRole]) -> List[AutoRole]:
if self._id is not None: if self._id is not None:
query = query.where(lambda x: x.auto_role_id == self._id) query = query.where(lambda x: x.id == self._id)
if self._channel_id is not None: if self._channel_id is not None:
query = query.where(lambda x: x.discord_channel_id == self._channel_id) query = query.where(lambda x: x.discord_channel_id == self._channel_id)
@ -57,7 +57,7 @@ class AutoRoleFilter(FilterABC):
query = query.where(lambda x: x.discord_message_id == self._message_id) query = query.where(lambda x: x.discord_message_id == self._message_id)
if self._server is not None: if self._server is not None:
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id) servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
query = query.where(lambda x: x.server.server_id in servers) query = query.where(lambda x: x.server.id in servers)
return query return query

View File

@ -39,7 +39,7 @@ class AutoRoleRuleFilter(FilterABC):
def filter(self, query: List[AutoRoleRule]) -> List[AutoRoleRule]: def filter(self, query: List[AutoRoleRule]) -> List[AutoRoleRule]:
if self._id is not None: if self._id is not None:
query = query.where(lambda x: x.auto_role_rule_id == self._id) query = query.where(lambda x: x.id == self._id)
if self._emoji_name is not None: if self._emoji_name is not None:
query = query.where(lambda x: x.emoji_name == self._emoji_name) query = query.where(lambda x: x.emoji_name == self._emoji_name)
@ -50,14 +50,14 @@ class AutoRoleRuleFilter(FilterABC):
if self._role_name is not None and self._role_id is not None: if self._role_name is not None and self._role_id is not None:
def get_role_name(x: AutoRoleRule): def get_role_name(x: AutoRoleRule):
guild = self._bot.get_guild(x.auto_role.server.discord_server_id) guild = self._bot.get_guild(x.auto_role.server.discord_id)
name = guild.get_role(x.role_id).name name = guild.get_role(x.role_id).name
return name == self._role_name or self._role_name in name return name == self._role_name or self._role_name in name
query = query.where(get_role_name) query = query.where(get_role_name)
if self._auto_role is not None: if self._auto_role is not None:
auto_roles = self._auto_role.filter(query.select(lambda x: x.auto_role)).select(lambda x: x.auto_role_id) auto_roles = self._auto_role.filter(query.select(lambda x: x.auto_role)).select(lambda x: x.id)
query = query.where(lambda x: x.auto_role.auto_role_id in auto_roles) query = query.where(lambda x: x.auto_role.id in auto_roles)
return query return query

View File

@ -32,16 +32,16 @@ class ClientFilter(FilterABC):
def filter(self, query: List[Client]) -> List[Client]: def filter(self, query: List[Client]) -> List[Client]:
if self._id is not None: if self._id is not None:
query = query.where(lambda x: x.client_id == self._id) query = query.where(lambda x: x.id == self._id)
if self._discord_id is not None: if self._discord_id is not None:
query = query.where(lambda x: x.client_id == self._discord_id) query = query.where(lambda x: x.id == self._discord_id)
if self._name is not None: if self._name is not None:
query = query.where(lambda x: self._name.lower() == x.name.lower() or self._name.lower() in x.name.lower()) query = query.where(lambda x: self._name.lower() == x.name.lower() or self._name.lower() in x.name.lower())
if self._server is not None: if self._server is not None:
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id) servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
query = query.where(lambda x: x.server.server_id in servers) query = query.where(lambda x: x.server.id in servers)
return query return query

View File

@ -25,7 +25,7 @@ class LevelFilter(FilterABC):
if "server" in values: if "server" in values:
from bot_graphql.filter.server_filter import ServerFilter from bot_graphql.filter.server_filter import ServerFilter
self._server: ServerFilter = self._services.get_service(LevelFilter) self._server: ServerFilter = self._services.get_service(ServerFilter)
self._server.from_dict(values["server"]) self._server.from_dict(values["server"])
def filter(self, query: List[Level]) -> List[Level]: def filter(self, query: List[Level]) -> List[Level]:
@ -36,7 +36,7 @@ class LevelFilter(FilterABC):
query = query.where(lambda x: self._name.lower() == x.name.lower() or self._name.lower() in x.name.lower()) query = query.where(lambda x: self._name.lower() == x.name.lower() or self._name.lower() in x.name.lower())
if self._server is not None: if self._server is not None:
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id) servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
query = query.where(lambda x: x.server.server_id in servers) query = query.where(lambda x: x.server.id in servers)
return query return query

View File

@ -28,15 +28,17 @@ class ServerFilter(FilterABC):
@ServiceProviderABC.inject @ServiceProviderABC.inject
def filter(self, query: List[Server], bot: DiscordBotServiceABC) -> List[Server]: def filter(self, query: List[Server], bot: DiscordBotServiceABC) -> List[Server]:
if self._id is not None: if self._id is not None:
query = query.where(lambda x: x.server_id == self._id) query = query.where(lambda x: x.id == self._id)
if self._discord_id is not None: if self._discord_id is not None:
query = query.where(lambda x: x.discord_server_id == self._discord_id) query = query.where(
lambda x: x.discord_id == self._discord_id or str(self._discord_id) in str(x.discord_id)
)
if self._name is not None: if self._name is not None:
def where_guild(x: Guild): def where_guild(x: Guild):
guild = bot.get_guild(x.discord_server_id) guild = bot.get_guild(x.discord_id)
return guild is not None and ( return guild is not None and (
self._name.lower() == guild.name.lower() or self._name.lower() in guild.name.lower() self._name.lower() == guild.name.lower() or self._name.lower() in guild.name.lower()
) )

View File

@ -1,3 +1,6 @@
import functools
from cpl_core.utils import String
from cpl_query.extension import List from cpl_query.extension import List
from bot_graphql.abc.filter_abc import FilterABC from bot_graphql.abc.filter_abc import FilterABC
@ -6,6 +9,7 @@ from bot_graphql.abc.filter_abc import FilterABC
class Sort(FilterABC): class Sort(FilterABC):
def __init__(self): def __init__(self):
FilterABC.__init__(self) FilterABC.__init__(self)
self._sort_direction = None self._sort_direction = None
self._sort_column = None self._sort_column = None
@ -16,5 +20,27 @@ class Sort(FilterABC):
if "sortColumn" in values: if "sortColumn" in values:
self._sort_column = values["sortColumn"] self._sort_column = values["sortColumn"]
@staticmethod
def _rgetattr(obj, attr, *args):
def _getattr(obj, attr):
return getattr(obj, attr, *args)
return functools.reduce(_getattr, [obj] + attr.split("."))
def _by_column(self, x):
atr = self._rgetattr(x, String.convert_to_snake_case(self._sort_column), None)
if atr is None:
return ""
return atr
def filter(self, query: List, *args) -> List: def filter(self, query: List, *args) -> List:
if self._sort_column is None:
return query
match self._sort_direction.lower() if self._sort_direction is not None else "ASC":
case "asc":
query = query.order_by(self._by_column)
case "desc":
query = query.order_by_descending(self._by_column)
return query return query

View File

@ -5,6 +5,7 @@ from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List from cpl_query.extension import List
from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
from bot_data.model.user import User from bot_data.model.user import User
from bot_graphql.abc.filter_abc import FilterABC from bot_graphql.abc.filter_abc import FilterABC
from bot_graphql.filter.level_filter import LevelFilter from bot_graphql.filter.level_filter import LevelFilter
@ -18,6 +19,7 @@ class UserFilter(FilterABC):
bot: DiscordBotServiceABC, bot: DiscordBotServiceABC,
client_utils: ClientUtilsABC, client_utils: ClientUtilsABC,
levels: LevelService, levels: LevelService,
user_joined_servers: UserJoinedServerRepositoryABC,
): ):
FilterABC.__init__(self) FilterABC.__init__(self)
@ -25,6 +27,7 @@ class UserFilter(FilterABC):
self._bot = bot self._bot = bot
self._client_utils = client_utils self._client_utils = client_utils
self._levels = levels self._levels = levels
self._user_joined_servers = user_joined_servers
self._id = None self._id = None
self._discord_id = None self._discord_id = None
@ -34,6 +37,7 @@ class UserFilter(FilterABC):
self._ontime = None self._ontime = None
self._level: Optional[LevelFilter] = None self._level: Optional[LevelFilter] = None
self._server = None self._server = None
self._left_server = None
def from_dict(self, values: dict): def from_dict(self, values: dict):
if "id" in values: if "id" in values:
@ -64,18 +68,26 @@ class UserFilter(FilterABC):
self._server: ServerFilter = self._services.get_service(ServerFilter) self._server: ServerFilter = self._services.get_service(ServerFilter)
self._server.from_dict(values["server"]) self._server.from_dict(values["server"])
if "leftServer" in values:
self._left_server = values["leftServer"]
def filter(self, query: List[User]) -> List[User]: def filter(self, query: List[User]) -> List[User]:
if self._id is not None: if self._id is not None:
query = query.where(lambda x: x.user_id == self._id) query = query.where(lambda x: x.id == self._id)
if self._discord_id is not None: if self._discord_id is not None:
query = query.where(lambda x: x.discord_id == self._discord_id) query = query.where(
lambda x: x.discord_id == self._discord_id or str(self._discord_id) in str(x.discord_id)
)
if self._name is not None: if self._name is not None:
query = query.where(
lambda x: self._bot.get_user(x.discord_id).name == self._name def _get_member(user: User):
or self._name in self._bot.get_user(x.discord_id).name guild = self._bot.get_guild(user.server.discord_id)
) member = guild.get_member(user.discord_id)
return member is not None and (member.name == self._name or self._name in member.name)
query = query.where(_get_member)
if self._xp is not None: if self._xp is not None:
query = query.where(lambda x: x.xp == self._xp) query = query.where(lambda x: x.xp == self._xp)
@ -91,7 +103,15 @@ class UserFilter(FilterABC):
query = query.where(lambda x: self._levels.get_level(x).id in levels) query = query.where(lambda x: self._levels.get_level(x).id in levels)
if self._server is not None: if self._server is not None:
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id) servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
query = query.where(lambda x: x.server.server_id in servers) query = query.where(lambda x: x.server.id in servers)
if self._left_server is not None:
def _has_user_left_server(user: User):
active_join = self._user_joined_servers.find_active_user_joined_server_by_user_id(user.id)
return (active_join is None) == self._left_server
query = query.where(_has_user_left_server)
return query return query

View File

@ -42,7 +42,7 @@ class UserJoinedGameServerFilter(FilterABC):
query = query.where(lambda x: x.game_server == self._game_server) query = query.where(lambda x: x.game_server == self._game_server)
if self._user is not None: if self._user is not None:
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id) users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
query = query.where(lambda x: x.user.user_id in users) query = query.where(lambda x: x.user.id in users)
return query return query

View File

@ -43,8 +43,8 @@ class UserJoinedServerFilter(FilterABC):
query = query.where(lambda x: x.id == self._id) query = query.where(lambda x: x.id == self._id)
if self._user is not None: if self._user is not None:
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id) users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
query = query.where(lambda x: x.user.user_id in users) query = query.where(lambda x: x.user.id in users)
if self._joined_on is not None: if self._joined_on is not None:
query = query.where(lambda x: x.joined_on == self._joined_on or self._joined_on in x.joined_on) query = query.where(lambda x: x.joined_on == self._joined_on or self._joined_on in x.joined_on)

View File

@ -51,19 +51,19 @@ class UserJoinedVoiceChannelFilter(FilterABC):
query = query.where(lambda x: x.id == self._id) query = query.where(lambda x: x.id == self._id)
if self._channel_id is not None: if self._channel_id is not None:
query = query.where(lambda x: x.dc_channel_id == self._channel_id) query = query.where(lambda x: x.channel_id == self._channel_id)
if self._channel_name is not None and self._channel_id is not None: if self._channel_name is not None and self._channel_id is not None:
def get_channel_name(x: UserJoinedVoiceChannel): def get_channel_name(x: UserJoinedVoiceChannel):
name = self._bot.get_channel(x.dc_channel_id).name name = self._bot.get_channel(x.channel_id).name
return name == self._channel_name or self._channel_name in name return name == self._channel_name or self._channel_name in name
query = query.where(get_channel_name) query = query.where(get_channel_name)
if self._user is not None: if self._user is not None:
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id) users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
query = query.where(lambda x: x.user.user_id in users) query = query.where(lambda x: x.user.id in users)
if self._joined_on is not None: if self._joined_on is not None:
query = query.where(lambda x: x.joined_on == self._joined_on or self._joined_on in x.joined_on) query = query.where(lambda x: x.joined_on == self._joined_on or self._joined_on in x.joined_on)

View File

@ -9,6 +9,11 @@ input Page {
} }
input Sort { input Sort {
sortDirection: String sortDirection: SortDirection
sortColumn: String sortColumn: String
} }
enum SortDirection {
ASC
DESC
}

View File

@ -17,6 +17,7 @@ type User implements TableQuery {
userJoinedGameServers(filter: UserJoinedGameServerFilter, page: Page, sort: Sort): [UserJoinedGameServer] userJoinedGameServers(filter: UserJoinedGameServerFilter, page: Page, sort: Sort): [UserJoinedGameServer]
server: Server server: Server
leftServer: Boolean
createdAt: String createdAt: String
modifiedAt: String modifiedAt: String
@ -31,6 +32,7 @@ input UserFilter {
ontime: Float ontime: Float
level: LevelFilter level: LevelFilter
server: ServerFilter server: ServerFilter
leftServer: Boolean
} }
type UserMutation { type UserMutation {
@ -40,4 +42,5 @@ type UserMutation {
input UserInput { input UserInput {
id: ID id: ID
xp: Int xp: Int
levelId: ID
} }

View File

@ -2,6 +2,7 @@ type UserJoinedGameServer implements TableQuery {
id: ID id: ID
gameServer: String gameServer: String
user: User user: User
time: Float
joinedOn: String joinedOn: String
leavedOn: String leavedOn: String

View File

@ -3,6 +3,7 @@ type UserJoinedVoiceChannel implements TableQuery {
channelId: String channelId: String
channelName: String channelName: String
user: User user: User
time: Float
joinedOn: String joinedOn: String
leavedOn: String leavedOn: String

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 - 2023 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = "bot_graphql.mutations"
__author__ = "Sven Heidemann"
__license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "1.0.dev130"
from collections import namedtuple
# imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -33,12 +33,12 @@ class AutoRoleMutation(QueryABC):
def get_new(x: AutoRole): def get_new(x: AutoRole):
return ( return (
x.server.server_id == input["serverId"] x.server.id == input["serverId"]
and x.discord_channel_id == input["channelId"] and x.discord_channel_id == input["channelId"]
and x.discord_message_id == input["messageId"] and x.discord_message_id == input["messageId"]
) )
return self._auto_roles.get_auto_roles_by_server_id(auto_role.server.server_id).where(get_new).last() return self._auto_roles.get_auto_roles_by_server_id(auto_role.server.id).where(get_new).last()
def resolve_update_auto_role(self, *_, input: dict): def resolve_update_auto_role(self, *_, input: dict):
auto_role = self._auto_roles.get_auto_role_by_id(input["id"]) auto_role = self._auto_roles.get_auto_role_by_id(input["id"])

View File

@ -35,16 +35,12 @@ class AutoRoleRuleMutation(QueryABC):
def get_new(x: AutoRoleRule): def get_new(x: AutoRoleRule):
return ( return (
x.auto_role.auto_role_id == input["autoRoleId"] x.auto_role.id == input["autoRoleId"]
and x.emoji_name == input["emojiName"] and x.emoji_name == input["emojiName"]
and x.role_id == input["roleId"] and x.role_id == input["roleId"]
) )
return ( return self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.id).where(get_new).last()
self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.auto_role_id)
.where(get_new)
.last()
)
def resolve_update_auto_role_rule(self, *_, input: dict): def resolve_update_auto_role_rule(self, *_, input: dict):
auto_role_rule = self._auto_roles.get_auto_role_rule_by_id(input["id"]) auto_role_rule = self._auto_roles.get_auto_role_rule_by_id(input["id"])

View File

@ -46,7 +46,7 @@ class LevelMutation(QueryABC):
and l.permissions == level.permissions and l.permissions == level.permissions
) )
return self._levels.get_levels_by_server_id(level.server.server_id).where(get_new_level).last() return self._levels.get_levels_by_server_id(level.server.id).where(get_new_level).last()
def resolve_update_level(self, *_, input: dict): def resolve_update_level(self, *_, input: dict):
level = self._levels.get_level_by_id(input["id"]) level = self._levels.get_level_by_id(input["id"])

View File

@ -45,11 +45,11 @@ class UserJoinedGameServerMutation(QueryABC):
user = self._users.get_user_by_id(input["userId"]) user = self._users.get_user_by_id(input["userId"])
self._can_user_mutate_data(user.server, UserRoleEnum.admin) self._can_user_mutate_data(user.server, UserRoleEnum.admin)
active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.user_id) active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.id)
if active is not None: if active is not None:
self._logger.debug( self._logger.debug(
__name__, __name__,
f"Skip UserJoinedGameServer for user {user.user_id}. User already plays on {active.game_server}.", f"Skip UserJoinedGameServer for user {user.id}. User already plays on {active.game_server}.",
) )
return return
@ -57,18 +57,18 @@ class UserJoinedGameServerMutation(QueryABC):
self._user_joined_game_servers.add_user_joined_game_server(new) self._user_joined_game_servers.add_user_joined_game_server(new)
self._db.save_changes() self._db.save_changes()
return self._user_joined_game_servers.get_active_user_joined_game_server_by_user_id(user.user_id) return self._user_joined_game_servers.get_active_user_joined_game_server_by_user_id(user.id)
def resolve_user_leaved(self, *_, input: dict): def resolve_user_leaved(self, *_, input: dict):
user = self._users.get_user_by_id(input["userId"]) user = self._users.get_user_by_id(input["userId"])
self._can_user_mutate_data(user.server, UserRoleEnum.admin) self._can_user_mutate_data(user.server, UserRoleEnum.admin)
active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.user_id) active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.id)
if active is None: if active is None:
return None return None
active.leaved_on = datetime.now() active.leaved_on = datetime.now()
settings: BaseServerSettings = self._base_helper.get_config(user.server.discord_server_id) settings: BaseServerSettings = self._base_helper.get_config(user.server.discord_id)
ontime = round((active.leaved_on - active.joined_on).total_seconds() / 3600, 2) ontime = round((active.leaved_on - active.joined_on).total_seconds() / 3600, 2)
old_xp = user.xp old_xp = user.xp

View File

@ -1,10 +1,12 @@
from cpl_core.database.context import DatabaseContextABC from cpl_core.database.context import DatabaseContextABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from bot_data.abc.level_repository_abc import LevelRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC
from bot_data.model.user_role_enum import UserRoleEnum from bot_data.model.user_role_enum import UserRoleEnum
from bot_graphql.abc.query_abc import QueryABC from bot_graphql.abc.query_abc import QueryABC
from modules.level.service.level_service import LevelService
from modules.permission.service.permission_service import PermissionService from modules.permission.service.permission_service import PermissionService
@ -16,6 +18,8 @@ class UserMutation(QueryABC):
bot: DiscordBotServiceABC, bot: DiscordBotServiceABC,
db: DatabaseContextABC, db: DatabaseContextABC,
permissions: PermissionService, permissions: PermissionService,
levels: LevelRepositoryABC,
level_service: LevelService,
): ):
QueryABC.__init__(self, "UserMutation") QueryABC.__init__(self, "UserMutation")
@ -24,6 +28,8 @@ class UserMutation(QueryABC):
self._bot = bot self._bot = bot
self._db = db self._db = db
self._permissions = permissions self._permissions = permissions
self._levels = levels
self._level_service = level_service
self.set_field("updateUser", self.resolve_update_user) self.set_field("updateUser", self.resolve_update_user)
@ -31,10 +37,15 @@ class UserMutation(QueryABC):
user = self._users.get_user_by_id(input["id"]) user = self._users.get_user_by_id(input["id"])
self._can_user_mutate_data(user.server, UserRoleEnum.moderator) self._can_user_mutate_data(user.server, UserRoleEnum.moderator)
if "levelId" in input:
level = self._levels.get_level_by_id(input["levelId"])
user.xp = level.min_xp
user.xp = input["xp"] if "xp" in input else user.xp user.xp = input["xp"] if "xp" in input else user.xp
self._users.update_user(user) self._users.update_user(user)
self._db.save_changes() self._db.save_changes()
self._bot.loop.create_task(self._level_service.set_level(user))
user = self._users.get_user_by_id(input["id"]) user = self._users.get_user_by_id(input["id"])
return user return user

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 - 2023 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = "bot_graphql.queries"
__author__ = "Sven Heidemann"
__license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "1.0.dev130"
from collections import namedtuple
# imports:
VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="1", minor="0", micro="dev130")

View File

@ -28,21 +28,21 @@ class AutoRoleQuery(DataQueryABC):
self.set_field("server", self.resolve_server) self.set_field("server", self.resolve_server)
self.add_collection( self.add_collection(
"autoRoleRule", "autoRoleRule",
lambda x, *_: self._auto_role_rules.get_auto_role_rules_by_auto_role_id(x.auto_role_id), lambda x, *_: self._auto_role_rules.get_auto_role_rules_by_auto_role_id(x.id),
AutoRoleFilter, AutoRoleFilter,
) )
@staticmethod @staticmethod
def resolve_id(x: AutoRole, *_): def resolve_id(x: AutoRole, *_):
return x.auto_role_id return x.id
@staticmethod @staticmethod
def resolve_channel_id(x: AutoRole, *_): def resolve_channel_id(x: AutoRole, *_):
return x.discord_channel_id return x.discord_channel_id
def resolve_channel_name(self, x: AutoRole, *_): @staticmethod
channel = self._bot.get_channel(x.discord_channel_id) def resolve_channel_name(x: AutoRole, *_):
return None if channel is None else channel.name return x.discord_channel_name
@staticmethod @staticmethod
def resolve_message_id(x: AutoRole, *_): def resolve_message_id(x: AutoRole, *_):
@ -50,6 +50,6 @@ class AutoRoleQuery(DataQueryABC):
def resolve_server(self, x: AutoRole, *_, filter: ServerFilter = None): def resolve_server(self, x: AutoRole, *_, filter: ServerFilter = None):
if filter is not None: if filter is not None:
return filter.filter(self._servers.get_server_by_id(x.server.server_id)) return filter.filter(self._servers.get_server_by_id(x.server.id))
return self._servers.get_server_by_id(x.server.server_id) return self._servers.get_server_by_id(x.server.id)

View File

@ -24,7 +24,7 @@ class AutoRoleRuleQuery(DataQueryABC):
@staticmethod @staticmethod
def resolve_id(x: AutoRoleRule, *_): def resolve_id(x: AutoRoleRule, *_):
return x.auto_role_rule_id return x.id
@staticmethod @staticmethod
def resolve_emoji_name(x: AutoRoleRule, *_): def resolve_emoji_name(x: AutoRoleRule, *_):
@ -34,9 +34,9 @@ class AutoRoleRuleQuery(DataQueryABC):
def resolve_role_id(x: AutoRoleRule, *_): def resolve_role_id(x: AutoRoleRule, *_):
return x.role_id return x.role_id
def resolve_role_name(self, x: AutoRoleRule, *_): @staticmethod
guild = self._bot.get_guild(x.auto_role.server.discord_server_id) def resolve_role_name(x: AutoRoleRule, *_):
return guild.get_role(x.role_id).name return x.role_name
def resolve_auto_role(self, x: AutoRoleRule, *_): def resolve_auto_role(self, x: AutoRoleRule, *_):
return self._auto_roles.get_auto_role_by_id(x.auto_role.auto_role_id) return self._auto_roles.get_auto_role_by_id(x.auto_role.id)

View File

@ -25,14 +25,15 @@ class ClientQuery(DataQueryABC):
@staticmethod @staticmethod
def resolve_id(client: Client, *_): def resolve_id(client: Client, *_):
return client.client_id return client.id
@staticmethod @staticmethod
def resolve_discord_id(client: Client, *_): def resolve_discord_id(client: Client, *_):
return client.discord_id return client.discord_id
def resolve_name(self, client: Client, *_): @staticmethod
return self._bot.user.name def resolve_name(client: Client, *_):
return client.name
@staticmethod @staticmethod
def resolve_sent_message_count(client: Client, *_): def resolve_sent_message_count(client: Client, *_):

View File

@ -11,7 +11,7 @@ class KnownUserQuery(DataQueryABC):
@staticmethod @staticmethod
def resolve_id(x: KnownUser, *_): def resolve_id(x: KnownUser, *_):
return x.known_user_id return x.id
@staticmethod @staticmethod
def resolve_discord_id(x: KnownUser, *_): def resolve_discord_id(x: KnownUser, *_):

View File

@ -42,29 +42,27 @@ class ServerQuery(DataQueryABC):
self.add_collection( self.add_collection(
"autoRole", "autoRole",
lambda server, *_: self._auto_roles.get_auto_roles_by_server_id(server.server_id), lambda server, *_: self._auto_roles.get_auto_roles_by_server_id(server.id),
AutoRoleFilter, AutoRoleFilter,
) )
self.add_collection( self.add_collection(
"client", lambda server, *_: self._clients.get_clients_by_server_id(server.server_id), ClientFilter "client", lambda server, *_: self._clients.get_clients_by_server_id(server.id), ClientFilter
) )
self.add_collection( self.add_collection("level", lambda server, *_: self._levels.get_levels_by_server_id(server.id), LevelFilter)
"level", lambda server, *_: self._levels.get_levels_by_server_id(server.server_id), LevelFilter self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.id), UserFilter)
)
self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.server_id), UserFilter)
@staticmethod @staticmethod
def resolve_id(server: Server, *_): def resolve_id(server: Server, *_):
return server.server_id return server.id
@staticmethod @staticmethod
def resolve_discord_id(server: Server, *_): def resolve_discord_id(server: Server, *_):
return server.discord_server_id return server.discord_id
def resolve_name(self, server: Server, *_): @staticmethod
guild = self._bot.get_guild(server.discord_server_id) def resolve_name(server: Server, *_):
return None if guild is None else guild.name return server.name
def resolve_icon_url(self, server: Server, *_): @staticmethod
guild = self._bot.get_guild(server.discord_server_id) def resolve_icon_url(server: Server, *_):
return None if guild is None else guild.icon.url return server.icon_url

View File

@ -28,6 +28,10 @@ class UserJoinedGameServerQuery(DataQueryABC):
def resolve_user(x: UserJoinedGameServer, *_): def resolve_user(x: UserJoinedGameServer, *_):
return x.user return x.user
@staticmethod
def resolve_time(x: UserJoinedGameServer, *_):
return x.time
@staticmethod @staticmethod
def resolve_joined_on(x: UserJoinedGameServer, *_): def resolve_joined_on(x: UserJoinedGameServer, *_):
return x.joined_on return x.joined_on

View File

@ -13,7 +13,7 @@ class UserJoinedServerQuery(DataQueryABC):
@staticmethod @staticmethod
def resolve_id(x: UserJoinedServer, *_): def resolve_id(x: UserJoinedServer, *_):
return x.join_id return x.id
@staticmethod @staticmethod
def resolve_user(x: UserJoinedServer, *_): def resolve_user(x: UserJoinedServer, *_):

View File

@ -14,24 +14,30 @@ class UserJoinedVoiceChannelQuery(DataQueryABC):
self.set_field("channelId", self.resolve_channel_id) self.set_field("channelId", self.resolve_channel_id)
self.set_field("channelName", self.resolve_channel_name) self.set_field("channelName", self.resolve_channel_name)
self.set_field("user", self.resolve_user) self.set_field("user", self.resolve_user)
self.set_field("time", self.resolve_time)
self.set_field("joinedOn", self.resolve_joined_on) self.set_field("joinedOn", self.resolve_joined_on)
self.set_field("leavedOn", self.resolve_leaved_on) self.set_field("leavedOn", self.resolve_leaved_on)
@staticmethod @staticmethod
def resolve_id(x: UserJoinedVoiceChannel, *_): def resolve_id(x: UserJoinedVoiceChannel, *_):
return x.join_id return x.id
@staticmethod @staticmethod
def resolve_channel_id(x: UserJoinedVoiceChannel, *_): def resolve_channel_id(x: UserJoinedVoiceChannel, *_):
return x.dc_channel_id return x.channel_id
def resolve_channel_name(self, x: UserJoinedVoiceChannel, *_): @staticmethod
return self._bot.get_channel(x.dc_channel_id).name def resolve_channel_name(x: UserJoinedVoiceChannel, *_):
return x.channel_name
@staticmethod @staticmethod
def resolve_user(x: UserJoinedVoiceChannel, *_): def resolve_user(x: UserJoinedVoiceChannel, *_):
return x.user return x.user
@staticmethod
def resolve_time(x: UserJoinedVoiceChannel, *_):
return x.time
@staticmethod @staticmethod
def resolve_joined_on(x: UserJoinedVoiceChannel, *_): def resolve_joined_on(x: UserJoinedVoiceChannel, *_):
return x.joined_on return x.joined_on

Some files were not shown because too many files have changed in this diff Show More