Compare commits
37 Commits
55e9fc6eb5
...
85e664e642
Author | SHA1 | Date | |
---|---|---|---|
85e664e642 | |||
64985f5983 | |||
|
02ed6eb75b | ||
|
b615f2608f | ||
|
bf776177d4 | ||
|
a2a0056873 | ||
|
eb18fdea46 | ||
|
6945cd2eac | ||
ef040f2b91 | |||
ba4ef693da | |||
07f2c4921c | |||
96339ed168 | |||
9667f40730 | |||
5a9ad77761 | |||
e4d1e229eb | |||
299fc65d1f | |||
aa38623633 | |||
fd9d938b8a | |||
efbe6efc20 | |||
da3680a83e | |||
610ce42fa2 | |||
6149825101 | |||
7193e58ba1 | |||
38417bd712 | |||
43b6df2ba3 | |||
7d67b08ce6 | |||
afff27b273 | |||
de8262dae1 | |||
b96288f4a3 | |||
1ca6debc59 | |||
dfe4f28e24 | |||
fea259fa3b | |||
85452c9a74 | |||
f44f77d7e5 | |||
b15bcec20a | |||
ee351ee749 | |||
f847841582 |
@ -15,7 +15,7 @@ __title__ = "bot"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "dev130"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@ -19,7 +19,7 @@
|
||||
"cpl-core==2022.12.1.post3",
|
||||
"cpl-translation==2022.12.1",
|
||||
"cpl-query==2022.12.2.post1",
|
||||
"Flask==2.2.2",
|
||||
"Flask==2.2.3",
|
||||
"Flask-Classful==0.14.2",
|
||||
"Flask-Cors==3.0.10",
|
||||
"PyJWT==2.6.0",
|
||||
@ -41,15 +41,15 @@
|
||||
"BuildSettings": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"OutputPath": "..\\..\\dist",
|
||||
"Main": "bot.main",
|
||||
"EntryPoint": "bot",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
"*\\__pycache__",
|
||||
"*\\logs",
|
||||
"*\\tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": [
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit ac7046820f3410f55e779797126d9410c6bcdc9f
|
||||
Subproject commit eff27f42808909a816c37f31d81f085d59d4728c
|
@ -15,7 +15,7 @@ __title__ = "bot.extension"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -11,7 +11,6 @@ from modules.boot_log.boot_log_module import BootLogModule
|
||||
from modules.database.database_module import DatabaseModule
|
||||
from modules.level.level_module import LevelModule
|
||||
from modules.permission.permission_module import PermissionModule
|
||||
from modules.stats.stats_module import StatsModule
|
||||
from modules.technician.technician_module import TechnicianModule
|
||||
|
||||
|
||||
@ -31,7 +30,6 @@ class ModuleList:
|
||||
BaseModule,
|
||||
LevelModule,
|
||||
ApiModule,
|
||||
StatsModule,
|
||||
TechnicianModule,
|
||||
# has to be last!
|
||||
BootLogModule,
|
||||
|
@ -263,30 +263,6 @@
|
||||
},
|
||||
"database": {},
|
||||
"permission": {},
|
||||
"stats": {
|
||||
"list": {
|
||||
"statistic": "Statistik",
|
||||
"description": "Beschreibung",
|
||||
"nothing_found": "Keine Statistiken gefunden."
|
||||
},
|
||||
"view": {
|
||||
"statistic": "Statistik",
|
||||
"description": "Beschreibung",
|
||||
"failed": "Statistik kann nicht gezeigt werden :("
|
||||
},
|
||||
"add": {
|
||||
"failed": "Statistik kann nicht hinzugefügt werden :(",
|
||||
"success": "Statistik wurde hinzugefügt :D"
|
||||
},
|
||||
"edit": {
|
||||
"failed": "Statistik kann nicht bearbeitet werden :(",
|
||||
"success": "Statistik wurde gespeichert :D"
|
||||
},
|
||||
"remove": {
|
||||
"failed": "Statistik kann nicht gelöscht werden :(",
|
||||
"success": "Statistik wurde gelöscht :D"
|
||||
}
|
||||
},
|
||||
"technician": {
|
||||
"restart_message": "Bin gleich wieder da :D",
|
||||
"shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, Euer Freund. Lebt lange und in Frieden :)",
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-api",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "dev130"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 3c2a863022e6656927b9360875695a6bcdc70ac9
|
||||
Subproject commit c712f856ebe30c71ac0b144045599ed2f91a1cba
|
@ -15,7 +15,7 @@ __title__ = "bot_api.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.controller"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.event"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.exception"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.filter"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.filter.discord"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.logging"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -1,7 +1,10 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.abc.dto_abc import DtoABC
|
||||
from bot_api.model.user_dto import UserDTO
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
|
||||
|
||||
@ -15,6 +18,7 @@ class AuthUserDTO(DtoABC):
|
||||
password: str = None,
|
||||
confirmation_id: Optional[str] = None,
|
||||
auth_role: AuthRoleEnum = None,
|
||||
users: List[UserDTO] = None,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
):
|
||||
@ -30,6 +34,11 @@ class AuthUserDTO(DtoABC):
|
||||
self._created_at = created_at
|
||||
self._modified_at = modified_at
|
||||
|
||||
if users is None:
|
||||
self._users = List(UserDTO)
|
||||
else:
|
||||
self._users = users
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
@ -82,6 +91,10 @@ class AuthUserDTO(DtoABC):
|
||||
def auth_role(self, value: AuthRoleEnum):
|
||||
self._auth_role = value
|
||||
|
||||
@property
|
||||
def users(self) -> List[UserDTO]:
|
||||
return self._users
|
||||
|
||||
@property
|
||||
def created_at(self) -> datetime:
|
||||
return self._created_at
|
||||
@ -98,6 +111,12 @@ class AuthUserDTO(DtoABC):
|
||||
self._password = values["password"]
|
||||
self._is_confirmed = values["isConfirmed"]
|
||||
self._auth_role = AuthRoleEnum(values["authRole"])
|
||||
if "users" in values:
|
||||
self._users = List(UserDTO)
|
||||
for u in values["users"]:
|
||||
user = UserDTO()
|
||||
user.from_dict(u)
|
||||
self._users.add(user)
|
||||
|
||||
self._created_at = values["createdAt"]
|
||||
self._modified_at = values["modifiedAt"]
|
||||
@ -111,6 +130,7 @@ class AuthUserDTO(DtoABC):
|
||||
"password": self._password,
|
||||
"isConfirmed": self._is_confirmed,
|
||||
"authRole": self._auth_role.value,
|
||||
"users": self._users.select(lambda u: u.to_dict()).to_list(),
|
||||
"createdAt": self._created_at,
|
||||
"modifiedAt": self._modified_at,
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.model.discord"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
88
kdb-bot/src/bot_api/model/user_dto.py
Normal file
88
kdb-bot/src/bot_api/model/user_dto.py
Normal 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,
|
||||
}
|
@ -15,7 +15,7 @@ __title__ = "bot_api.route"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -2,7 +2,6 @@ from typing import Optional
|
||||
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from flask import jsonify
|
||||
|
||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||
from bot_api.exception.service_error_code_enum import ServiceErrorCode
|
||||
@ -10,7 +9,6 @@ from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.filter.discord.server_select_criteria import ServerSelectCriteria
|
||||
from bot_api.model.discord.server_dto import ServerDTO
|
||||
from bot_api.model.discord.server_filtered_result_dto import ServerFilteredResultDTO
|
||||
from bot_api.model.error_dto import ErrorDTO
|
||||
from bot_api.transformer.server_transformer import ServerTransformer
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
@ -35,7 +33,7 @@ class DiscordService:
|
||||
self._users = users
|
||||
|
||||
def _to_dto(self, x: Server) -> Optional[ServerDTO]:
|
||||
guild = self._bot.get_guild(x.discord_server_id)
|
||||
guild = self._bot.get_guild(x.discord_id)
|
||||
if guild is None:
|
||||
return ServerTransformer.to_dto(x, "", 0, None)
|
||||
|
||||
@ -55,8 +53,8 @@ class DiscordService:
|
||||
if role != AuthRoleEnum.admin:
|
||||
auth_user = self._auth_users.find_auth_user_by_email(token["email"])
|
||||
if auth_user is not None:
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id)
|
||||
servers = servers.where(lambda x: x.server_id in user_ids)
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.id)
|
||||
servers = servers.where(lambda x: x.id in user_ids)
|
||||
|
||||
servers = List(ServerDTO, servers)
|
||||
return servers.select(self._to_dto).where(lambda x: x.name != "")
|
||||
@ -72,8 +70,8 @@ class DiscordService:
|
||||
if role != AuthRoleEnum.admin:
|
||||
auth_user = self._auth_users.find_auth_user_by_email(token["email"])
|
||||
if auth_user is not None:
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id)
|
||||
filtered_result.result = filtered_result.result.where(lambda x: x.server_id in user_ids)
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.id)
|
||||
filtered_result.result = filtered_result.result.where(lambda x: x.id in user_ids)
|
||||
|
||||
servers: List = filtered_result.result.select(self._to_dto).where(lambda x: x.name != "")
|
||||
result = List(ServerDTO, servers)
|
||||
@ -87,7 +85,7 @@ class DiscordService:
|
||||
|
||||
async def get_server_by_id_async(self, id: int) -> ServerDTO:
|
||||
server = self._servers.get_server_by_id(id)
|
||||
guild = self._bot.get_guild(server.discord_server_id)
|
||||
guild = self._bot.get_guild(server.discord_id)
|
||||
|
||||
server_dto = ServerTransformer.to_dto(server, guild.name, guild.member_count, guild.icon)
|
||||
return server_dto
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.transformer"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -1,9 +1,16 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_api.abc.transformer_abc import TransformerABC
|
||||
from bot_api.model.auth_user_dto import AuthUserDTO
|
||||
from bot_api.model.user_dto import UserDTO
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.auth_user import AuthUser
|
||||
from bot_data.model.user import User
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class AuthUserTransformer(TransformerABC):
|
||||
@ -25,7 +32,28 @@ class AuthUserTransformer(TransformerABC):
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_dto(db: AuthUser, password: str = None) -> AuthUserDTO:
|
||||
@ServiceProviderABC.inject
|
||||
def _is_technician(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_technician(member)
|
||||
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _is_admin(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_admin(member)
|
||||
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _is_moderator(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_moderator(member)
|
||||
|
||||
@classmethod
|
||||
def to_dto(cls, db: AuthUser, password: str = None) -> AuthUserDTO:
|
||||
return AuthUserDTO(
|
||||
db.id,
|
||||
db.first_name,
|
||||
@ -34,6 +62,21 @@ class AuthUserTransformer(TransformerABC):
|
||||
"" if password is None else password,
|
||||
db.confirmation_id,
|
||||
db.auth_role,
|
||||
List(
|
||||
UserDTO,
|
||||
db.users.select(
|
||||
lambda u: UserDTO(
|
||||
u.id,
|
||||
u.discord_id,
|
||||
u.xp,
|
||||
u.minecraft_id,
|
||||
u.server,
|
||||
cls._is_technician(u),
|
||||
cls._is_admin(u),
|
||||
cls._is_moderator(u),
|
||||
)
|
||||
),
|
||||
),
|
||||
db.created_at,
|
||||
db.modified_at,
|
||||
)
|
||||
|
@ -15,8 +15,8 @@ class ServerTransformer(TransformerABC):
|
||||
@staticmethod
|
||||
def to_dto(db: Server, name: str, member_count: int, icon_url: Optional[discord.Asset]) -> ServerDTO:
|
||||
return ServerDTO(
|
||||
db.server_id,
|
||||
db.discord_server_id,
|
||||
db.id,
|
||||
db.discord_id,
|
||||
name,
|
||||
member_count,
|
||||
icon_url.url if icon_url is not None else None,
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-core",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "dev130"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.core_extension"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.events"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.exception"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.helper"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.logging"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.pipes"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -60,28 +60,28 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
def received_command(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.received_command_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def moved_user(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.moved_users_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def moved_users(self, guild_id: int, count: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.moved_users_count += count
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def get_client(self, dc_ic: int, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
return client
|
||||
|
||||
async def check_if_bot_is_ready_yet(self) -> bool:
|
||||
@ -138,7 +138,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
) -> bool:
|
||||
umcph = None
|
||||
try:
|
||||
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.user_id, created_at)
|
||||
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||
if umcph is None:
|
||||
self._umcphs.add_user_message_count_per_hour(
|
||||
UserMessageCountPerHour(
|
||||
@ -151,7 +151,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
self._db.save_changes()
|
||||
|
||||
umcph = self._umcphs.get_user_message_count_per_hour_by_user_id_and_date(user.user_id, created_at)
|
||||
umcph = self._umcphs.get_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||
except Exception as e:
|
||||
self._logger.error(
|
||||
__name__,
|
||||
@ -183,7 +183,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
def get_ontime_for_user(self, user: User) -> float:
|
||||
return round(
|
||||
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.user_id)
|
||||
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.id)
|
||||
.where(lambda x: x.leaved_on is not None and x.joined_on is not None)
|
||||
.sum(lambda join: (join.leaved_on - join.joined_on).total_seconds() / 3600),
|
||||
2,
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -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
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-data",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "3",
|
||||
"Micro": "1"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "dev130"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@ -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.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
|
||||
from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import (
|
||||
@ -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.seeder_service import SeederService
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
from bot_data.service.statistic_repository_service import StatisticRepositoryService
|
||||
from bot_data.service.user_joined_game_server_repository_service import UserJoinedGameServerRepositoryService
|
||||
from bot_data.service.user_joined_server_repository_service import (
|
||||
UserJoinedServerRepositoryService,
|
||||
@ -63,7 +61,6 @@ class DataModule(ModuleABC):
|
||||
services.add_transient(UserJoinedGameServerRepositoryABC, UserJoinedGameServerRepositoryService)
|
||||
services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService)
|
||||
services.add_transient(LevelRepositoryABC, LevelRepositoryService)
|
||||
services.add_transient(StatisticRepositoryABC, StatisticRepositoryService)
|
||||
services.add_transient(
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
UserMessageCountPerHourRepositoryService,
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.migration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class StatsMigration(MigrationABC):
|
||||
name = "0.3_StatsMigration"
|
||||
name = "1.0_RemoveStatsMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
@ -18,20 +18,26 @@ class StatsMigration(MigrationABC):
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Statistics` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`Code` LONGTEXT NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
DROP TABLE IF EXISTS `Statistics`;
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `Statistics`;")
|
||||
self._cursor.execute(
|
||||
str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `Statistics` (
|
||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`Code` LONGTEXT NOT NULL,
|
||||
`ServerId` BIGINT,
|
||||
`CreatedAt` DATETIME(6),
|
||||
`LastModifiedAt` DATETIME(6),
|
||||
PRIMARY KEY(`Id`),
|
||||
FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`)
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -73,7 +73,7 @@ class ApiKey(TableABC):
|
||||
) VALUES (
|
||||
'{self._identifier}',
|
||||
'{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._modified_at}'
|
||||
);
|
||||
|
@ -42,6 +42,8 @@ class AuthUser(TableABC):
|
||||
|
||||
if users is None:
|
||||
self._users = List(User)
|
||||
else:
|
||||
self._users = users
|
||||
|
||||
self._auth_role_id = auth_role
|
||||
|
||||
@ -250,10 +252,10 @@ class AuthUser(TableABC):
|
||||
`EMail` = '{self._email}',
|
||||
`Password` = '{self._password}',
|
||||
`PasswordSalt` = '{self._password_salt}',
|
||||
`RefreshToken` = '{"NULL" if self._refresh_token is None else self._refresh_token}',
|
||||
`ConfirmationId` = '{"NULL" if self._confirmation_id is None else self._confirmation_id}',
|
||||
`ForgotPasswordId` = '{"NULL" if self._forgot_password_id is None else self._forgot_password_id}',
|
||||
`OAuthId` = '{"NULL" if self._oauth_id is None else self._oauth_id}',
|
||||
`RefreshToken` = '{'null' if self._refresh_token is None else f'{self._refresh_token}'}',
|
||||
`ConfirmationId` = '{'null' if self._confirmation_id is None else f'{self._confirmation_id}'}',
|
||||
`ForgotPasswordId` = '{'null' if self._forgot_password_id is None else f'{self._forgot_password_id}'}',
|
||||
`OAuthId` = '{'null' if self._oauth_id is None else f'{self._oauth_id}'}',
|
||||
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
||||
`AuthRole` = {self._auth_role_id.value},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
|
@ -71,7 +71,7 @@ class AuthUserUsersRelation(TableABC):
|
||||
`AuthUserId`, `UserId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._auth_user.id},
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
@ -84,10 +84,10 @@ class AuthUserUsersRelation(TableABC):
|
||||
f"""
|
||||
UPDATE `AuthUserUsersRelations`
|
||||
SET `AuthUserId` = '{self._auth_user.id}',,
|
||||
`UserId` = '{self._user.user_id}'
|
||||
`UserId` = '{self._user.id}'
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
||||
@ -97,6 +97,6 @@ class AuthUserUsersRelation(TableABC):
|
||||
f"""
|
||||
DELETE FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
@ -2,6 +2,8 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
@ -10,7 +12,7 @@ class AutoRole(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
server: Optional[Server],
|
||||
dc_channel_id: int,
|
||||
channel_id: int,
|
||||
dc_message_id: int,
|
||||
created_at: datetime = None,
|
||||
modified_at: datetime = None,
|
||||
@ -18,7 +20,7 @@ class AutoRole(TableABC):
|
||||
):
|
||||
self._auto_role_id = id
|
||||
self._server = server
|
||||
self._discord_channel_id = dc_channel_id
|
||||
self._discord_channel_id = channel_id
|
||||
self._discord_message_id = dc_message_id
|
||||
|
||||
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
|
||||
|
||||
@property
|
||||
def auto_role_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._auto_role_id
|
||||
|
||||
@property
|
||||
@ -41,6 +43,12 @@ class AutoRole(TableABC):
|
||||
def discord_channel_id(self, value: int):
|
||||
self._discord_channel_id = value
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def discord_channel_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
channel = bot.get_channel(self.discord_channel_id)
|
||||
return None if channel is None else channel.name
|
||||
|
||||
@property
|
||||
def discord_message_id(self) -> int:
|
||||
return self._discord_message_id
|
||||
@ -91,7 +99,7 @@ class AutoRole(TableABC):
|
||||
INSERT INTO `AutoRoles` (
|
||||
`ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
{self._discord_channel_id},
|
||||
{self._discord_message_id},
|
||||
'{self._created_at}',
|
||||
@ -105,7 +113,7 @@ class AutoRole(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoles`
|
||||
SET `ServerId` = {self._server.server_id},
|
||||
SET `ServerId` = {self._server.id},
|
||||
`DiscordChannelId` = {self._discord_channel_id},
|
||||
`DiscordMessageId` = {self._discord_message_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
|
@ -1,6 +1,8 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.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
|
||||
|
||||
@property
|
||||
def auto_role_rule_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._auto_role_rule_id
|
||||
|
||||
@property
|
||||
@ -44,6 +46,12 @@ class AutoRoleRule(TableABC):
|
||||
def role_id(self) -> int:
|
||||
return self._discord_role_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def role_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.auto_role.server.discord_id)
|
||||
return guild.get_role(self.role_id).name
|
||||
|
||||
@role_id.setter
|
||||
def role_id(self, value: int):
|
||||
self._discord_role_id = value
|
||||
|
@ -1,5 +1,8 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
|
||||
@ -32,13 +35,18 @@ class Client(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def client_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._client_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_client_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
return bot.user.name
|
||||
|
||||
@property
|
||||
def sent_message_count(self) -> int:
|
||||
return self._sent_message_count
|
||||
@ -154,7 +162,7 @@ class Client(TableABC):
|
||||
{self._deleted_message_count},
|
||||
{self._received_message_count},
|
||||
{self._moved_users_count},
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@ -19,7 +19,7 @@ class KnownUser(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def known_user_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._known_user_id
|
||||
|
||||
@property
|
||||
|
@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
@ -114,7 +115,7 @@ class Level(TableABC):
|
||||
'{self._color}',
|
||||
{self._min_xp},
|
||||
{self._permissions},
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@ -1,7 +1,8 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
|
||||
class Server(TableABC):
|
||||
@ -20,13 +21,25 @@ class Server(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._server_id
|
||||
|
||||
@property
|
||||
def discord_server_id(self) -> int:
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_server_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.name
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def icon_url(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.icon.url
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
|
@ -1,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};
|
||||
"""
|
||||
)
|
@ -2,7 +2,10 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.level import Level
|
||||
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
|
||||
|
||||
@property
|
||||
def user_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._user_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.server.discord_id)
|
||||
user = guild.get_member(self.discord_id)
|
||||
return None if user is None else user.name
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def icon_url(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.server.discord_id)
|
||||
user = guild.get_member(self.discord_id)
|
||||
return None if user is None else user.display_icon
|
||||
|
||||
@property
|
||||
def xp(self) -> int:
|
||||
return self._xp
|
||||
@ -44,6 +61,22 @@ class User(TableABC):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._xp = value
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def ontime(self, services: ServiceProviderABC) -> float:
|
||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
|
||||
client_utils: ClientUtilsABC = services.get_service(ClientUtilsABC)
|
||||
return client_utils.get_ontime_for_user(self)
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def level(self, services: ServiceProviderABC) -> Level:
|
||||
from modules.level.service.level_service import LevelService
|
||||
|
||||
levels: LevelService = services.get_service(LevelService)
|
||||
return levels.get_level(self)
|
||||
|
||||
@property
|
||||
def minecraft_id(self) -> Optional[str]:
|
||||
return self._minecraft_id
|
||||
@ -56,6 +89,17 @@ class User(TableABC):
|
||||
def server(self) -> Optional[Server]:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def left_server(
|
||||
self,
|
||||
services: ServiceProviderABC,
|
||||
) -> bool:
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
|
||||
ujs: UserJoinedServerRepositoryABC = services.get_service(UserJoinedServerRepositoryABC)
|
||||
return ujs.find_active_user_joined_server_by_user_id(self.id) is None
|
||||
|
||||
@staticmethod
|
||||
def get_select_all_string() -> str:
|
||||
return str(
|
||||
@ -110,8 +154,8 @@ class User(TableABC):
|
||||
) VALUES (
|
||||
{self._discord_id},
|
||||
{self._xp},
|
||||
'{"NULL" if self._minecraft_id is None else self._minecraft_id}',
|
||||
{self._server.server_id},
|
||||
'{self._minecraft_id}',
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
@ -124,7 +168,7 @@ class User(TableABC):
|
||||
f"""
|
||||
UPDATE `Users`
|
||||
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}'
|
||||
WHERE `UserId` = {self._user_id};
|
||||
"""
|
||||
|
@ -38,6 +38,10 @@ class UserJoinedGameServer(TableABC):
|
||||
def game_server(self) -> str:
|
||||
return self._game_server
|
||||
|
||||
@property
|
||||
def time(self) -> float:
|
||||
return round((self.leaved_on - self.joined_on).total_seconds() / 3600, 2)
|
||||
|
||||
@property
|
||||
def joined_on(self) -> datetime:
|
||||
return self._joined_on
|
||||
@ -100,7 +104,7 @@ class UserJoinedGameServer(TableABC):
|
||||
INSERT INTO `UserJoinedGameServer` (
|
||||
`UserId`, `GameServer`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._game_server}',
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
@ -115,7 +119,7 @@ class UserJoinedGameServer(TableABC):
|
||||
INSERT INTO `UserJoinedGameServer` (
|
||||
`UserId`, `GameServer`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._game_server}',
|
||||
'{self._joined_on}',
|
||||
'{self._created_at}',
|
||||
|
@ -25,7 +25,7 @@ class UserJoinedServer(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._join_id
|
||||
|
||||
@property
|
||||
@ -103,7 +103,7 @@ class UserJoinedServer(TableABC):
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
'{self._created_at}',
|
||||
@ -117,7 +117,7 @@ class UserJoinedServer(TableABC):
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._joined_on}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
@ -132,7 +132,7 @@ class UserJoinedServer(TableABC):
|
||||
UPDATE `UserJoinedServers`
|
||||
SET `LeavedOn` = '{self._leaved_on}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `UserId` = {self._user.user_id};
|
||||
WHERE `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.model.user import User
|
||||
|
||||
@ -9,7 +11,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
def __init__(
|
||||
self,
|
||||
user: User,
|
||||
dc_channel_id: int,
|
||||
channel_id: int,
|
||||
joined_on: datetime,
|
||||
leaved_on: datetime = None,
|
||||
created_at: datetime = None,
|
||||
@ -17,7 +19,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
id=0,
|
||||
):
|
||||
self._join_id = id
|
||||
self._dc_channel_id = dc_channel_id
|
||||
self._channel_id = channel_id
|
||||
self._user = user
|
||||
self._joined_on = joined_on
|
||||
self._leaved_on = leaved_on
|
||||
@ -27,17 +29,26 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._join_id
|
||||
|
||||
@property
|
||||
def dc_channel_id(self) -> int:
|
||||
return self._dc_channel_id
|
||||
def channel_id(self) -> int:
|
||||
return self._channel_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def channel_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
return bot.get_channel(self.channel_id).name
|
||||
|
||||
@property
|
||||
def user(self) -> User:
|
||||
return self._user
|
||||
|
||||
@property
|
||||
def time(self) -> float:
|
||||
return round((self.leaved_on - self.joined_on).total_seconds() / 3600, 2)
|
||||
|
||||
@property
|
||||
def joined_on(self) -> datetime:
|
||||
return self._joined_on
|
||||
@ -100,8 +111,8 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._dc_channel_id},
|
||||
{self._user.id},
|
||||
{self._channel_id},
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
'{self._created_at}',
|
||||
@ -115,8 +126,8 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._dc_channel_id},
|
||||
{self._user.id},
|
||||
{self._channel_id},
|
||||
'{self._joined_on}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
|
@ -97,7 +97,7 @@ class UserMessageCountPerHour(TableABC):
|
||||
INSERT INTO `UserMessageCountPerHour` (
|
||||
`UserId`, `Date`, `Hour`, `XPCount`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._date}',
|
||||
{self._hour},
|
||||
{self._xp_count},
|
||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "0.3.1"
|
||||
__version__ = "1.0.dev130"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="3", micro="1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -28,7 +28,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
||||
|
||||
@staticmethod
|
||||
def _get_value_from_result(value: any) -> Optional[any]:
|
||||
if isinstance(value, str) and "NULL" in value:
|
||||
if isinstance(value, str) and "null" in value:
|
||||
return None
|
||||
|
||||
return value
|
||||
|
@ -193,9 +193,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._logger.warn(__name__, f"Cannot find server by id {server_id}")
|
||||
raise Exception("Value not found")
|
||||
|
||||
client = self.find_client_by_discord_id_and_server_id(id, server.server_id)
|
||||
client = self.find_client_by_discord_id_and_server_id(id, server.id)
|
||||
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")
|
||||
|
||||
return client
|
||||
|
@ -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)
|
@ -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
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="dev130")
|
||||
|
@ -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")
|
@ -75,9 +75,9 @@ class QueryABC(ObjectType):
|
||||
element: AutoRole = element
|
||||
for u in user.users:
|
||||
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)
|
||||
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
|
||||
break
|
||||
|
||||
@ -85,23 +85,23 @@ class QueryABC(ObjectType):
|
||||
element: AutoRole = element.auto_role
|
||||
for u in user.users:
|
||||
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)
|
||||
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
|
||||
break
|
||||
|
||||
elif type(element) == Client:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.server.server_id == element.server.server_id:
|
||||
if u.server.id == element.server.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == KnownUser:
|
||||
for u in user.users:
|
||||
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)
|
||||
if permissions.is_member_moderator(member):
|
||||
access = True
|
||||
@ -110,42 +110,42 @@ class QueryABC(ObjectType):
|
||||
elif type(element) == Level:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.server.server_id == element.server.server_id:
|
||||
if u.server.id == element.server.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == Server:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.server.server_id == element.server_id:
|
||||
if u.server.id == element.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == User:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user_id:
|
||||
if u.id == element.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == UserJoinedServer:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user.user_id:
|
||||
if u.id == element.user.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == UserJoinedVoiceChannel:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user.user_id:
|
||||
if u.id == element.user.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == UserJoinedGameServer:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user.user_id:
|
||||
if u.id == element.user.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
@ -160,8 +160,8 @@ class QueryABC(ObjectType):
|
||||
if auth_user == "system" or auth_user.auth_role == AuthRoleEnum.admin:
|
||||
return
|
||||
|
||||
member = bot.get_guild(server.discord_server_id).get_member(
|
||||
auth_user.users.where(lambda x: x.server.server_id == server.server_id).single().discord_id
|
||||
member = bot.get_guild(server.discord_id).get_member(
|
||||
auth_user.users.where(lambda x: x.server.id == server.id).single().discord_id
|
||||
)
|
||||
|
||||
check_perm = lambda x: True
|
||||
@ -180,12 +180,12 @@ class QueryABC(ObjectType):
|
||||
# @FilterABC.resolve_filter_annotation
|
||||
def _resolve_collection(self, collection: List, *_, filter: FilterABC = None, page: Page = None, sort: Sort = None):
|
||||
if filter is not None:
|
||||
return filter.filter(collection)
|
||||
collection = filter.filter(collection)
|
||||
|
||||
if page is not None:
|
||||
return page.filter(collection)
|
||||
collection = page.filter(collection)
|
||||
|
||||
if sort is not None:
|
||||
return sort.filter(collection)
|
||||
collection = sort.filter(collection)
|
||||
|
||||
return collection
|
||||
|
@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-data",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "1",
|
||||
"Micro": "0"
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "dev130"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@ -16,10 +16,10 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.1"
|
||||
"cpl-core>=1.0.dev130"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.12.1"
|
||||
"cpl-cli>=1.0.dev130"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@ -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")
|
@ -42,7 +42,7 @@ class AutoRoleFilter(FilterABC):
|
||||
|
||||
def filter(self, query: List[AutoRole]) -> List[AutoRole]:
|
||||
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:
|
||||
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)
|
||||
|
||||
if self._server is not None:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.server.id in servers)
|
||||
|
||||
return query
|
||||
|
@ -39,7 +39,7 @@ class AutoRoleRuleFilter(FilterABC):
|
||||
|
||||
def filter(self, query: List[AutoRoleRule]) -> List[AutoRoleRule]:
|
||||
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:
|
||||
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:
|
||||
|
||||
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
|
||||
return name == self._role_name or self._role_name in name
|
||||
|
||||
query = query.where(get_role_name)
|
||||
|
||||
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)
|
||||
query = query.where(lambda x: x.auto_role.auto_role_id in auto_roles)
|
||||
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.id in auto_roles)
|
||||
|
||||
return query
|
||||
|
@ -32,16 +32,16 @@ class ClientFilter(FilterABC):
|
||||
|
||||
def filter(self, query: List[Client]) -> List[Client]:
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.server.id in servers)
|
||||
|
||||
return query
|
||||
|
@ -25,7 +25,7 @@ class LevelFilter(FilterABC):
|
||||
if "server" in values:
|
||||
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"])
|
||||
|
||||
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())
|
||||
|
||||
if self._server is not None:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.server.id in servers)
|
||||
|
||||
return query
|
||||
|
@ -28,15 +28,17 @@ class ServerFilter(FilterABC):
|
||||
@ServiceProviderABC.inject
|
||||
def filter(self, query: List[Server], bot: DiscordBotServiceABC) -> List[Server]:
|
||||
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:
|
||||
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:
|
||||
|
||||
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 (
|
||||
self._name.lower() == guild.name.lower() or self._name.lower() in guild.name.lower()
|
||||
)
|
||||
|
@ -1,3 +1,6 @@
|
||||
import functools
|
||||
|
||||
from cpl_core.utils import String
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_graphql.abc.filter_abc import FilterABC
|
||||
@ -6,6 +9,7 @@ from bot_graphql.abc.filter_abc import FilterABC
|
||||
class Sort(FilterABC):
|
||||
def __init__(self):
|
||||
FilterABC.__init__(self)
|
||||
|
||||
self._sort_direction = None
|
||||
self._sort_column = None
|
||||
|
||||
@ -16,5 +20,27 @@ class Sort(FilterABC):
|
||||
if "sortColumn" in values:
|
||||
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:
|
||||
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
|
||||
|
@ -5,6 +5,7 @@ from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
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_graphql.abc.filter_abc import FilterABC
|
||||
from bot_graphql.filter.level_filter import LevelFilter
|
||||
@ -18,6 +19,7 @@ class UserFilter(FilterABC):
|
||||
bot: DiscordBotServiceABC,
|
||||
client_utils: ClientUtilsABC,
|
||||
levels: LevelService,
|
||||
user_joined_servers: UserJoinedServerRepositoryABC,
|
||||
):
|
||||
FilterABC.__init__(self)
|
||||
|
||||
@ -25,6 +27,7 @@ class UserFilter(FilterABC):
|
||||
self._bot = bot
|
||||
self._client_utils = client_utils
|
||||
self._levels = levels
|
||||
self._user_joined_servers = user_joined_servers
|
||||
|
||||
self._id = None
|
||||
self._discord_id = None
|
||||
@ -34,6 +37,7 @@ class UserFilter(FilterABC):
|
||||
self._ontime = None
|
||||
self._level: Optional[LevelFilter] = None
|
||||
self._server = None
|
||||
self._left_server = None
|
||||
|
||||
def from_dict(self, values: dict):
|
||||
if "id" in values:
|
||||
@ -64,18 +68,26 @@ class UserFilter(FilterABC):
|
||||
self._server: ServerFilter = self._services.get_service(ServerFilter)
|
||||
self._server.from_dict(values["server"])
|
||||
|
||||
if "leftServer" in values:
|
||||
self._left_server = values["leftServer"]
|
||||
|
||||
def filter(self, query: List[User]) -> List[User]:
|
||||
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:
|
||||
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:
|
||||
query = query.where(
|
||||
lambda x: self._bot.get_user(x.discord_id).name == self._name
|
||||
or self._name in self._bot.get_user(x.discord_id).name
|
||||
)
|
||||
|
||||
def _get_member(user: User):
|
||||
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:
|
||||
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)
|
||||
|
||||
if self._server is not None:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
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
|
||||
|
@ -42,7 +42,7 @@ class UserJoinedGameServerFilter(FilterABC):
|
||||
query = query.where(lambda x: x.game_server == self._game_server)
|
||||
|
||||
if self._user is not None:
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id)
|
||||
query = query.where(lambda x: x.user.user_id in users)
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.user.id in users)
|
||||
|
||||
return query
|
||||
|
@ -43,8 +43,8 @@ class UserJoinedServerFilter(FilterABC):
|
||||
query = query.where(lambda x: x.id == self._id)
|
||||
|
||||
if self._user is not None:
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id)
|
||||
query = query.where(lambda x: x.user.user_id in users)
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.user.id in users)
|
||||
|
||||
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)
|
||||
|
@ -51,19 +51,19 @@ class UserJoinedVoiceChannelFilter(FilterABC):
|
||||
query = query.where(lambda x: x.id == self._id)
|
||||
|
||||
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:
|
||||
|
||||
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
|
||||
|
||||
query = query.where(get_channel_name)
|
||||
|
||||
if self._user is not None:
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id)
|
||||
query = query.where(lambda x: x.user.user_id in users)
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.user.id in users)
|
||||
|
||||
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)
|
||||
|
@ -9,6 +9,11 @@ input Page {
|
||||
}
|
||||
|
||||
input Sort {
|
||||
sortDirection: String
|
||||
sortDirection: SortDirection
|
||||
sortColumn: String
|
||||
}
|
||||
|
||||
enum SortDirection {
|
||||
ASC
|
||||
DESC
|
||||
}
|
@ -17,6 +17,7 @@ type User implements TableQuery {
|
||||
userJoinedGameServers(filter: UserJoinedGameServerFilter, page: Page, sort: Sort): [UserJoinedGameServer]
|
||||
|
||||
server: Server
|
||||
leftServer: Boolean
|
||||
|
||||
createdAt: String
|
||||
modifiedAt: String
|
||||
@ -31,6 +32,7 @@ input UserFilter {
|
||||
ontime: Float
|
||||
level: LevelFilter
|
||||
server: ServerFilter
|
||||
leftServer: Boolean
|
||||
}
|
||||
|
||||
type UserMutation {
|
||||
@ -40,4 +42,5 @@ type UserMutation {
|
||||
input UserInput {
|
||||
id: ID
|
||||
xp: Int
|
||||
levelId: ID
|
||||
}
|
@ -2,6 +2,7 @@ type UserJoinedGameServer implements TableQuery {
|
||||
id: ID
|
||||
gameServer: String
|
||||
user: User
|
||||
time: Float
|
||||
joinedOn: String
|
||||
leavedOn: String
|
||||
|
||||
|
@ -3,6 +3,7 @@ type UserJoinedVoiceChannel implements TableQuery {
|
||||
channelId: String
|
||||
channelName: String
|
||||
user: User
|
||||
time: Float
|
||||
joinedOn: String
|
||||
leavedOn: String
|
||||
|
||||
|
@ -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")
|
@ -33,12 +33,12 @@ class AutoRoleMutation(QueryABC):
|
||||
|
||||
def get_new(x: AutoRole):
|
||||
return (
|
||||
x.server.server_id == input["serverId"]
|
||||
x.server.id == input["serverId"]
|
||||
and x.discord_channel_id == input["channelId"]
|
||||
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):
|
||||
auto_role = self._auto_roles.get_auto_role_by_id(input["id"])
|
||||
|
@ -35,16 +35,12 @@ class AutoRoleRuleMutation(QueryABC):
|
||||
|
||||
def get_new(x: AutoRoleRule):
|
||||
return (
|
||||
x.auto_role.auto_role_id == input["autoRoleId"]
|
||||
x.auto_role.id == input["autoRoleId"]
|
||||
and x.emoji_name == input["emojiName"]
|
||||
and x.role_id == input["roleId"]
|
||||
)
|
||||
|
||||
return (
|
||||
self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.auto_role_id)
|
||||
.where(get_new)
|
||||
.last()
|
||||
)
|
||||
return self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.id).where(get_new).last()
|
||||
|
||||
def resolve_update_auto_role_rule(self, *_, input: dict):
|
||||
auto_role_rule = self._auto_roles.get_auto_role_rule_by_id(input["id"])
|
||||
|
@ -46,7 +46,7 @@ class LevelMutation(QueryABC):
|
||||
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):
|
||||
level = self._levels.get_level_by_id(input["id"])
|
||||
|
@ -45,11 +45,11 @@ class UserJoinedGameServerMutation(QueryABC):
|
||||
user = self._users.get_user_by_id(input["userId"])
|
||||
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:
|
||||
self._logger.debug(
|
||||
__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
|
||||
|
||||
@ -57,18 +57,18 @@ class UserJoinedGameServerMutation(QueryABC):
|
||||
self._user_joined_game_servers.add_user_joined_game_server(new)
|
||||
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):
|
||||
user = self._users.get_user_by_id(input["userId"])
|
||||
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:
|
||||
return None
|
||||
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)
|
||||
old_xp = user.xp
|
||||
|
@ -1,10 +1,12 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
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.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from modules.level.service.level_service import LevelService
|
||||
from modules.permission.service.permission_service import PermissionService
|
||||
|
||||
|
||||
@ -16,6 +18,8 @@ class UserMutation(QueryABC):
|
||||
bot: DiscordBotServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionService,
|
||||
levels: LevelRepositoryABC,
|
||||
level_service: LevelService,
|
||||
):
|
||||
QueryABC.__init__(self, "UserMutation")
|
||||
|
||||
@ -24,6 +28,8 @@ class UserMutation(QueryABC):
|
||||
self._bot = bot
|
||||
self._db = db
|
||||
self._permissions = permissions
|
||||
self._levels = levels
|
||||
self._level_service = level_service
|
||||
|
||||
self.set_field("updateUser", self.resolve_update_user)
|
||||
|
||||
@ -31,10 +37,15 @@ class UserMutation(QueryABC):
|
||||
user = self._users.get_user_by_id(input["id"])
|
||||
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
|
||||
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
self._bot.loop.create_task(self._level_service.set_level(user))
|
||||
|
||||
user = self._users.get_user_by_id(input["id"])
|
||||
return user
|
||||
|
@ -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")
|
@ -28,21 +28,21 @@ class AutoRoleQuery(DataQueryABC):
|
||||
self.set_field("server", self.resolve_server)
|
||||
self.add_collection(
|
||||
"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,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: AutoRole, *_):
|
||||
return x.auto_role_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_channel_id(x: AutoRole, *_):
|
||||
return x.discord_channel_id
|
||||
|
||||
def resolve_channel_name(self, x: AutoRole, *_):
|
||||
channel = self._bot.get_channel(x.discord_channel_id)
|
||||
return None if channel is None else channel.name
|
||||
@staticmethod
|
||||
def resolve_channel_name(x: AutoRole, *_):
|
||||
return x.discord_channel_name
|
||||
|
||||
@staticmethod
|
||||
def resolve_message_id(x: AutoRole, *_):
|
||||
@ -50,6 +50,6 @@ class AutoRoleQuery(DataQueryABC):
|
||||
|
||||
def resolve_server(self, x: AutoRole, *_, filter: ServerFilter = 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)
|
||||
|
@ -24,7 +24,7 @@ class AutoRoleRuleQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: AutoRoleRule, *_):
|
||||
return x.auto_role_rule_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_emoji_name(x: AutoRoleRule, *_):
|
||||
@ -34,9 +34,9 @@ class AutoRoleRuleQuery(DataQueryABC):
|
||||
def resolve_role_id(x: AutoRoleRule, *_):
|
||||
return x.role_id
|
||||
|
||||
def resolve_role_name(self, x: AutoRoleRule, *_):
|
||||
guild = self._bot.get_guild(x.auto_role.server.discord_server_id)
|
||||
return guild.get_role(x.role_id).name
|
||||
@staticmethod
|
||||
def resolve_role_name(x: AutoRoleRule, *_):
|
||||
return x.role_name
|
||||
|
||||
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)
|
||||
|
@ -25,14 +25,15 @@ class ClientQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(client: Client, *_):
|
||||
return client.client_id
|
||||
return client.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(client: Client, *_):
|
||||
return client.discord_id
|
||||
|
||||
def resolve_name(self, client: Client, *_):
|
||||
return self._bot.user.name
|
||||
@staticmethod
|
||||
def resolve_name(client: Client, *_):
|
||||
return client.name
|
||||
|
||||
@staticmethod
|
||||
def resolve_sent_message_count(client: Client, *_):
|
||||
|
@ -11,7 +11,7 @@ class KnownUserQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: KnownUser, *_):
|
||||
return x.known_user_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(x: KnownUser, *_):
|
||||
|
@ -42,29 +42,27 @@ class ServerQuery(DataQueryABC):
|
||||
|
||||
self.add_collection(
|
||||
"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,
|
||||
)
|
||||
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(
|
||||
"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.server_id), UserFilter)
|
||||
self.add_collection("level", lambda server, *_: self._levels.get_levels_by_server_id(server.id), LevelFilter)
|
||||
self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.id), UserFilter)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(server: Server, *_):
|
||||
return server.server_id
|
||||
return server.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(server: Server, *_):
|
||||
return server.discord_server_id
|
||||
return server.discord_id
|
||||
|
||||
def resolve_name(self, server: Server, *_):
|
||||
guild = self._bot.get_guild(server.discord_server_id)
|
||||
return None if guild is None else guild.name
|
||||
@staticmethod
|
||||
def resolve_name(server: Server, *_):
|
||||
return server.name
|
||||
|
||||
def resolve_icon_url(self, server: Server, *_):
|
||||
guild = self._bot.get_guild(server.discord_server_id)
|
||||
return None if guild is None else guild.icon.url
|
||||
@staticmethod
|
||||
def resolve_icon_url(server: Server, *_):
|
||||
return server.icon_url
|
||||
|
@ -28,6 +28,10 @@ class UserJoinedGameServerQuery(DataQueryABC):
|
||||
def resolve_user(x: UserJoinedGameServer, *_):
|
||||
return x.user
|
||||
|
||||
@staticmethod
|
||||
def resolve_time(x: UserJoinedGameServer, *_):
|
||||
return x.time
|
||||
|
||||
@staticmethod
|
||||
def resolve_joined_on(x: UserJoinedGameServer, *_):
|
||||
return x.joined_on
|
||||
|
@ -13,7 +13,7 @@ class UserJoinedServerQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: UserJoinedServer, *_):
|
||||
return x.join_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_user(x: UserJoinedServer, *_):
|
||||
|
@ -14,24 +14,30 @@ class UserJoinedVoiceChannelQuery(DataQueryABC):
|
||||
self.set_field("channelId", self.resolve_channel_id)
|
||||
self.set_field("channelName", self.resolve_channel_name)
|
||||
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("leavedOn", self.resolve_leaved_on)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: UserJoinedVoiceChannel, *_):
|
||||
return x.join_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_channel_id(x: UserJoinedVoiceChannel, *_):
|
||||
return x.dc_channel_id
|
||||
return x.channel_id
|
||||
|
||||
def resolve_channel_name(self, x: UserJoinedVoiceChannel, *_):
|
||||
return self._bot.get_channel(x.dc_channel_id).name
|
||||
@staticmethod
|
||||
def resolve_channel_name(x: UserJoinedVoiceChannel, *_):
|
||||
return x.channel_name
|
||||
|
||||
@staticmethod
|
||||
def resolve_user(x: UserJoinedVoiceChannel, *_):
|
||||
return x.user
|
||||
|
||||
@staticmethod
|
||||
def resolve_time(x: UserJoinedVoiceChannel, *_):
|
||||
return x.time
|
||||
|
||||
@staticmethod
|
||||
def resolve_joined_on(x: UserJoinedVoiceChannel, *_):
|
||||
return x.joined_on
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user