Merge pull request 'staging' (#453) from staging into master
All checks were successful
Deploy prod on push / on-push-deploy_sh-edraft (push) Successful in 3m21s
All checks were successful
Deploy prod on push / on-push-deploy_sh-edraft (push) Successful in 3m21s
Reviewed-on: #453
This commit is contained in:
commit
18386339b7
@ -14,7 +14,6 @@
|
|||||||
"config": "src/modules/config/config.json",
|
"config": "src/modules/config/config.json",
|
||||||
"database": "src/modules/database/database.json",
|
"database": "src/modules/database/database.json",
|
||||||
"level": "src/modules/level/level.json",
|
"level": "src/modules/level/level.json",
|
||||||
"permission": "src/modules/permission/permission.json",
|
|
||||||
"technician": "src/modules/technician/technician.json",
|
"technician": "src/modules/technician/technician.json",
|
||||||
"short-role-name": "src/modules/short_role_name/short-role-name.json",
|
"short-role-name": "src/modules/short_role_name/short-role-name.json",
|
||||||
"special-offers": "src/modules/special_offers/special-offers.json",
|
"special-offers": "src/modules/special_offers/special-offers.json",
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "1",
|
"Major": "1",
|
||||||
"Minor": "2",
|
"Minor": "2",
|
||||||
"Micro": "2"
|
"Micro": "3"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
@ -70,7 +70,6 @@
|
|||||||
"../modules/config/config.json",
|
"../modules/config/config.json",
|
||||||
"../modules/database/database.json",
|
"../modules/database/database.json",
|
||||||
"../modules/level/level.json",
|
"../modules/level/level.json",
|
||||||
"../modules/permission/permission.json",
|
|
||||||
"../modules/short_role_name/short-role-name.json",
|
"../modules/short_role_name/short-role-name.json",
|
||||||
"../modules/special_offers/special-offers.json",
|
"../modules/special_offers/special-offers.json",
|
||||||
"../modules/technician/technician.json"
|
"../modules/technician/technician.json"
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot.extension"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -12,7 +12,6 @@ from modules.boot_log.boot_log_module import BootLogModule
|
|||||||
from modules.config.config_module import ConfigModule
|
from modules.config.config_module import ConfigModule
|
||||||
from modules.database.database_module import DatabaseModule
|
from modules.database.database_module import DatabaseModule
|
||||||
from modules.level.level_module import LevelModule
|
from modules.level.level_module import LevelModule
|
||||||
from modules.permission.permission_module import PermissionModule
|
|
||||||
from modules.short_role_name.short_role_name_module import ShortRoleNameModule
|
from modules.short_role_name.short_role_name_module import ShortRoleNameModule
|
||||||
from modules.special_offers.special_offers_module import SteamSpecialOffersModule
|
from modules.special_offers.special_offers_module import SteamSpecialOffersModule
|
||||||
from modules.technician.technician_module import TechnicianModule
|
from modules.technician.technician_module import TechnicianModule
|
||||||
@ -30,7 +29,6 @@ class ModuleList:
|
|||||||
ConfigModule, # has to be before db check
|
ConfigModule, # has to be before db check
|
||||||
DatabaseModule,
|
DatabaseModule,
|
||||||
GraphQLModule,
|
GraphQLModule,
|
||||||
PermissionModule,
|
|
||||||
AutoRoleModule,
|
AutoRoleModule,
|
||||||
BaseModule,
|
BaseModule,
|
||||||
LevelModule,
|
LevelModule,
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.abc"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "1",
|
"Major": "1",
|
||||||
"Minor": "2",
|
"Minor": "2",
|
||||||
"Micro": "2"
|
"Micro": "3"
|
||||||
},
|
},
|
||||||
"Author": "",
|
"Author": "",
|
||||||
"AuthorEmail": "",
|
"AuthorEmail": "",
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.configuration"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.controller"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.event"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.exception"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.filter"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.filter.discord"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.logging"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.model"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.model.discord"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.route"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.service"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_api.transformer"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -10,7 +10,7 @@ from bot_api.model.user_dto import UserDTO
|
|||||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||||
from bot_data.model.auth_user import AuthUser
|
from bot_data.model.auth_user import AuthUser
|
||||||
from bot_data.model.user import User
|
from bot_data.model.user import User
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
|
|
||||||
class AuthUserTransformer(TransformerABC):
|
class AuthUserTransformer(TransformerABC):
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.abc"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -48,6 +48,16 @@ class ClientUtilsABC(ABC):
|
|||||||
def get_auto_complete_list(self, _l: List, current: str, select: Callable = None) -> List:
|
def get_auto_complete_list(self, _l: List, current: str, select: Callable = None) -> List:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def update_user_message_xp_count_by_hour(
|
||||||
|
self,
|
||||||
|
created_at: datetime,
|
||||||
|
user: User,
|
||||||
|
settings: ServerConfig,
|
||||||
|
is_reaction: bool = False,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_message_xp_count_by_hour_higher_that_max_message_count_per_hour(
|
def is_message_xp_count_by_hour_higher_that_max_message_count_per_hour(
|
||||||
self,
|
self,
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "1",
|
"Major": "1",
|
||||||
"Minor": "2",
|
"Minor": "2",
|
||||||
"Micro": "2"
|
"Micro": "3"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.configuration"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,6 @@ class FeatureFlagsEnum(Enum):
|
|||||||
database_module = "DatabaseModule"
|
database_module = "DatabaseModule"
|
||||||
level_module = "LevelModule"
|
level_module = "LevelModule"
|
||||||
moderator_module = "ModeratorModule"
|
moderator_module = "ModeratorModule"
|
||||||
permission_module = "PermissionModule"
|
|
||||||
short_role_name_module = "ShortRoleNameModule"
|
short_role_name_module = "ShortRoleNameModule"
|
||||||
steam_special_offers_module = "SteamSpecialOffersModule"
|
steam_special_offers_module = "SteamSpecialOffersModule"
|
||||||
# features
|
# features
|
||||||
|
@ -16,7 +16,6 @@ class FeatureFlagsSettings(ConfigurationModelABC):
|
|||||||
FeatureFlagsEnum.data_module.value: True, # 03.10.2022 #56
|
FeatureFlagsEnum.data_module.value: True, # 03.10.2022 #56
|
||||||
FeatureFlagsEnum.database_module.value: True, # 02.10.2022 #48
|
FeatureFlagsEnum.database_module.value: True, # 02.10.2022 #48
|
||||||
FeatureFlagsEnum.moderator_module.value: False, # 02.10.2022 #48
|
FeatureFlagsEnum.moderator_module.value: False, # 02.10.2022 #48
|
||||||
FeatureFlagsEnum.permission_module.value: True, # 02.10.2022 #48
|
|
||||||
FeatureFlagsEnum.config_module.value: True, # 19.07.2023 #127
|
FeatureFlagsEnum.config_module.value: True, # 19.07.2023 #127
|
||||||
FeatureFlagsEnum.short_role_name_module.value: True, # 28.09.2023 #378
|
FeatureFlagsEnum.short_role_name_module.value: True, # 28.09.2023 #378
|
||||||
FeatureFlagsEnum.steam_special_offers_module.value: True, # 11.10.2023 #188
|
FeatureFlagsEnum.steam_special_offers_module.value: True, # 11.10.2023 #188
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.core_extension"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -9,7 +9,7 @@ from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
|||||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
from bot_core.helper.command_checks import CommandChecks
|
from bot_core.helper.command_checks import CommandChecks
|
||||||
from bot_core.helper.event_checks import EventChecks
|
from bot_core.helper.event_checks import EventChecks
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
|
|
||||||
class CoreExtension(ApplicationExtensionABC):
|
class CoreExtension(ApplicationExtensionABC):
|
||||||
|
@ -7,6 +7,7 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
|||||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||||
from bot_core.abc.module_abc import ModuleABC
|
from bot_core.abc.module_abc import ModuleABC
|
||||||
|
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
from bot_core.events.core_on_ready_event import CoreOnReadyEvent
|
from bot_core.events.core_on_ready_event import CoreOnReadyEvent
|
||||||
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
|
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
|
||||||
@ -14,6 +15,7 @@ from bot_core.service.client_utils_service import ClientUtilsService
|
|||||||
from bot_core.service.config_service import ConfigService
|
from bot_core.service.config_service import ConfigService
|
||||||
from bot_core.service.data_integrity_service import DataIntegrityService
|
from bot_core.service.data_integrity_service import DataIntegrityService
|
||||||
from bot_core.service.message_service import MessageService
|
from bot_core.service.message_service import MessageService
|
||||||
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class CoreModule(ModuleABC):
|
class CoreModule(ModuleABC):
|
||||||
@ -28,6 +30,7 @@ class CoreModule(ModuleABC):
|
|||||||
services.add_transient(MessageServiceABC, MessageService)
|
services.add_transient(MessageServiceABC, MessageService)
|
||||||
services.add_transient(ClientUtilsABC, ClientUtilsService)
|
services.add_transient(ClientUtilsABC, ClientUtilsService)
|
||||||
services.add_transient(DataIntegrityService)
|
services.add_transient(DataIntegrityService)
|
||||||
|
services.add_singleton(PermissionServiceABC, PermissionService)
|
||||||
|
|
||||||
# pipes
|
# pipes
|
||||||
services.add_transient(DateTimeOffsetPipe)
|
services.add_transient(DateTimeOffsetPipe)
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.events"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.exception"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.helper"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -7,7 +7,7 @@ from discord.ext.commands import Context
|
|||||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||||
from bot_core.exception.check_error import CheckError
|
from bot_core.exception.check_error import CheckError
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
|
|
||||||
class CommandChecks:
|
class CommandChecks:
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.logging"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.pipes"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_core.service"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -143,14 +143,13 @@ class ClientUtilsService(ClientUtilsABC):
|
|||||||
|
|
||||||
return _l.take(25)
|
return _l.take(25)
|
||||||
|
|
||||||
def is_message_xp_count_by_hour_higher_that_max_message_count_per_hour(
|
def update_user_message_xp_count_by_hour(
|
||||||
self,
|
self,
|
||||||
created_at: datetime,
|
created_at: datetime,
|
||||||
user: User,
|
user: User,
|
||||||
settings: ServerConfig,
|
settings: ServerConfig,
|
||||||
is_reaction: bool = False,
|
is_reaction: bool = False,
|
||||||
) -> bool:
|
):
|
||||||
umcph = None
|
|
||||||
try:
|
try:
|
||||||
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||||
if umcph is None:
|
if umcph is None:
|
||||||
@ -162,44 +161,50 @@ class ClientUtilsService(ClientUtilsABC):
|
|||||||
user,
|
user,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._db.save_changes()
|
self._db.save_changes()
|
||||||
|
|
||||||
umcph = self._umcphs.get_user_message_count_per_hour_by_user_id_and_date(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__,
|
|
||||||
f"Cannot add user message count per hour with id {umcph.id}",
|
|
||||||
e,
|
|
||||||
)
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
if is_reaction:
|
|
||||||
umcph.xp_count += settings.xp_per_reaction
|
|
||||||
else:
|
|
||||||
umcph.xp_count += settings.xp_per_message
|
|
||||||
|
|
||||||
|
umcph.xp_count += settings.xp_per_reaction if is_reaction else settings.xp_per_message
|
||||||
self._umcphs.update_user_message_count_per_hour(umcph)
|
self._umcphs.update_user_message_count_per_hour(umcph)
|
||||||
self._db.save_changes()
|
self._db.save_changes()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(
|
self._logger.error(
|
||||||
__name__,
|
__name__,
|
||||||
f"Cannot update user message count per hour with id {umcph.id}",
|
f"Cannot update user message count per hour {created_at}",
|
||||||
e,
|
e,
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if umcph.xp_count is None:
|
def is_message_xp_count_by_hour_higher_that_max_message_count_per_hour(
|
||||||
|
self,
|
||||||
|
created_at: datetime,
|
||||||
|
user: User,
|
||||||
|
settings: ServerConfig,
|
||||||
|
is_reaction: bool = False,
|
||||||
|
) -> bool:
|
||||||
|
try:
|
||||||
|
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||||
|
if umcph is None or umcph.xp_count is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return umcph.xp_count > settings.max_message_xp_per_hour
|
return umcph.xp_count > settings.max_message_xp_per_hour
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(
|
||||||
|
__name__,
|
||||||
|
f"Cannot add user message count per hour with",
|
||||||
|
e,
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
def get_ontime_for_user(self, user: User) -> float:
|
def get_ontime_for_user(self, user: User) -> float:
|
||||||
return round(
|
return round(
|
||||||
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.id)
|
sum(
|
||||||
.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),
|
(join.leaved_on - join.joined_on).total_seconds() / 3600
|
||||||
|
for join in self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.id)
|
||||||
|
if join.leaved_on is not None and join.joined_on is not None
|
||||||
|
]
|
||||||
|
),
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -214,7 +219,7 @@ class ClientUtilsService(ClientUtilsABC):
|
|||||||
guild: Guild = self._bot.guilds.where(lambda g: g == guild).single()
|
guild: Guild = self._bot.guilds.where(lambda g: g == guild).single()
|
||||||
channel = guild.get_channel(discord_channel_id)
|
channel = guild.get_channel(discord_channel_id)
|
||||||
message = await channel.fetch_message(discord_message_id)
|
message = await channel.fetch_message(discord_message_id)
|
||||||
emoji = List(discord.Emoji, guild.emojis).where(lambda x: x.name == rule.emoji_name).single()
|
emoji = List(discord.Emoji, [x for x in guild.emojis if x.name == rule.emoji_name]).single()
|
||||||
|
|
||||||
if emoji is None:
|
if emoji is None:
|
||||||
self._logger.debug(__name__, f"Emoji {rule.emoji_name} not found")
|
self._logger.debug(__name__, f"Emoji {rule.emoji_name} not found")
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
import discord
|
|
||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
from cpl_discord.container import Member, Guild
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||||
@ -66,74 +65,76 @@ class DataIntegrityService:
|
|||||||
|
|
||||||
self._is_for_shutdown = False
|
self._is_for_shutdown = False
|
||||||
|
|
||||||
def _check_known_users(self):
|
async def check_data_integrity(self, is_for_shutdown=False):
|
||||||
self._logger.debug(__name__, f"Start checking KnownUsers table, {len(self._bot.users)}")
|
self._logger.info(__name__, f"Data integrity service started")
|
||||||
for u in self._bot.users:
|
if is_for_shutdown != self._is_for_shutdown:
|
||||||
u: discord.User = u
|
self._is_for_shutdown = is_for_shutdown
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if u.bot:
|
|
||||||
self._logger.trace(__name__, f"User {u.id} is ignored, because its a bot")
|
|
||||||
continue
|
|
||||||
|
|
||||||
user = self._known_users.find_user_by_discord_id(u.id)
|
|
||||||
if user is not None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
self._logger.warn(__name__, f"Unknown user: {u.id}")
|
|
||||||
self._logger.debug(__name__, f"Add user: {u.id}")
|
|
||||||
self._known_users.add_user(KnownUser(u.id))
|
|
||||||
self._db_context.save_changes()
|
|
||||||
|
|
||||||
user = self._known_users.find_user_by_discord_id(u.id)
|
|
||||||
if user is None:
|
|
||||||
self._logger.fatal(__name__, f"Cannot add user: {u.id}")
|
|
||||||
|
|
||||||
self._logger.debug(__name__, f"Added user: {u.id}")
|
|
||||||
except Exception as e:
|
|
||||||
self._logger.error(__name__, f"Cannot get user", e)
|
|
||||||
|
|
||||||
def check_servers(self):
|
|
||||||
self._logger.debug(__name__, f"Start checking Servers table")
|
|
||||||
for g in self._bot.guilds:
|
for g in self._bot.guilds:
|
||||||
g: discord.Guild = g
|
self._logger.debug(__name__, f"Start check for server: {g.id}")
|
||||||
try:
|
s = self._get_or_create_server(g)
|
||||||
server = self._servers.find_server_by_discord_id(g.id)
|
self._logger.debug(__name__, f"Start check for clients")
|
||||||
if server is not None:
|
self._check_clients(g.id, s)
|
||||||
|
|
||||||
|
for m in [m for m in g.members if not m.bot]:
|
||||||
|
await self._check_default_role(m)
|
||||||
|
self._check_known_user(m.id)
|
||||||
|
|
||||||
|
self._logger.debug(__name__, f"Start check for member: {g.id}@{m.id}")
|
||||||
|
u = self._get_or_create_user(s, m.id)
|
||||||
|
|
||||||
|
self._logger.debug(__name__, f"Start check for user joined server: {g.id}@{m.id}")
|
||||||
|
self._check_user_join(g, m, u)
|
||||||
|
|
||||||
|
self._logger.debug(__name__, f"Start check for user joined voice channels: {g.id}@{m.id}")
|
||||||
|
self._check_user_joined_vc(g.id, m, u)
|
||||||
|
|
||||||
|
self._logger.debug(__name__, f"Start check for user joined game servers: {g.id}@{m.id}")
|
||||||
|
self._check_user_joined_gs(g.id, m.id, u)
|
||||||
|
|
||||||
|
self._logger.debug(__name__, f"Start check for user got achievements: {g.id}@{m.id}")
|
||||||
|
await self._check_for_user_achievements(u)
|
||||||
|
|
||||||
|
for m in [m for m in g.members if m.bot]:
|
||||||
|
u = self._users.find_user_by_discord_id_and_server_id(m.id, s.id)
|
||||||
|
if u is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._logger.warn(__name__, f"Server not found in database: {g.id}")
|
self._remove_bot(u)
|
||||||
self._logger.debug(__name__, f"Add server: {g.id}")
|
self._logger.info(__name__, f"Data integrity service finished")
|
||||||
self._servers.add_server(Server(g.id))
|
except Exception as e:
|
||||||
|
self._logger.fatal(__name__, f"Checking data integrity failed", e)
|
||||||
|
|
||||||
|
def _get_or_create_server(self, guild: Guild) -> Server:
|
||||||
|
try:
|
||||||
|
server = self._servers.find_server_by_discord_id(guild.id)
|
||||||
|
if server is not None:
|
||||||
|
return server
|
||||||
|
|
||||||
|
self._logger.warn(__name__, f"Server not found in database: {guild.id}")
|
||||||
|
self._logger.debug(__name__, f"Add server: {guild.id}")
|
||||||
|
self._servers.add_server(Server(guild.id))
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
|
||||||
server = self._servers.find_server_by_discord_id(g.id)
|
server = self._servers.find_server_by_discord_id(guild.id)
|
||||||
if server is None:
|
if server is None:
|
||||||
self._logger.fatal(__name__, f"Cannot add server: {g.id}")
|
self._logger.fatal(__name__, f"Cannot add server: {guild.id}")
|
||||||
|
|
||||||
self._logger.debug(__name__, f"Added server: {g.id}")
|
self._logger.trace(__name__, f"Added server: {guild.id}")
|
||||||
|
return server
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Cannot get server", e)
|
self._logger.error(__name__, f"Cannot get server", e)
|
||||||
|
|
||||||
results = self._servers.get_servers()
|
def _check_clients(self, guild_id: int, server: Server):
|
||||||
if results is None or len(results) == 0:
|
|
||||||
self._logger.error(__name__, f"Table Servers is empty!")
|
|
||||||
|
|
||||||
def _check_clients(self):
|
|
||||||
self._logger.debug(__name__, f"Start checking Clients table")
|
|
||||||
for g in self._bot.guilds:
|
|
||||||
g: discord.Guild = g
|
|
||||||
try:
|
try:
|
||||||
server: Server = self._servers.find_server_by_discord_id(g.id)
|
|
||||||
if server is None:
|
|
||||||
self._logger.fatal(__name__, f"Server not found in database: {g.id}")
|
|
||||||
|
|
||||||
client = self._clients.find_client_by_server_id(server.id)
|
client = self._clients.find_client_by_server_id(server.id)
|
||||||
if client is not None:
|
if client is not None:
|
||||||
continue
|
return
|
||||||
|
|
||||||
self._logger.warn(
|
self._logger.warn(
|
||||||
__name__,
|
__name__,
|
||||||
f"Client for server {g.id} not found in database: {self._bot.user.id}",
|
f"Client for server {guild_id} not found in database: {self._bot.user.id}",
|
||||||
)
|
)
|
||||||
self._logger.debug(__name__, f"Add client: {self._bot.user.id}")
|
self._logger.debug(__name__, f"Add client: {self._bot.user.id}")
|
||||||
self._clients.add_client(Client(self._bot.user.id, 0, 0, 0, 0, 0, server))
|
self._clients.add_client(Client(self._bot.user.id, 0, 0, 0, 0, 0, server))
|
||||||
@ -143,10 +144,10 @@ class DataIntegrityService:
|
|||||||
if client is None:
|
if client is None:
|
||||||
self._logger.fatal(
|
self._logger.fatal(
|
||||||
__name__,
|
__name__,
|
||||||
f"Cannot add client {self._bot.user.id} for server {g.id}",
|
f"Cannot add client {self._bot.user.id} for server {guild_id}",
|
||||||
)
|
)
|
||||||
|
|
||||||
self._logger.debug(__name__, f"Added client: {g.id}")
|
self._logger.trace(__name__, f"Added client: {guild_id}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Cannot get client", e)
|
self._logger.error(__name__, f"Cannot get client", e)
|
||||||
|
|
||||||
@ -154,32 +155,37 @@ class DataIntegrityService:
|
|||||||
if results is None or len(results) == 0:
|
if results is None or len(results) == 0:
|
||||||
self._logger.error(__name__, f"Table Servers is empty!")
|
self._logger.error(__name__, f"Table Servers is empty!")
|
||||||
|
|
||||||
def _check_users(self):
|
def _check_known_user(self, member_id: int):
|
||||||
self._logger.debug(__name__, f"Start checking Users table")
|
|
||||||
for g in self._bot.guilds:
|
|
||||||
g: discord.Guild = g
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
server = self._servers.find_server_by_discord_id(g.id)
|
if self._known_users.find_user_by_discord_id(member_id) is not None:
|
||||||
if server is None:
|
return
|
||||||
self._logger.fatal(__name__, f"Server not found in database: {g.id}")
|
|
||||||
|
|
||||||
for u in g.members:
|
self._logger.warn(__name__, f"Unknown user: {member_id}")
|
||||||
u: Union[discord.Member, discord.User] = u
|
self._logger.trace(__name__, f"Add known user: {member_id}")
|
||||||
if u.bot:
|
self._known_users.add_user(KnownUser(member_id))
|
||||||
self._logger.trace(__name__, f"User {u.id} is ignored, because its a bot")
|
|
||||||
continue
|
|
||||||
|
|
||||||
user = self._users.find_user_by_discord_id_and_server_id(u.id, server.id)
|
|
||||||
if user is not None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
self._logger.warn(__name__, f"User not found in database: {u.id}")
|
|
||||||
self._logger.debug(__name__, f"Add user: {u.id}")
|
|
||||||
self._users.add_user(User(u.id, 0, 0, 0, None, server))
|
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
|
||||||
self._logger.debug(__name__, f"Added User: {u.id}")
|
user = self._known_users.find_user_by_discord_id(member_id)
|
||||||
|
if user is None:
|
||||||
|
self._logger.fatal(__name__, f"Cannot add user: {member_id}")
|
||||||
|
|
||||||
|
self._logger.trace(__name__, f"Added known user: {member_id}")
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(__name__, f"Cannot get user", e)
|
||||||
|
|
||||||
|
def _get_or_create_user(self, server: Server, member_id: int) -> User:
|
||||||
|
try:
|
||||||
|
user = self._users.find_user_by_discord_id_and_server_id(member_id, server.id)
|
||||||
|
if user is not None:
|
||||||
|
return user
|
||||||
|
|
||||||
|
self._logger.warn(__name__, f"User not found in database: {member_id}")
|
||||||
|
self._logger.debug(__name__, f"Add user: {member_id}")
|
||||||
|
self._users.add_user(User(member_id, 0, 0, 0, None, server))
|
||||||
|
self._db_context.save_changes()
|
||||||
|
|
||||||
|
self._logger.trace(__name__, f"Added User: {member_id}")
|
||||||
|
return self._users.get_user_by_discord_id_and_server_id(member_id, server.id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Cannot get User", e)
|
self._logger.error(__name__, f"Cannot get User", e)
|
||||||
|
|
||||||
@ -187,63 +193,34 @@ class DataIntegrityService:
|
|||||||
if results is None or len(results) == 0:
|
if results is None or len(results) == 0:
|
||||||
self._logger.error(__name__, f"Table Users is empty!")
|
self._logger.error(__name__, f"Table Users is empty!")
|
||||||
|
|
||||||
def _check_user_joins(self):
|
def _check_user_join(self, guild: Guild, member: Member, user: User):
|
||||||
self._logger.debug(__name__, f"Start checking UserJoinedServers table")
|
|
||||||
for guild in self._bot.guilds:
|
|
||||||
guild: discord.Guild = guild
|
|
||||||
|
|
||||||
server = self._servers.find_server_by_discord_id(guild.id)
|
|
||||||
if server is None:
|
|
||||||
self._logger.fatal(__name__, f"Server not found in database: {guild.id}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for u in guild.members:
|
|
||||||
u: discord.User = u
|
|
||||||
if u.bot:
|
|
||||||
self._logger.trace(__name__, f"User {u.id} is ignored, because its a bot")
|
|
||||||
continue
|
|
||||||
|
|
||||||
user = self._users.find_user_by_discord_id_and_server_id(u.id, server.id)
|
|
||||||
if user is None:
|
|
||||||
self._logger.fatal(__name__, f"User not found in database: {u.id}")
|
|
||||||
|
|
||||||
join = self._user_joins.find_active_user_joined_server_by_user_id(user.id)
|
join = self._user_joins.find_active_user_joined_server_by_user_id(user.id)
|
||||||
if join is not None:
|
if join is not None:
|
||||||
continue
|
return
|
||||||
|
|
||||||
m: discord.Member = u
|
|
||||||
self._logger.warn(
|
self._logger.warn(
|
||||||
__name__,
|
__name__,
|
||||||
f"Active UserJoinedServer not found in database: {guild.id}:{u.id}@{m.joined_at}",
|
f"Active UserJoinedServer not found in database: {guild.id}:{member.id}@{member.joined_at}",
|
||||||
)
|
)
|
||||||
self._logger.debug(
|
self._logger.debug(
|
||||||
__name__,
|
__name__,
|
||||||
f"Add UserJoinedServer: {guild.id}:{u.id}@{m.joined_at}",
|
f"Add UserJoinedServer: {guild.id}:{member.id}@{member.joined_at}",
|
||||||
)
|
|
||||||
self._user_joins.add_user_joined_server(
|
|
||||||
UserJoinedServer(user, self._dtp.transform(m.joined_at), None)
|
|
||||||
)
|
)
|
||||||
|
self._user_joins.add_user_joined_server(UserJoinedServer(user, self._dtp.transform(member.joined_at), None))
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
|
||||||
self._logger.debug(__name__, f"Added UserJoinedServer: {u.id}")
|
self._logger.trace(__name__, f"Added UserJoinedServer: {member.id}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Cannot get UserJoinedServer", e)
|
self._logger.error(__name__, f"Cannot get UserJoinedServer", e)
|
||||||
|
|
||||||
results = self._users.get_users()
|
try:
|
||||||
if results is None or len(results) == 0:
|
|
||||||
self._logger.error(__name__, f"Table Users is empty!")
|
|
||||||
|
|
||||||
joins = self._user_joins.get_user_joined_servers()
|
joins = self._user_joins.get_user_joined_servers()
|
||||||
for join in joins:
|
for join in [x for x in joins if x.user.server.discord_id == guild.id and x.leaved_on is None]:
|
||||||
join: UserJoinedServer = join
|
|
||||||
if join.user.server.discord_id != guild.id:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if join.leaved_on is not None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
dc_user = guild.get_member(join.user.discord_id)
|
dc_user = guild.get_member(join.user.discord_id)
|
||||||
if dc_user is None:
|
if dc_user is not None:
|
||||||
|
continue
|
||||||
|
|
||||||
self._logger.warn(
|
self._logger.warn(
|
||||||
__name__,
|
__name__,
|
||||||
f"User {join.user.discord_id} already left the server.",
|
f"User {join.user.discord_id} already left the server.",
|
||||||
@ -252,42 +229,26 @@ class DataIntegrityService:
|
|||||||
self._user_joins.update_user_joined_server(join)
|
self._user_joins.update_user_joined_server(join)
|
||||||
|
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(__name__, f"Cannot update UserJoinedServer", e)
|
||||||
|
|
||||||
def _check_user_joins_vc(self):
|
def _check_user_joined_vc(self, guild_id: int, member: Member, user: User):
|
||||||
self._logger.debug(__name__, f"Start checking UserJoinedVoiceChannel table")
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild_id}")
|
||||||
for guild in self._bot.guilds:
|
|
||||||
guild: discord.Guild = guild
|
|
||||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}")
|
|
||||||
|
|
||||||
server = self._servers.find_server_by_discord_id(guild.id)
|
|
||||||
if server is None:
|
|
||||||
self._logger.fatal(__name__, f"Server not found in database: {guild.id}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# close open voice states
|
# close open voice states
|
||||||
for member in guild.members:
|
|
||||||
if member.bot:
|
|
||||||
self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
|
|
||||||
continue
|
|
||||||
|
|
||||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
|
||||||
if user is None:
|
|
||||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
|
||||||
|
|
||||||
joins = self._user_joins_vc.find_active_user_joined_voice_channels_by_user_id(user.id)
|
joins = self._user_joins_vc.find_active_user_joined_voice_channels_by_user_id(user.id)
|
||||||
if joins is None or len(joins) == 0:
|
if joins is None or len(joins) == 0:
|
||||||
continue
|
return
|
||||||
|
|
||||||
for join in joins:
|
for join in joins:
|
||||||
self._logger.warn(
|
self._logger.warn(
|
||||||
__name__,
|
__name__,
|
||||||
f"Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}",
|
f"Active UserJoinedVoiceChannel found in database: {guild_id}:{member.id}@{join.joined_on}",
|
||||||
)
|
)
|
||||||
join.leaved_on = datetime.now()
|
join.leaved_on = datetime.now()
|
||||||
|
|
||||||
if (
|
if ((join.leaved_on - join.joined_on).total_seconds() / 60 / 60) > settings.max_voice_state_hours:
|
||||||
(join.leaved_on - join.joined_on).total_seconds() / 60 / 60
|
|
||||||
) > settings.max_voice_state_hours:
|
|
||||||
join.leaved_on = join.joined_on + timedelta(hours=settings.max_voice_state_hours)
|
join.leaved_on = join.joined_on + timedelta(hours=settings.max_voice_state_hours)
|
||||||
|
|
||||||
self._user_joins_vc.update_user_joined_voice_channel(join)
|
self._user_joins_vc.update_user_joined_voice_channel(join)
|
||||||
@ -301,59 +262,30 @@ class DataIntegrityService:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# add open voice states
|
# add open voice states
|
||||||
for member in guild.members:
|
|
||||||
if member.bot:
|
|
||||||
self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if member.voice is None or member.voice.channel.id in settings.afk_channel_ids:
|
if member.voice is None or member.voice.channel.id in settings.afk_channel_ids:
|
||||||
continue
|
return
|
||||||
|
|
||||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
|
||||||
if user is None:
|
|
||||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
|
||||||
|
|
||||||
join = UserJoinedVoiceChannel(user, member.voice.channel.id, datetime.now())
|
join = UserJoinedVoiceChannel(user, member.voice.channel.id, datetime.now())
|
||||||
self._user_joins_vc.add_user_joined_voice_channel(join)
|
self._user_joins_vc.add_user_joined_voice_channel(join)
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Cannot get UserJoinedVoiceChannel", e)
|
self._logger.error(__name__, f"Cannot get UserJoinedVoiceChannel", e)
|
||||||
|
|
||||||
def _check_user_joined_gs(self):
|
def _check_user_joined_gs(self, guild_id: int, member_id: int, user: User):
|
||||||
self._logger.debug(__name__, f"Start checking UserJoinedGameServer table")
|
|
||||||
for guild in self._bot.guilds:
|
|
||||||
guild: discord.Guild = guild
|
|
||||||
|
|
||||||
server = self._servers.find_server_by_discord_id(guild.id)
|
|
||||||
if server is None:
|
|
||||||
self._logger.fatal(__name__, f"Server not found in database: {guild.id}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for member in guild.members:
|
|
||||||
if member.bot:
|
|
||||||
self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
|
|
||||||
continue
|
|
||||||
|
|
||||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
|
||||||
if user is None:
|
|
||||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
|
||||||
|
|
||||||
joins = self._user_joined_gs.find_active_user_joined_game_servers_by_user_id(user.id)
|
joins = self._user_joined_gs.find_active_user_joined_game_servers_by_user_id(user.id)
|
||||||
if joins is None or len(joins) == 0:
|
if joins is None or len(joins) == 0:
|
||||||
continue
|
return
|
||||||
|
|
||||||
for join in joins:
|
for join in joins:
|
||||||
self._logger.warn(
|
self._logger.warn(
|
||||||
__name__,
|
__name__,
|
||||||
f"Active UserJoinedGameServer found in database: {guild.id}:{member.id}@{join.joined_on}",
|
f"Active UserJoinedGameServer found in database: {guild_id}:{member_id}@{join.joined_on}",
|
||||||
)
|
)
|
||||||
join.leaved_on = datetime.now()
|
join.leaved_on = datetime.now()
|
||||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}")
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild_id}")
|
||||||
|
|
||||||
if (
|
if join.time > settings.max_voice_state_hours:
|
||||||
(join.leaved_on - join.joined_on).total_seconds() / 60 / 60
|
|
||||||
) > settings.max_voice_state_hours:
|
|
||||||
join.leaved_on = join.joined_on + timedelta(hours=settings.max_voice_state_hours)
|
join.leaved_on = join.joined_on + timedelta(hours=settings.max_voice_state_hours)
|
||||||
|
|
||||||
self._user_joined_gs.update_user_joined_game_server(join)
|
self._user_joined_gs.update_user_joined_game_server(join)
|
||||||
@ -365,38 +297,19 @@ class DataIntegrityService:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Cannot get UserJoinedGameServer", e)
|
self._logger.error(__name__, f"Cannot get UserJoinedGameServer", e)
|
||||||
|
|
||||||
async def _check_for_user_achievements(self):
|
async def _check_for_user_achievements(self, user: User):
|
||||||
self._logger.debug(__name__, f"Start checking UserGotAchievement table")
|
try:
|
||||||
|
|
||||||
for guild in self._bot.guilds:
|
|
||||||
server = self._servers.find_server_by_discord_id(guild.id)
|
|
||||||
if server is None:
|
|
||||||
self._logger.fatal(__name__, f"Server not found in database: {guild.id}")
|
|
||||||
|
|
||||||
for member in guild.members:
|
|
||||||
if member.bot:
|
|
||||||
self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
|
|
||||||
continue
|
|
||||||
|
|
||||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
|
||||||
if user is None:
|
|
||||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
|
||||||
|
|
||||||
await self._achievements.validate_achievements_for_user(user)
|
await self._achievements.validate_achievements_for_user(user)
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(__name__, f"Cannot check UserGotAchievement for {user.id}", e)
|
||||||
|
|
||||||
async def _check_default_role(self):
|
async def _check_default_role(self, member: Member):
|
||||||
for guild in self._bot.guilds:
|
|
||||||
for member in guild.members:
|
|
||||||
await self._client_utils.check_default_role(member)
|
await self._client_utils.check_default_role(member)
|
||||||
|
|
||||||
def _check_for_bots(self):
|
def _remove_bot(self, user: User):
|
||||||
for guild in self._bot.guilds:
|
known_user = self._known_users.find_user_by_discord_id(user.discord_id)
|
||||||
server = self._servers.get_server_by_discord_id(guild.id)
|
if known_user is not None:
|
||||||
|
self._known_users.delete_user(known_user)
|
||||||
for member in guild.members.where(lambda x: x.bot):
|
|
||||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
|
||||||
if user is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for join in self._user_joins.get_user_joined_servers_by_user_id(user.id):
|
for join in self._user_joins.get_user_joined_servers_by_user_id(user.id):
|
||||||
self._user_joins.delete_user_joined_server(join)
|
self._user_joins.delete_user_joined_server(join)
|
||||||
@ -404,18 +317,3 @@ class DataIntegrityService:
|
|||||||
self._user_joins_vc.delete_user_joined_voice_channel_by_user_id(user.id)
|
self._user_joins_vc.delete_user_joined_voice_channel_by_user_id(user.id)
|
||||||
self._users.delete_user(user)
|
self._users.delete_user(user)
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
|
||||||
async def check_data_integrity(self, is_for_shutdown=False):
|
|
||||||
if is_for_shutdown != self._is_for_shutdown:
|
|
||||||
self._is_for_shutdown = is_for_shutdown
|
|
||||||
|
|
||||||
await self._check_default_role()
|
|
||||||
self._check_known_users()
|
|
||||||
self.check_servers()
|
|
||||||
self._check_clients()
|
|
||||||
self._check_users()
|
|
||||||
self._check_user_joins()
|
|
||||||
self._check_user_joins_vc()
|
|
||||||
self._check_user_joined_gs()
|
|
||||||
await self._check_for_user_achievements()
|
|
||||||
self._check_for_bots()
|
|
||||||
|
114
bot/src/bot_core/service/permission_service.py
Normal file
114
bot/src/bot_core/service/permission_service.py
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.logging import LoggerABC
|
||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
|
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||||
|
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||||
|
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
|
|
||||||
|
class PermissionService(PermissionServiceABC):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
logger: LoggerABC,
|
||||||
|
bot: DiscordBotServiceABC,
|
||||||
|
config: ConfigurationABC,
|
||||||
|
servers: ServerRepositoryABC,
|
||||||
|
server_configs: ServerConfigRepositoryABC,
|
||||||
|
technician_configs: TechnicianConfigRepositoryABC,
|
||||||
|
):
|
||||||
|
PermissionServiceABC.__init__(self)
|
||||||
|
self._logger = logger
|
||||||
|
self._bot = bot
|
||||||
|
self._config = config
|
||||||
|
self._servers = servers
|
||||||
|
self._server_configs = server_configs
|
||||||
|
self._technician_configs = technician_configs
|
||||||
|
|
||||||
|
# member_id: {team_member_type: {guild_id: bool}}
|
||||||
|
self._cache: dict[int, dict[TeamMemberTypeEnum, dict[int, bool]]] = {}
|
||||||
|
|
||||||
|
def reset_cache(self):
|
||||||
|
self._cache = {}
|
||||||
|
|
||||||
|
def get_cached_permission(
|
||||||
|
self, member_id: int, team_member_type: TeamMemberTypeEnum, guild_id: int = None
|
||||||
|
) -> Optional[bool]:
|
||||||
|
if member_id not in self._cache:
|
||||||
|
self._cache[member_id] = {}
|
||||||
|
|
||||||
|
if team_member_type not in self._cache[member_id]:
|
||||||
|
self._cache[member_id][team_member_type] = {}
|
||||||
|
return None
|
||||||
|
|
||||||
|
if guild_id not in self._cache[member_id][team_member_type]:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self._cache[member_id][team_member_type][guild_id]
|
||||||
|
|
||||||
|
def set_cached_permission(
|
||||||
|
self, value: bool, member_id: int, team_member_type: TeamMemberTypeEnum, guild_id: int = None
|
||||||
|
):
|
||||||
|
if member_id not in self._cache:
|
||||||
|
self._cache[member_id] = {}
|
||||||
|
|
||||||
|
if team_member_type not in self._cache[member_id]:
|
||||||
|
self._cache[member_id][team_member_type] = {}
|
||||||
|
|
||||||
|
self._cache[member_id][team_member_type][guild_id] = value
|
||||||
|
|
||||||
|
def _has_member_role(self, member: discord.Member, team_member_type: TeamMemberTypeEnum) -> bool:
|
||||||
|
if member is None or member.guild is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
has_permission_cached = self.get_cached_permission(member.id, team_member_type, member.guild.id)
|
||||||
|
if has_permission_cached is not None:
|
||||||
|
return has_permission_cached
|
||||||
|
|
||||||
|
self._logger.debug(__name__, f"Checking is member {member.name} {team_member_type.value}")
|
||||||
|
|
||||||
|
has_permission = True in [
|
||||||
|
member.guild.get_role(x.role_id) in member.roles
|
||||||
|
for x in self._server_configs.get_server_config_by_server(
|
||||||
|
self._servers.get_server_by_discord_id(member.guild.id).id
|
||||||
|
).team_role_ids
|
||||||
|
if x.team_member_type == team_member_type
|
||||||
|
]
|
||||||
|
self.set_cached_permission(has_permission, member.id, team_member_type, member.guild.id)
|
||||||
|
return has_permission
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(__name__, "Permission check failed", e)
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def is_member_admin(self, member: discord.Member) -> bool:
|
||||||
|
return self._has_member_role(member, TeamMemberTypeEnum.admin)
|
||||||
|
|
||||||
|
def is_member_moderator(self, member: discord.Member) -> bool:
|
||||||
|
return self._has_member_role(member, TeamMemberTypeEnum.moderator) or self._has_member_role(
|
||||||
|
member, TeamMemberTypeEnum.admin
|
||||||
|
)
|
||||||
|
|
||||||
|
def is_member_technician(self, member: discord.Member) -> bool:
|
||||||
|
if member is None or member.guild is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
has_permission_cached = self.get_cached_permission(member.id, TeamMemberTypeEnum.technician)
|
||||||
|
if has_permission_cached is not None:
|
||||||
|
return has_permission_cached
|
||||||
|
|
||||||
|
self._logger.debug(__name__, f"Checking is member {member.name} technician")
|
||||||
|
|
||||||
|
try:
|
||||||
|
has_permission = member.id in self._technician_configs.get_technician_config().technician_ids
|
||||||
|
self.set_cached_permission(has_permission, member.id, TeamMemberTypeEnum.technician)
|
||||||
|
return has_permission
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(__name__, "Permission check failed", e)
|
||||||
|
return False
|
@ -15,7 +15,7 @@ __title__ = "bot_data"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.abc"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -19,10 +19,6 @@ class UserJoinedServerRepositoryABC(ABC):
|
|||||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_user_joined_server_by_server_id(self, server_id: int) -> UserJoinedServer:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> list[UserJoinedServer]:
|
def get_user_joined_servers_by_user_id(self, user_id: int) -> list[UserJoinedServer]:
|
||||||
pass
|
pass
|
||||||
|
@ -31,6 +31,10 @@ class UserRepositoryABC(ABC):
|
|||||||
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_users_with_activity_by_server_id(self, server_id: int) -> List[User]:
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
||||||
pass
|
pass
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "1",
|
"Major": "1",
|
||||||
"Minor": "2",
|
"Minor": "2",
|
||||||
"Micro": "2"
|
"Micro": "3"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.model"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -4,3 +4,4 @@ from enum import Enum
|
|||||||
class TeamMemberTypeEnum(Enum):
|
class TeamMemberTypeEnum(Enum):
|
||||||
moderator = "Moderator"
|
moderator = "Moderator"
|
||||||
admin = "Admin"
|
admin = "Admin"
|
||||||
|
technician = "Technician"
|
||||||
|
@ -2,6 +2,7 @@ from datetime import datetime, date
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from cpl_core.database import TableABC
|
from cpl_core.database import TableABC
|
||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
@ -31,6 +32,8 @@ class User(TableABC):
|
|||||||
self._birthday = birthday
|
self._birthday = birthday
|
||||||
self._server = server
|
self._server = server
|
||||||
|
|
||||||
|
self._activity = 0
|
||||||
|
|
||||||
TableABC.__init__(self)
|
TableABC.__init__(self)
|
||||||
self._created_at = created_at if created_at is not None else self._created_at
|
self._created_at = created_at if created_at is not None else self._created_at
|
||||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||||
@ -92,10 +95,40 @@ class User(TableABC):
|
|||||||
@property
|
@property
|
||||||
@ServiceProviderABC.inject
|
@ServiceProviderABC.inject
|
||||||
def ontime(self, services: ServiceProviderABC) -> float:
|
def ontime(self, services: ServiceProviderABC) -> float:
|
||||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
db: DatabaseContextABC = services.get_service(DatabaseContextABC)
|
||||||
|
result = db.select(
|
||||||
|
f"""
|
||||||
|
SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedVoiceChannel.LeavedOn, UserJoinedVoiceChannel.JoinedOn)) / 3600),2)
|
||||||
|
FROM UserJoinedVoiceChannel
|
||||||
|
WHERE UserId = {self._user_id};
|
||||||
|
"""
|
||||||
|
)[0][0]
|
||||||
|
if result is None:
|
||||||
|
return 0
|
||||||
|
return float(result)
|
||||||
|
|
||||||
client_utils: ClientUtilsABC = services.get_service(ClientUtilsABC)
|
@property
|
||||||
return client_utils.get_ontime_for_user(self)
|
@ServiceProviderABC.inject
|
||||||
|
def game_ontime(self, services: ServiceProviderABC) -> float:
|
||||||
|
db: DatabaseContextABC = services.get_service(DatabaseContextABC)
|
||||||
|
result = db.select(
|
||||||
|
f"""
|
||||||
|
SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedGameServer.LeavedOn, UserJoinedGameServer.JoinedOn)) / 3600),2)
|
||||||
|
FROM UserJoinedGameServer
|
||||||
|
WHERE UserId = {self._user_id};
|
||||||
|
"""
|
||||||
|
)[0][0]
|
||||||
|
if result is None:
|
||||||
|
return 0
|
||||||
|
return float(result)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def activity(self) -> int:
|
||||||
|
return self._activity
|
||||||
|
|
||||||
|
@activity.setter
|
||||||
|
def activity(self, value: int):
|
||||||
|
self._activity = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ServiceProviderABC.inject
|
@ServiceProviderABC.inject
|
||||||
|
@ -67,15 +67,6 @@ class UserJoinedServer(TableABC):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_select_by_server_id_string(id: int) -> str:
|
|
||||||
return str(
|
|
||||||
f"""
|
|
||||||
SELECT * FROM `UserJoinedServers`
|
|
||||||
WHERE `ServerId` = {id};
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_select_by_user_id_string(id: int) -> str:
|
def get_select_by_user_id_string(id: int) -> str:
|
||||||
return str(
|
return str(
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_data.service"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -48,66 +48,60 @@ class AchievementRepositoryService(AchievementRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_achievements(self) -> List[Achievement]:
|
def get_achievements(self) -> List[Achievement]:
|
||||||
achievements = List(Achievement)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Achievement.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {Achievement.get_select_all_string()}")
|
||||||
results = self._context.select(Achievement.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user with id {result[0]}")
|
|
||||||
achievements.append(self._from_result(result))
|
|
||||||
|
|
||||||
return achievements
|
return List(
|
||||||
|
Achievement,
|
||||||
|
[self._from_result(result) for result in self._context.select(Achievement.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
def get_achievement_by_id(self, id: int) -> Achievement:
|
def get_achievement_by_id(self, id: int) -> Achievement:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Achievement.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {Achievement.get_select_by_id_string(id)}")
|
||||||
result = self._context.select(Achievement.get_select_by_id_string(id))[0]
|
return self._from_result(self._context.select(Achievement.get_select_by_id_string(id))[0])
|
||||||
|
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_achievements_by_server_id(self, server_id: int) -> List[Achievement]:
|
def get_achievements_by_server_id(self, server_id: int) -> List[Achievement]:
|
||||||
achievements = List(Achievement)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {Achievement.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {Achievement.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(Achievement.get_select_by_server_id_string(server_id))
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user with id {result[0]}")
|
|
||||||
achievements.append(self._from_result(result))
|
|
||||||
|
|
||||||
return achievements
|
return List(
|
||||||
|
Achievement,
|
||||||
|
[
|
||||||
|
self._from_result(result)
|
||||||
|
for result in self._context.select(Achievement.get_select_by_server_id_string(server_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_achievements_by_user_id(self, user_id: int) -> List[Achievement]:
|
def get_achievements_by_user_id(self, user_id: int) -> List[Achievement]:
|
||||||
achievements = List(Achievement)
|
|
||||||
achievements_joins = List(UserGotAchievement)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserGotAchievement.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserGotAchievement.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserGotAchievement.get_select_by_user_id_string(user_id))
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Got UserGotAchievement with id {result[0]}")
|
|
||||||
achievements_joins.append(self._join_from_result(result))
|
|
||||||
|
|
||||||
for achievements_join in achievements_joins:
|
return List(
|
||||||
results = self._context.select(Achievement.get_select_by_id_string(achievements_join.achievement.id))
|
UserGotAchievement,
|
||||||
for result in results:
|
[
|
||||||
self._logger.trace(__name__, f"Got Achievement with id {result[0]}")
|
self._join_from_result(result).achievement
|
||||||
achievements.append(self._from_result(result))
|
for result in self._context.select(UserGotAchievement.get_select_by_user_id_string(user_id))
|
||||||
|
],
|
||||||
return achievements
|
)
|
||||||
|
|
||||||
def get_user_got_achievements_by_achievement_id(self, achievement_id: int) -> List[Achievement]:
|
def get_user_got_achievements_by_achievement_id(self, achievement_id: int) -> List[Achievement]:
|
||||||
achievements_joins = List(UserGotAchievement)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserGotAchievement.get_select_by_achievement_id_string(achievement_id)}",
|
f"Send SQL command: {UserGotAchievement.get_select_by_achievement_id_string(achievement_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserGotAchievement.get_select_by_achievement_id_string(achievement_id))
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Got UserGotAchievement with id {result[0]}")
|
|
||||||
achievements_joins.append(self._join_from_result(result))
|
|
||||||
|
|
||||||
return achievements_joins
|
return List(
|
||||||
|
UserGotAchievement,
|
||||||
|
[
|
||||||
|
self._join_from_result(result)
|
||||||
|
for result in self._context.select(
|
||||||
|
UserGotAchievement.get_select_by_achievement_id_string(achievement_id)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def add_achievement(self, achievement: Achievement):
|
def add_achievement(self, achievement: Achievement):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {achievement.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {achievement.insert_string}")
|
||||||
|
@ -44,13 +44,12 @@ class ApiKeyRepositoryService(ApiKeyRepositoryABC):
|
|||||||
return api_key
|
return api_key
|
||||||
|
|
||||||
def get_api_keys(self) -> List[ApiKey]:
|
def get_api_keys(self) -> List[ApiKey]:
|
||||||
api_keys = List(ApiKey)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_all_string()}")
|
||||||
results = self._context.select(ApiKey.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
api_keys.append(self._api_key_from_result(result))
|
|
||||||
|
|
||||||
return api_keys
|
return List(
|
||||||
|
ApiKey,
|
||||||
|
[self._api_key_from_result(result) for result in self._context.select(ApiKey.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
def get_api_key(self, identifier: str, key: str) -> ApiKey:
|
def get_api_key(self, identifier: str, key: str) -> ApiKey:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_string(identifier, key)}")
|
self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_string(identifier, key)}")
|
||||||
|
@ -64,23 +64,16 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
|||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {auth_user.get_select_user_id_from_relations()}",
|
f"Send SQL command: {auth_user.get_select_user_id_from_relations()}",
|
||||||
)
|
)
|
||||||
relation_ids = List(int)
|
|
||||||
results = self._context.select(auth_user.get_select_user_id_from_relations())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Got auth user relation with id {result[0]}")
|
|
||||||
relation_ids.append(result[0])
|
|
||||||
|
|
||||||
return relation_ids
|
return List(int, [result[0] for result in self._context.select(auth_user.get_select_user_id_from_relations())])
|
||||||
|
|
||||||
def get_all_auth_users(self) -> List[AuthUser]:
|
def get_all_auth_users(self) -> List[AuthUser]:
|
||||||
users = List(AuthUser)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_all_string()}")
|
||||||
results = self._context.select(AuthUser.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get auth user with id {result[0]}")
|
|
||||||
users.append(self._user_from_result(result))
|
|
||||||
|
|
||||||
return users
|
return List(
|
||||||
|
AuthUser,
|
||||||
|
[self._user_from_result(result) for result in self._context.select(AuthUser.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
def get_filtered_auth_users(self, criteria: AuthUserSelectCriteria) -> FilteredResult:
|
def get_filtered_auth_users(self, criteria: AuthUserSelectCriteria) -> FilteredResult:
|
||||||
users = self.get_all_auth_users()
|
users = self.get_all_auth_users()
|
||||||
@ -129,8 +122,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
|||||||
|
|
||||||
def get_auth_user_by_email(self, email: str) -> AuthUser:
|
def get_auth_user_by_email(self, email: str) -> AuthUser:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}")
|
self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}")
|
||||||
result = self._context.select(AuthUser.get_select_by_email_string(email))[0]
|
return self._user_from_result(self._context.select(AuthUser.get_select_by_email_string(email))[0])
|
||||||
return self._user_from_result(result)
|
|
||||||
|
|
||||||
def find_auth_user_by_email(self, email: str) -> Optional[AuthUser]:
|
def find_auth_user_by_email(self, email: str) -> Optional[AuthUser]:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}")
|
self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}")
|
||||||
@ -138,9 +130,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._user_from_result(result[0])
|
||||||
|
|
||||||
return self._user_from_result(result)
|
|
||||||
|
|
||||||
def find_auth_user_by_confirmation_id(self, id: str) -> Optional[AuthUser]:
|
def find_auth_user_by_confirmation_id(self, id: str) -> Optional[AuthUser]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -151,9 +141,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._user_from_result(result[0])
|
||||||
|
|
||||||
return self._user_from_result(result)
|
|
||||||
|
|
||||||
def find_auth_user_by_forgot_password_id(self, id: str) -> Optional[AuthUser]:
|
def find_auth_user_by_forgot_password_id(self, id: str) -> Optional[AuthUser]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -164,9 +152,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._user_from_result(result[0])
|
||||||
|
|
||||||
return self._user_from_result(result)
|
|
||||||
|
|
||||||
def add_auth_user(self, user: AuthUser):
|
def add_auth_user(self, user: AuthUser):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user.insert_string}")
|
||||||
|
@ -23,27 +23,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
|||||||
|
|
||||||
AutoRoleRepositoryABC.__init__(self)
|
AutoRoleRepositoryABC.__init__(self)
|
||||||
|
|
||||||
def get_auto_roles(self) -> List[AutoRole]:
|
def _from_result(self, result: tuple) -> AutoRole:
|
||||||
auto_roles = List(AutoRole)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_all_string()}")
|
|
||||||
results = self._context.select(AutoRole.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
auto_roles.append(
|
|
||||||
AutoRole(
|
|
||||||
self._servers.get_server_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return auto_roles
|
|
||||||
|
|
||||||
def get_auto_role_by_id(self, id: int) -> AutoRole:
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}")
|
|
||||||
result = self._context.select(AutoRole.get_select_by_id_string(id))[0]
|
|
||||||
return AutoRole(
|
return AutoRole(
|
||||||
self._servers.get_server_by_id(result[1]),
|
self._servers.get_server_by_id(result[1]),
|
||||||
result[2],
|
result[2],
|
||||||
@ -53,55 +33,37 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
|||||||
id=result[0],
|
id=result[0],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_auto_roles(self) -> List[AutoRole]:
|
||||||
|
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_all_string()}")
|
||||||
|
return List(
|
||||||
|
AutoRole, [self._from_result(result) for result in self._context.select(AutoRole.get_select_all_string())]
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_auto_role_by_id(self, id: int) -> AutoRole:
|
||||||
|
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}")
|
||||||
|
return self._from_result(self._context.select(AutoRole.get_select_by_id_string(id))[0])
|
||||||
|
|
||||||
def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]:
|
def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}")
|
||||||
result = self._context.select(AutoRole.get_select_by_id_string(id))
|
result = self._context.select(AutoRole.get_select_by_id_string(id))
|
||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return AutoRole(
|
|
||||||
self._servers.get_server_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]:
|
def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_server_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_server_id_string(id)}")
|
||||||
auto_roles = List(AutoRole)
|
return List(
|
||||||
results = self._context.select(AutoRole.get_select_by_server_id_string(id))
|
AutoRole,
|
||||||
for result in results:
|
[self._from_result(result) for result in self._context.select(AutoRole.get_select_by_server_id_string(id))],
|
||||||
auto_roles.append(
|
|
||||||
AutoRole(
|
|
||||||
self._servers.get_server_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return auto_roles
|
|
||||||
|
|
||||||
def get_auto_role_by_message_id(self, id: int) -> AutoRole:
|
def get_auto_role_by_message_id(self, id: int) -> AutoRole:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {AutoRole.get_select_by_message_id_string(id)}",
|
f"Send SQL command: {AutoRole.get_select_by_message_id_string(id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(AutoRole.get_select_by_message_id_string(id))[0]
|
return self._from_result(self._context.select(AutoRole.get_select_by_message_id_string(id))[0])
|
||||||
return AutoRole(
|
|
||||||
self._servers.get_server_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]:
|
def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -112,16 +74,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return AutoRole(
|
|
||||||
self._servers.get_server_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def add_auto_role(self, auto_role: AutoRole):
|
def add_auto_role(self, auto_role: AutoRole):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {auto_role.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {auto_role.insert_string}")
|
||||||
@ -135,27 +88,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
|||||||
self._logger.trace(__name__, f"Send SQL command: {auto_role.delete_string}")
|
self._logger.trace(__name__, f"Send SQL command: {auto_role.delete_string}")
|
||||||
self._context.cursor.execute(auto_role.delete_string)
|
self._context.cursor.execute(auto_role.delete_string)
|
||||||
|
|
||||||
def get_auto_role_rules(self) -> List[AutoRoleRule]:
|
def _rule_from_result(self, result: tuple) -> AutoRoleRule:
|
||||||
auto_role_rules = List(AutoRoleRule)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_all_string()}")
|
|
||||||
results = self._context.select(AutoRoleRule.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
auto_role_rules.append(
|
|
||||||
AutoRoleRule(
|
|
||||||
self.get_auto_role_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return auto_role_rules
|
|
||||||
|
|
||||||
def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule:
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_by_id_string(id)}")
|
|
||||||
result = self._context.select(AutoRoleRule.get_select_by_id_string(id))[0]
|
|
||||||
return AutoRoleRule(
|
return AutoRoleRule(
|
||||||
self.get_auto_role_by_id(result[1]),
|
self.get_auto_role_by_id(result[1]),
|
||||||
result[2],
|
result[2],
|
||||||
@ -165,26 +98,29 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
|||||||
id=result[0],
|
id=result[0],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_auto_role_rules(self) -> List[AutoRoleRule]:
|
||||||
|
self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_all_string()}")
|
||||||
|
return List(
|
||||||
|
AutoRoleRule,
|
||||||
|
[self._rule_from_result(result) for result in self._context.select(AutoRoleRule.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule:
|
||||||
|
self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_by_id_string(id)}")
|
||||||
|
return self._rule_from_result(self._context.select(AutoRoleRule.get_select_by_id_string(id))[0])
|
||||||
|
|
||||||
def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]:
|
def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]:
|
||||||
auto_role_rules = List(AutoRoleRule)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {AutoRoleRule.get_select_by_auto_role_id_string(id)}",
|
f"Send SQL command: {AutoRoleRule.get_select_by_auto_role_id_string(id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(AutoRoleRule.get_select_by_auto_role_id_string(id))
|
return List(
|
||||||
for result in results:
|
AutoRoleRule,
|
||||||
auto_role_rules.append(
|
[
|
||||||
AutoRoleRule(
|
self._rule_from_result(result)
|
||||||
self.get_auto_role_by_id(result[1]),
|
for result in self._context.select(AutoRoleRule.get_select_by_auto_role_id_string(id))
|
||||||
result[2],
|
],
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return auto_role_rules
|
|
||||||
|
|
||||||
def add_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
def add_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {auto_role_rule.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {auto_role_rule.insert_string}")
|
||||||
|
@ -23,32 +23,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
|||||||
|
|
||||||
ClientRepositoryABC.__init__(self)
|
ClientRepositoryABC.__init__(self)
|
||||||
|
|
||||||
def get_clients(self) -> List[Client]:
|
def _from_result(self, result: tuple) -> Client:
|
||||||
clients = List(Client)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Client.get_select_all_string()}")
|
|
||||||
results = self._context.select(Client.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get client with id {result[0]}")
|
|
||||||
clients.append(
|
|
||||||
Client(
|
|
||||||
result[1],
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
result[6],
|
|
||||||
self._servers.get_server_by_id(result[7]),
|
|
||||||
result[8],
|
|
||||||
result[9],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return clients
|
|
||||||
|
|
||||||
def get_client_by_id(self, client_id: int) -> Client:
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Client.get_select_by_id_string(client_id)}")
|
|
||||||
result = self._context.select(Client.get_select_by_id_string(client_id))
|
|
||||||
return Client(
|
return Client(
|
||||||
result[1],
|
result[1],
|
||||||
result[2],
|
result[2],
|
||||||
@ -62,49 +37,37 @@ class ClientRepositoryService(ClientRepositoryABC):
|
|||||||
id=result[0],
|
id=result[0],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_clients(self) -> List[Client]:
|
||||||
|
self._logger.trace(__name__, f"Send SQL command: {Client.get_select_all_string()}")
|
||||||
|
|
||||||
|
return List(
|
||||||
|
Client, [self._from_result(result) for result in self._context.select(Client.get_select_all_string())]
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_client_by_id(self, client_id: int) -> Client:
|
||||||
|
self._logger.trace(__name__, f"Send SQL command: {Client.get_select_by_id_string(client_id)}")
|
||||||
|
return self._from_result(self._context.select(Client.get_select_by_id_string(client_id))[0])
|
||||||
|
|
||||||
def get_clients_by_server_id(self, server_id: int) -> List[Client]:
|
def get_clients_by_server_id(self, server_id: int) -> List[Client]:
|
||||||
clients = List(Client)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {Client.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {Client.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(Client.get_select_by_server_id_string(server_id))
|
|
||||||
for result in results:
|
|
||||||
clients.append(
|
|
||||||
Client(
|
|
||||||
result[1],
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
result[6],
|
|
||||||
self._servers.get_server_by_id(result[7]),
|
|
||||||
result[8],
|
|
||||||
result[9],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return clients
|
return List(
|
||||||
|
Client,
|
||||||
|
[
|
||||||
|
self._from_result(result)
|
||||||
|
for result in self._context.select(Client.get_select_by_server_id_string(server_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {Client.get_select_by_discord_id_string(discord_id)}",
|
f"Send SQL command: {Client.get_select_by_discord_id_string(discord_id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(Client.get_select_by_discord_id_string(discord_id))[0]
|
return self._from_result(self._context.select(Client.get_select_by_discord_id_string(discord_id))[0])
|
||||||
return Client(
|
|
||||||
result[1],
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
result[6],
|
|
||||||
self._servers.get_server_by_id(result[7]),
|
|
||||||
result[8],
|
|
||||||
result[9],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -115,20 +78,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return Client(
|
|
||||||
result[1],
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
result[6],
|
|
||||||
self._servers.get_server_by_id(result[7]),
|
|
||||||
result[8],
|
|
||||||
result[9],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def find_client_by_server_id(self, discord_id: int) -> Optional[Client]:
|
def find_client_by_server_id(self, discord_id: int) -> Optional[Client]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -139,20 +89,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return Client(
|
|
||||||
result[1],
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
result[6],
|
|
||||||
self._servers.get_server_by_id(result[7]),
|
|
||||||
result[8],
|
|
||||||
result[9],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]:
|
def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -163,20 +100,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return Client(
|
|
||||||
result[1],
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
result[6],
|
|
||||||
self._servers.get_server_by_id(result[7]),
|
|
||||||
result[8],
|
|
||||||
result[9],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def add_client(self, client: Client):
|
def add_client(self, client: Client):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {client.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {client.insert_string}")
|
||||||
|
@ -35,49 +35,49 @@ class GameServerRepositoryService(GameServerRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_game_servers(self) -> List[GameServer]:
|
def get_game_servers(self) -> List[GameServer]:
|
||||||
game_servers = List(GameServer)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {GameServer.get_select_all_string()}",
|
f"Send SQL command: {GameServer.get_select_all_string()}",
|
||||||
)
|
)
|
||||||
results = self._context.select(GameServer.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user-joined-game-server with id {result[0]}")
|
|
||||||
game_servers.append(self._from_result(result))
|
|
||||||
|
|
||||||
return game_servers
|
return List(
|
||||||
|
GameServer,
|
||||||
|
[self._from_result(result) for result in self._context.select(GameServer.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
def get_game_servers_by_server_id(self, id: int) -> List[GameServer]:
|
def get_game_servers_by_server_id(self, id: int) -> List[GameServer]:
|
||||||
game_servers = List(GameServer)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {GameServer.get_select_by_server_id_string(id)}",
|
f"Send SQL command: {GameServer.get_select_by_server_id_string(id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(GameServer.get_select_by_server_id_string(id))
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user-joined-game-server with id {result[0]}")
|
|
||||||
game_servers.append(self._from_result(result))
|
|
||||||
|
|
||||||
return game_servers
|
return List(
|
||||||
|
GameServer,
|
||||||
|
[
|
||||||
|
self._from_result(result)
|
||||||
|
for result in self._context.select(GameServer.get_select_by_server_id_string(id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_game_server_by_id(self, id: int) -> GameServer:
|
def get_game_server_by_id(self, id: int) -> GameServer:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {GameServer.get_select_by_id_string(id)}",
|
f"Send SQL command: {GameServer.get_select_by_id_string(id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(GameServer.get_select_by_id_string(id))[0]
|
return self._from_result(self._context.select(GameServer.get_select_by_id_string(id))[0])
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_game_servers_by_api_key_id(self, id: int) -> List[GameServer]:
|
def get_game_servers_by_api_key_id(self, id: int) -> List[GameServer]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {GameServer.get_select_by_api_key_id_string(id)}",
|
f"Send SQL command: {GameServer.get_select_by_api_key_id_string(id)}",
|
||||||
)
|
)
|
||||||
game_servers = List(GameServer)
|
return List(
|
||||||
results = self._context.select(GameServer.get_select_by_api_key_id_string(id))
|
GameServer,
|
||||||
for result in results:
|
[
|
||||||
game_servers.append(self._from_result(result))
|
self._from_result(result)
|
||||||
return game_servers
|
for result in self._context.select(GameServer.get_select_by_api_key_id_string(id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def add_game_server(self, game_server: GameServer):
|
def add_game_server(self, game_server: GameServer):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {game_server.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {game_server.insert_string}")
|
||||||
|
@ -4,8 +4,8 @@ from cpl_core.database.context import DatabaseContextABC
|
|||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
|
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
from bot_core.logging.database_logger import DatabaseLogger
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
|
||||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
from bot_data.model.level import Level
|
from bot_data.model.level import Level
|
||||||
|
|
||||||
|
|
||||||
@ -41,20 +41,15 @@ class LevelRepositoryService(LevelRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_levels(self) -> List[Level]:
|
def get_levels(self) -> List[Level]:
|
||||||
levels = List(Level)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Level.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {Level.get_select_all_string()}")
|
||||||
results = self._context.select(Level.get_select_all_string())
|
return List(
|
||||||
for result in results:
|
Level, [self._level_from_result(result) for result in self._context.select(Level.get_select_all_string())]
|
||||||
self._logger.trace(__name__, f"Get level with id {result[0]}")
|
)
|
||||||
levels.append(self._level_from_result(result))
|
|
||||||
|
|
||||||
return levels
|
|
||||||
|
|
||||||
def get_level_by_id(self, id: int) -> Level:
|
def get_level_by_id(self, id: int) -> Level:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}")
|
||||||
result = self._context.select(Level.get_select_by_id_string(id))[0]
|
|
||||||
|
|
||||||
return self._level_from_result(result)
|
return self._level_from_result(self._context.select(Level.get_select_by_id_string(id))[0])
|
||||||
|
|
||||||
def find_level_by_id(self, id: int) -> Optional[Level]:
|
def find_level_by_id(self, id: int) -> Optional[Level]:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}")
|
||||||
@ -65,21 +60,19 @@ class LevelRepositoryService(LevelRepositoryABC):
|
|||||||
return self._level_from_result(result[0])
|
return self._level_from_result(result[0])
|
||||||
|
|
||||||
def get_levels_by_server_id(self, server_id: int) -> List[Level]:
|
def get_levels_by_server_id(self, server_id: int) -> List[Level]:
|
||||||
levels = List(Level)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(Level.get_select_by_server_id_string(server_id))
|
return List(
|
||||||
|
Level,
|
||||||
for result in results:
|
[
|
||||||
self._logger.trace(__name__, f"Get level with id {result[0]}")
|
self._level_from_result(result)
|
||||||
levels.append(self._level_from_result(result))
|
for result in self._context.select(Level.get_select_by_server_id_string(server_id))
|
||||||
|
],
|
||||||
return levels
|
)
|
||||||
|
|
||||||
def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]:
|
def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]:
|
||||||
levels = List(Level)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}",
|
||||||
@ -88,11 +81,10 @@ class LevelRepositoryService(LevelRepositoryABC):
|
|||||||
if results is None or len(results) == 0:
|
if results is None or len(results) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for result in results:
|
return List(
|
||||||
self._logger.trace(__name__, f"Get level with id {result[0]}")
|
Level,
|
||||||
levels.append(self._level_from_result(result))
|
[self._level_from_result(result) for result in results],
|
||||||
|
)
|
||||||
return levels
|
|
||||||
|
|
||||||
def add_level(self, level: Level):
|
def add_level(self, level: Level):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {level.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {level.insert_string}")
|
||||||
|
@ -5,8 +5,8 @@ from cpl_query.extension import List
|
|||||||
from discord import EntityType
|
from discord import EntityType
|
||||||
|
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
from bot_core.logging.database_logger import DatabaseLogger
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
|
||||||
from bot_data.abc.scheduled_event_repository_abc import ScheduledEventRepositoryABC
|
from bot_data.abc.scheduled_event_repository_abc import ScheduledEventRepositoryABC
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
from bot_data.model.scheduled_event import ScheduledEvent
|
from bot_data.model.scheduled_event import ScheduledEvent
|
||||||
from bot_data.model.scheduled_event_interval_enum import ScheduledEventIntervalEnum
|
from bot_data.model.scheduled_event_interval_enum import ScheduledEventIntervalEnum
|
||||||
|
|
||||||
@ -49,34 +49,34 @@ class ScheduledEventRepositoryService(ScheduledEventRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_scheduled_events(self) -> List[ScheduledEvent]:
|
def get_scheduled_events(self) -> List[ScheduledEvent]:
|
||||||
scheduled_events = List(ScheduledEvent)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ScheduledEvent.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {ScheduledEvent.get_select_all_string()}")
|
||||||
results = self._context.select(ScheduledEvent.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get scheduled_event with id {result[0]}")
|
|
||||||
scheduled_events.append(self._scheduled_event_from_result(result))
|
|
||||||
|
|
||||||
return scheduled_events
|
return List(
|
||||||
|
ScheduledEvent,
|
||||||
|
[
|
||||||
|
self._scheduled_event_from_result(result)
|
||||||
|
for result in self._context.select(ScheduledEvent.get_select_all_string())
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_scheduled_event_by_id(self, id: int) -> ScheduledEvent:
|
def get_scheduled_event_by_id(self, id: int) -> ScheduledEvent:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ScheduledEvent.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {ScheduledEvent.get_select_by_id_string(id)}")
|
||||||
result = self._context.select(ScheduledEvent.get_select_by_id_string(id))[0]
|
|
||||||
|
|
||||||
return self._scheduled_event_from_result(result)
|
return self._scheduled_event_from_result(self._context.select(ScheduledEvent.get_select_by_id_string(id))[0])
|
||||||
|
|
||||||
def get_scheduled_events_by_server_id(self, server_id: int) -> List[ScheduledEvent]:
|
def get_scheduled_events_by_server_id(self, server_id: int) -> List[ScheduledEvent]:
|
||||||
scheduled_events = List(ScheduledEvent)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {ScheduledEvent.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {ScheduledEvent.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(ScheduledEvent.get_select_by_server_id_string(server_id))
|
|
||||||
|
|
||||||
for result in results:
|
return List(
|
||||||
self._logger.trace(__name__, f"Get scheduled_event with id {result[0]}")
|
ScheduledEvent,
|
||||||
scheduled_events.append(self._scheduled_event_from_result(result))
|
[
|
||||||
|
self._scheduled_event_from_result(result)
|
||||||
return scheduled_events
|
for result in self._context.select(ScheduledEvent.get_select_by_server_id_string(server_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def add_scheduled_event(self, scheduled_event: ScheduledEvent):
|
def add_scheduled_event(self, scheduled_event: ScheduledEvent):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {scheduled_event.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {scheduled_event.insert_string}")
|
||||||
|
@ -26,15 +26,14 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC):
|
|||||||
self._servers = servers
|
self._servers = servers
|
||||||
|
|
||||||
def _get_team_role_ids(self, server_id: int) -> List[ServerTeamRoleIdsConfig]:
|
def _get_team_role_ids(self, server_id: int) -> List[ServerTeamRoleIdsConfig]:
|
||||||
ids = List(ServerTeamRoleIdsConfig)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {ServerTeamRoleIdsConfig.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {ServerTeamRoleIdsConfig.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(ServerTeamRoleIdsConfig.get_select_by_server_id_string(server_id))
|
|
||||||
for result in results:
|
return List(
|
||||||
self._logger.trace(__name__, f"Got ServerTeamRoleIdsConfig with id {result[0]}")
|
ServerTeamRoleIdsConfig,
|
||||||
ids.append(
|
[
|
||||||
ServerTeamRoleIdsConfig(
|
ServerTeamRoleIdsConfig(
|
||||||
result[1],
|
result[1],
|
||||||
TeamMemberTypeEnum(result[2]),
|
TeamMemberTypeEnum(result[2]),
|
||||||
@ -43,22 +42,23 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC):
|
|||||||
result[5],
|
result[5],
|
||||||
id=result[0],
|
id=result[0],
|
||||||
)
|
)
|
||||||
|
for result in self._context.select(ServerTeamRoleIdsConfig.get_select_by_server_id_string(server_id))
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
return ids
|
|
||||||
|
|
||||||
def _get_afk_channel_ids(self, server_id: int) -> List[int]:
|
def _get_afk_channel_ids(self, server_id: int) -> List[int]:
|
||||||
urls = List(int)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {ServerAFKChannelIdsConfig.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {ServerAFKChannelIdsConfig.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(ServerAFKChannelIdsConfig.get_select_by_server_id_string(server_id))
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Got ServerAFKChannelIdsConfig with id {result[0]}")
|
|
||||||
urls.append(result[1])
|
|
||||||
|
|
||||||
return urls
|
return List(
|
||||||
|
int,
|
||||||
|
[
|
||||||
|
result[1]
|
||||||
|
for result in self._context.select(ServerAFKChannelIdsConfig.get_select_by_server_id_string(server_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def _from_result(self, result: tuple) -> ServerConfig:
|
def _from_result(self, result: tuple) -> ServerConfig:
|
||||||
return ServerConfig(
|
return ServerConfig(
|
||||||
@ -102,18 +102,14 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC):
|
|||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {ServerConfig.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {ServerConfig.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(ServerConfig.get_select_by_server_id_string(server_id))[0]
|
return self._from_result(self._context.select(ServerConfig.get_select_by_server_id_string(server_id))[0])
|
||||||
|
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_server_config_by_id(self, config_id: int) -> ServerConfig:
|
def get_server_config_by_id(self, config_id: int) -> ServerConfig:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {ServerConfig.get_select_by_id_string(config_id)}",
|
f"Send SQL command: {ServerConfig.get_select_by_id_string(config_id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(ServerConfig.get_select_by_id_string(config_id))[0]
|
return self._from_result(self._context.select(ServerConfig.get_select_by_id_string(config_id))[0])
|
||||||
|
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def add_server_config(self, server_config: ServerConfig):
|
def add_server_config(self, server_config: ServerConfig):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {server_config.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {server_config.insert_string}")
|
||||||
|
@ -25,12 +25,15 @@ class ServerRepositoryService(ServerRepositoryABC):
|
|||||||
ServerRepositoryABC.__init__(self)
|
ServerRepositoryABC.__init__(self)
|
||||||
|
|
||||||
def get_servers(self) -> List[Server]:
|
def get_servers(self) -> List[Server]:
|
||||||
servers = List(Server)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {Server.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {Server.get_select_all_string()}")
|
||||||
results = self._context.select(Server.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
servers.append(Server(result[1], result[2], result[3], id=result[0]))
|
|
||||||
|
|
||||||
|
servers = List(
|
||||||
|
Server,
|
||||||
|
[
|
||||||
|
Server(result[1], result[2], result[3], id=result[0])
|
||||||
|
for result in self._context.select(Server.get_select_all_string())
|
||||||
|
],
|
||||||
|
)
|
||||||
self._cache.add_servers(servers)
|
self._cache.add_servers(servers)
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
@ -96,9 +99,7 @@ class ServerRepositoryService(ServerRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return Server(result[0][1], result[0][2], result[0][3], id=result[0][0])
|
||||||
|
|
||||||
return Server(result[1], result[2], result[3], id=result[0])
|
|
||||||
|
|
||||||
def add_server(self, server: Server):
|
def add_server(self, server: Server):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {server.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {server.insert_string}")
|
||||||
|
@ -43,14 +43,15 @@ class ShortRoleNameRepositoryService(ShortRoleNameRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_short_role_names(self) -> List[ShortRoleName]:
|
def get_short_role_names(self) -> List[ShortRoleName]:
|
||||||
short_role_names = List(ShortRoleName)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ShortRoleName.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {ShortRoleName.get_select_all_string()}")
|
||||||
results = self._context.select(ShortRoleName.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get short_role_name with id {result[0]}")
|
|
||||||
short_role_names.append(self._short_role_name_from_result(result))
|
|
||||||
|
|
||||||
return short_role_names
|
return List(
|
||||||
|
ShortRoleName,
|
||||||
|
[
|
||||||
|
self._short_role_name_from_result(result)
|
||||||
|
for result in self._context.select(ShortRoleName.get_select_all_string())
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_short_role_name_by_id(self, id: int) -> ShortRoleName:
|
def get_short_role_name_by_id(self, id: int) -> ShortRoleName:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ShortRoleName.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {ShortRoleName.get_select_by_id_string(id)}")
|
||||||
@ -59,31 +60,30 @@ class ShortRoleNameRepositoryService(ShortRoleNameRepositoryABC):
|
|||||||
return self._short_role_name_from_result(result)
|
return self._short_role_name_from_result(result)
|
||||||
|
|
||||||
def find_short_role_names_by_role_id(self, role_id: int) -> List[ShortRoleName]:
|
def find_short_role_names_by_role_id(self, role_id: int) -> List[ShortRoleName]:
|
||||||
short_role_names = List(ShortRoleName)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {ShortRoleName.get_select_by_role_id_string(role_id)}",
|
f"Send SQL command: {ShortRoleName.get_select_by_role_id_string(role_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(ShortRoleName.get_select_by_role_id_string(role_id))
|
return List(
|
||||||
for result in results:
|
ShortRoleName,
|
||||||
self._logger.trace(__name__, f"Get short_role_name with id {result[0]}")
|
[
|
||||||
short_role_names.append(self._short_role_name_from_result(result))
|
self._short_role_name_from_result(result)
|
||||||
|
for result in self._context.select(ShortRoleName.get_select_by_role_id_string(role_id))
|
||||||
return short_role_names
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_short_role_names_by_server_id(self, server_id: int) -> List[ShortRoleName]:
|
def get_short_role_names_by_server_id(self, server_id: int) -> List[ShortRoleName]:
|
||||||
short_role_names = List(ShortRoleName)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {ShortRoleName.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {ShortRoleName.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(ShortRoleName.get_select_by_server_id_string(server_id))
|
return List(
|
||||||
|
ShortRoleName,
|
||||||
for result in results:
|
[
|
||||||
self._logger.trace(__name__, f"Get short_role_name with id {result[0]}")
|
self._short_role_name_from_result(result)
|
||||||
short_role_names.append(self._short_role_name_from_result(result))
|
for result in self._context.select(ShortRoleName.get_select_by_server_id_string(server_id))
|
||||||
|
],
|
||||||
return short_role_names
|
)
|
||||||
|
|
||||||
def add_short_role_name(self, short_role_name: ShortRoleName):
|
def add_short_role_name(self, short_role_name: ShortRoleName):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {short_role_name.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {short_role_name.insert_string}")
|
||||||
|
@ -42,23 +42,24 @@ class SteamSpecialOfferRepositoryService(SteamSpecialOfferRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_steam_special_offers(self) -> List[SteamSpecialOffer]:
|
def get_steam_special_offers(self) -> List[SteamSpecialOffer]:
|
||||||
steam_special_offers = List(SteamSpecialOffer)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {SteamSpecialOffer.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {SteamSpecialOffer.get_select_all_string()}")
|
||||||
results = self._context.select(SteamSpecialOffer.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get steam_special_offer with id {result[0]}")
|
|
||||||
steam_special_offers.append(self._steam_special_offer_from_result(result))
|
|
||||||
|
|
||||||
return steam_special_offers
|
return List(
|
||||||
|
SteamSpecialOffer,
|
||||||
|
[
|
||||||
|
self._steam_special_offer_from_result(result)
|
||||||
|
for result in self._context.select(SteamSpecialOffer.get_select_all_string())
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_steam_special_offer_by_name(self, name: str) -> SteamSpecialOffer:
|
def get_steam_special_offer_by_name(self, name: str) -> SteamSpecialOffer:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {SteamSpecialOffer.get_select_by_name_string(name)}",
|
f"Send SQL command: {SteamSpecialOffer.get_select_by_name_string(name)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(SteamSpecialOffer.get_select_by_name_string(name))[0]
|
return self._steam_special_offer_from_result(
|
||||||
|
self._context.select(SteamSpecialOffer.get_select_by_name_string(name))[0]
|
||||||
return self._steam_special_offer_from_result(result)
|
)
|
||||||
|
|
||||||
def add_steam_special_offer(self, steam_special_offer: SteamSpecialOffer):
|
def add_steam_special_offer(self, steam_special_offer: SteamSpecialOffer):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {steam_special_offer.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {steam_special_offer.insert_string}")
|
||||||
|
@ -18,27 +18,17 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC):
|
|||||||
self._context = db_context
|
self._context = db_context
|
||||||
|
|
||||||
def _get_technician_ids(self) -> List[int]:
|
def _get_technician_ids(self) -> List[int]:
|
||||||
ids = List(int)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {TechnicianIdConfig.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {TechnicianIdConfig.get_select_all_string()}")
|
||||||
results = self._context.select(TechnicianIdConfig.get_select_all_string())
|
return List(int, [config[1] for config in self._context.select(TechnicianIdConfig.get_select_all_string())])
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Got TechnicianId with id {result[0]}")
|
|
||||||
ids.append(result[1])
|
|
||||||
|
|
||||||
return ids
|
|
||||||
|
|
||||||
def _get_technician_ping_urls(self) -> List[str]:
|
def _get_technician_ping_urls(self) -> List[str]:
|
||||||
urls = List(str)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {TechnicianPingUrlConfig.get_select_all_string()}",
|
f"Send SQL command: {TechnicianPingUrlConfig.get_select_all_string()}",
|
||||||
)
|
)
|
||||||
results = self._context.select(TechnicianPingUrlConfig.get_select_all_string())
|
return List(
|
||||||
for result in results:
|
str, [ping_url[1] for ping_url in self._context.select(TechnicianPingUrlConfig.get_select_all_string())]
|
||||||
self._logger.trace(__name__, f"Got TechnicianPingUrl with id {result[0]}")
|
)
|
||||||
urls.append(result[1])
|
|
||||||
|
|
||||||
return urls
|
|
||||||
|
|
||||||
def _from_result(self, result: tuple) -> TechnicianConfig:
|
def _from_result(self, result: tuple) -> TechnicianConfig:
|
||||||
return TechnicianConfig(
|
return TechnicianConfig(
|
||||||
@ -64,9 +54,7 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC):
|
|||||||
|
|
||||||
def get_technician_config(self) -> TechnicianConfig:
|
def get_technician_config(self) -> TechnicianConfig:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {TechnicianConfig.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {TechnicianConfig.get_select_all_string()}")
|
||||||
result = self._context.select(TechnicianConfig.get_select_all_string())[0]
|
return self._from_result(self._context.select(TechnicianConfig.get_select_all_string())[0])
|
||||||
|
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def add_technician_config(self, technician_config: TechnicianConfig):
|
def add_technician_config(self, technician_config: TechnicianConfig):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {technician_config.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {technician_config.insert_string}")
|
||||||
|
@ -39,46 +39,47 @@ class UserGameIdentRepositoryService(UserGameIdentRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_user_game_idents(self) -> List[UserGameIdent]:
|
def get_user_game_idents(self) -> List[UserGameIdent]:
|
||||||
joins = List(UserGameIdent)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserGameIdent.get_select_all_string()}",
|
f"Send SQL command: {UserGameIdent.get_select_all_string()}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserGameIdent.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get UserGameIdent with id {result[0]}")
|
|
||||||
joins.append(self._from_result(result))
|
|
||||||
|
|
||||||
return joins
|
return List(
|
||||||
|
UserGameIdent,
|
||||||
|
[
|
||||||
|
self._from_result(game_ident)
|
||||||
|
for game_ident in self._context.select(UserGameIdent.get_select_all_string())
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_user_game_idents_by_game_server_id(self, game_server_id: int) -> List[UserGameIdent]:
|
def get_user_game_idents_by_game_server_id(self, game_server_id: int) -> List[UserGameIdent]:
|
||||||
joins = List(UserGameIdent)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserGameIdent.get_select_by_game_server_id_string(game_server_id)}",
|
f"Send SQL command: {UserGameIdent.get_select_by_game_server_id_string(game_server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserGameIdent.get_select_by_game_server_id_string(game_server_id))
|
return List(
|
||||||
for result in results:
|
UserGameIdent,
|
||||||
self._logger.trace(__name__, f"Get UserGameIdent with id {result[0]}")
|
[
|
||||||
joins.append(self._from_result(result))
|
self._from_result(game_ident)
|
||||||
|
for game_ident in self._context.select(
|
||||||
return joins
|
UserGameIdent.get_select_by_game_server_id_string(game_server_id)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserGameIdent.get_select_by_id_string(id)}",
|
f"Send SQL command: {UserGameIdent.get_select_by_id_string(id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserGameIdent.get_select_by_id_string(id))[0]
|
return self._from_result(self._context.select(UserGameIdent.get_select_by_id_string(id))[0])
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_user_game_ident_by_ident(self, ident: str) -> UserGameIdent:
|
def get_user_game_ident_by_ident(self, ident: str) -> UserGameIdent:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserGameIdent.get_select_by_ident_string(ident)}",
|
f"Send SQL command: {UserGameIdent.get_select_by_ident_string(ident)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserGameIdent.get_select_by_ident_string(ident))[0]
|
return self._from_result(self._context.select(UserGameIdent.get_select_by_ident_string(ident))[0])
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def find_user_game_ident_by_ident(self, ident: str) -> Optional[UserGameIdent]:
|
def find_user_game_ident_by_ident(self, ident: str) -> Optional[UserGameIdent]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -89,20 +90,20 @@ class UserGameIdentRepositoryService(UserGameIdentRepositoryABC):
|
|||||||
if len(result) == 0:
|
if len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_user_game_idents_by_user_id(self, user_id: int) -> List[UserGameIdent]:
|
def get_user_game_idents_by_user_id(self, user_id: int) -> List[UserGameIdent]:
|
||||||
joins = List(UserGameIdent)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserGameIdent.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserGameIdent.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserGameIdent.get_select_by_user_id_string(user_id))
|
return List(
|
||||||
for result in results:
|
UserGameIdent,
|
||||||
joins.append(self._from_result(result))
|
[
|
||||||
|
self._from_result(game_ident)
|
||||||
return joins
|
for game_ident in self._context.select(UserGameIdent.get_select_by_user_id_string(user_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def add_user_game_ident(self, user_game_ident: UserGameIdent):
|
def add_user_game_ident(self, user_game_ident: UserGameIdent):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user_game_ident.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user_game_ident.insert_string}")
|
||||||
|
@ -39,45 +39,45 @@ class UserJoinedGameServerRepositoryService(UserJoinedGameServerRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_user_joined_game_servers(self) -> List[UserJoinedGameServer]:
|
def get_user_joined_game_servers(self) -> List[UserJoinedGameServer]:
|
||||||
joins = List(UserJoinedGameServer)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedGameServer.get_select_all_string()}",
|
f"Send SQL command: {UserJoinedGameServer.get_select_all_string()}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserJoinedGameServer.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user-joined-game-server with id {result[0]}")
|
|
||||||
joins.append(self._from_result(result))
|
|
||||||
|
|
||||||
return joins
|
return List(
|
||||||
|
UserJoinedGameServer,
|
||||||
|
[self._from_result(join) for join in self._context.select(UserJoinedGameServer.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
def get_user_joined_game_server_by_id(self, id: int) -> UserJoinedGameServer:
|
def get_user_joined_game_server_by_id(self, id: int) -> UserJoinedGameServer:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedGameServer.get_select_by_id_string(id)}",
|
f"Send SQL command: {UserJoinedGameServer.get_select_by_id_string(id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserJoinedGameServer.get_select_by_id_string(id))[0]
|
return self._from_result(self._context.select(UserJoinedGameServer.get_select_by_id_string(id))[0])
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_user_joined_game_servers_by_user_id(self, user_id: int) -> List[UserJoinedGameServer]:
|
def get_user_joined_game_servers_by_user_id(self, user_id: int) -> List[UserJoinedGameServer]:
|
||||||
joins = List(UserJoinedGameServer)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedGameServer.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedGameServer.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserJoinedGameServer.get_select_by_user_id_string(user_id))
|
|
||||||
for result in results:
|
|
||||||
joins.append(self._from_result(result))
|
|
||||||
|
|
||||||
return joins
|
return List(
|
||||||
|
UserJoinedGameServer,
|
||||||
|
[
|
||||||
|
self._from_result(join)
|
||||||
|
for join in self._context.select(UserJoinedGameServer.get_select_by_user_id_string(user_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_active_user_joined_game_server_by_user_id(self, user_id: int) -> UserJoinedGameServer:
|
def get_active_user_joined_game_server_by_user_id(self, user_id: int) -> UserJoinedGameServer:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedGameServer.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedGameServer.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserJoinedGameServer.get_select_active_by_user_id_string(user_id))[0]
|
return self._from_result(
|
||||||
return self._from_result(result)
|
self._context.select(UserJoinedGameServer.get_select_active_by_user_id_string(user_id))[0]
|
||||||
|
)
|
||||||
|
|
||||||
def find_active_user_joined_game_server_by_user_id(self, user_id: int) -> Optional[UserJoinedGameServer]:
|
def find_active_user_joined_game_server_by_user_id(self, user_id: int) -> Optional[UserJoinedGameServer]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -88,22 +88,21 @@ class UserJoinedGameServerRepositoryService(UserJoinedGameServerRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def find_active_user_joined_game_servers_by_user_id(self, user_id: int) -> List[Optional[UserJoinedGameServer]]:
|
def find_active_user_joined_game_servers_by_user_id(self, user_id: int) -> List[Optional[UserJoinedGameServer]]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedGameServer.get_select_active_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedGameServer.get_select_active_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
result = List(UserJoinedGameServer)
|
|
||||||
db_results = self._context.select(UserJoinedGameServer.get_select_active_by_user_id_string(user_id))
|
|
||||||
|
|
||||||
for db_result in db_results:
|
return List(
|
||||||
result.append(self._from_result(db_result))
|
UserJoinedGameServer,
|
||||||
|
[
|
||||||
return result
|
self._from_result(join)
|
||||||
|
for join in self._context.select(UserJoinedGameServer.get_select_active_by_user_id_string(user_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def add_user_joined_game_server(self, user_joined_game_server: UserJoinedGameServer):
|
def add_user_joined_game_server(self, user_joined_game_server: UserJoinedGameServer):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user_joined_game_server.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user_joined_game_server.insert_string}")
|
||||||
|
@ -23,14 +23,8 @@ class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
|||||||
|
|
||||||
UserJoinedServerRepositoryABC.__init__(self)
|
UserJoinedServerRepositoryABC.__init__(self)
|
||||||
|
|
||||||
def get_user_joined_servers(self) -> List[UserJoinedServer]:
|
def __from_result(self, result: tuple) -> UserJoinedServer:
|
||||||
joins = List(UserJoinedServer)
|
return UserJoinedServer(
|
||||||
self._logger.trace(__name__, f"Send SQL command: {UserJoinedServer.get_select_all_string()}")
|
|
||||||
results = self._context.select(UserJoinedServer.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user-joined-server with id {result[0]}")
|
|
||||||
joins.append(
|
|
||||||
UserJoinedServer(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
self._users.get_user_by_id(result[1]),
|
||||||
result[2],
|
result[2],
|
||||||
result[3],
|
result[3],
|
||||||
@ -38,74 +32,42 @@ class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
|||||||
result[5],
|
result[5],
|
||||||
id=result[0],
|
id=result[0],
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return joins
|
def get_user_joined_servers(self) -> List[UserJoinedServer]:
|
||||||
|
self._logger.trace(__name__, f"Send SQL command: {UserJoinedServer.get_select_all_string()}")
|
||||||
|
|
||||||
|
return List(
|
||||||
|
UserJoinedServer,
|
||||||
|
[self.__from_result(join) for join in self._context.select(UserJoinedServer.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedServer.get_select_by_id_string(id)}",
|
f"Send SQL command: {UserJoinedServer.get_select_by_id_string(id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserJoinedServer.get_select_by_id_string(id))[0]
|
return self.__from_result(self._context.select(UserJoinedServer.get_select_by_id_string(id))[0])
|
||||||
return UserJoinedServer(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_user_joined_server_by_server_id(self, server_id: int) -> UserJoinedServer:
|
|
||||||
self._logger.trace(
|
|
||||||
__name__,
|
|
||||||
f"Send SQL command: {UserJoinedServer.get(id)}",
|
|
||||||
)
|
|
||||||
result = self._context.select(UserJoinedServer.get_select_by_id_string(id))[0]
|
|
||||||
return UserJoinedServer(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> List[UserJoinedServer]:
|
def get_user_joined_servers_by_user_id(self, user_id: int) -> List[UserJoinedServer]:
|
||||||
joins = List(UserJoinedServer)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserJoinedServer.get_select_by_user_id_string(user_id))
|
return List(
|
||||||
for result in results:
|
UserJoinedServer,
|
||||||
joins.append(
|
[
|
||||||
UserJoinedServer(
|
self.__from_result(join)
|
||||||
self._users.get_user_by_id(result[1]),
|
for join in self._context.select(UserJoinedServer.get_select_by_user_id_string(user_id))
|
||||||
result[2],
|
],
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return joins
|
|
||||||
|
|
||||||
def get_active_user_joined_server_by_user_id(self, user_id: int) -> UserJoinedServer:
|
def get_active_user_joined_server_by_user_id(self, user_id: int) -> UserJoinedServer:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedServer.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserJoinedServer.get_select_active_by_user_id_string(user_id))[0]
|
return self.__from_result(
|
||||||
return UserJoinedServer(
|
self._context.select(UserJoinedServer.get_select_active_by_user_id_string(user_id))[0]
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def find_active_user_joined_server_by_user_id(self, user_id: int) -> Optional[UserJoinedServer]:
|
def find_active_user_joined_server_by_user_id(self, user_id: int) -> Optional[UserJoinedServer]:
|
||||||
@ -117,16 +79,7 @@ class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self.__from_result(result[0])
|
||||||
|
|
||||||
return UserJoinedServer(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def add_user_joined_server(self, user_joined_server: UserJoinedServer):
|
def add_user_joined_server(self, user_joined_server: UserJoinedServer):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user_joined_server.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user_joined_server.insert_string}")
|
||||||
|
@ -25,17 +25,8 @@ class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryAB
|
|||||||
|
|
||||||
UserJoinedVoiceChannelRepositoryABC.__init__(self)
|
UserJoinedVoiceChannelRepositoryABC.__init__(self)
|
||||||
|
|
||||||
def get_user_joined_voice_channels(self) -> List[UserJoinedVoiceChannel]:
|
def __from_result(self, result: tuple) -> UserJoinedVoiceChannel:
|
||||||
joins = List(UserJoinedVoiceChannel)
|
return UserJoinedVoiceChannel(
|
||||||
self._logger.trace(
|
|
||||||
__name__,
|
|
||||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_all_string()}",
|
|
||||||
)
|
|
||||||
results = self._context.select(UserJoinedVoiceChannel.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user-joined-voice-channel with id {result[0]}")
|
|
||||||
joins.append(
|
|
||||||
UserJoinedVoiceChannel(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
self._users.get_user_by_id(result[1]),
|
||||||
result[2],
|
result[2],
|
||||||
result[3],
|
result[3],
|
||||||
@ -43,59 +34,46 @@ class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryAB
|
|||||||
result[5],
|
result[5],
|
||||||
id=result[0],
|
id=result[0],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_user_joined_voice_channels(self) -> List[UserJoinedVoiceChannel]:
|
||||||
|
self._logger.trace(
|
||||||
|
__name__,
|
||||||
|
f"Send SQL command: {UserJoinedVoiceChannel.get_select_all_string()}",
|
||||||
)
|
)
|
||||||
|
|
||||||
return joins
|
return List(
|
||||||
|
UserJoinedVoiceChannel,
|
||||||
|
[self.__from_result(join) for join in self._context.select(UserJoinedVoiceChannel.get_select_all_string())],
|
||||||
|
)
|
||||||
|
|
||||||
def get_user_joined_voice_channel_by_id(self, id: int) -> UserJoinedVoiceChannel:
|
def get_user_joined_voice_channel_by_id(self, id: int) -> UserJoinedVoiceChannel:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_id_string(id)}",
|
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_id_string(id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserJoinedVoiceChannel.get_select_by_id_string(id))[0]
|
return self.__from_result(self._context.select(UserJoinedVoiceChannel.get_select_by_id_string(id))[0])
|
||||||
return UserJoinedVoiceChannel(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[UserJoinedVoiceChannel]:
|
def get_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[UserJoinedVoiceChannel]:
|
||||||
joins = List(UserJoinedVoiceChannel)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserJoinedVoiceChannel.get_select_by_user_id_string(user_id))
|
|
||||||
for result in results:
|
|
||||||
joins.append(
|
|
||||||
UserJoinedVoiceChannel(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return joins
|
return List(
|
||||||
|
UserJoinedVoiceChannel,
|
||||||
|
[
|
||||||
|
self.__from_result(join)
|
||||||
|
for join in self._context.select(UserJoinedVoiceChannel.get_select_by_user_id_string(user_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> UserJoinedVoiceChannel:
|
def get_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> UserJoinedVoiceChannel:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedVoiceChannel.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id))[0]
|
return self.__from_result(
|
||||||
return UserJoinedVoiceChannel(
|
self._context.select(UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id))[0]
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def find_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> Optional[UserJoinedVoiceChannel]:
|
def find_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> Optional[UserJoinedVoiceChannel]:
|
||||||
@ -107,38 +85,21 @@ class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryAB
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self.__from_result(result[0])
|
||||||
|
|
||||||
return UserJoinedVoiceChannel(
|
|
||||||
self._users.get_user_by_id(result[1]),
|
|
||||||
result[2],
|
|
||||||
result[3],
|
|
||||||
result[4],
|
|
||||||
result[5],
|
|
||||||
id=result[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
def find_active_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[Optional[UserJoinedVoiceChannel]]:
|
def find_active_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[Optional[UserJoinedVoiceChannel]]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
result = List(UserJoinedVoiceChannel)
|
|
||||||
db_results = self._context.select(UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id))
|
|
||||||
|
|
||||||
for db_result in db_results:
|
return List(
|
||||||
result.append(
|
UserJoinedVoiceChannel,
|
||||||
UserJoinedVoiceChannel(
|
[
|
||||||
self._users.get_user_by_id(db_result[1]),
|
self.__from_result(join)
|
||||||
db_result[2],
|
for join in self._context.select(UserJoinedVoiceChannel.get_select_active_by_user_id_string(user_id))
|
||||||
db_result[3],
|
],
|
||||||
db_result[4],
|
|
||||||
db_result[5],
|
|
||||||
id=db_result[0],
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def add_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel):
|
def add_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user_joined_voice_channel.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user_joined_voice_channel.insert_string}")
|
||||||
|
@ -44,39 +44,30 @@ class UserMessageCountPerHourRepositoryService(UserMessageCountPerHourRepository
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_user_message_count_per_hours(self) -> List[UserMessageCountPerHour]:
|
def get_user_message_count_per_hours(self) -> List[UserMessageCountPerHour]:
|
||||||
umcphs = List(UserMessageCountPerHour)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserMessageCountPerHour.get_select_all_string()}",
|
f"Send SQL command: {UserMessageCountPerHour.get_select_all_string()}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserMessageCountPerHour.get_select_all_string())
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user message count per hour with id {result[0]}")
|
|
||||||
umcphs.append(self._from_result(result))
|
|
||||||
|
|
||||||
return umcphs
|
return List(
|
||||||
|
UserMessageCountPerHour,
|
||||||
|
[
|
||||||
|
self._from_result(umcphs)
|
||||||
|
for umcphs in self._context.select(UserMessageCountPerHour.get_select_all_string())
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def find_user_message_count_per_hour_by_user_id(self, user_id: int) -> List[Optional[UserMessageCountPerHour]]:
|
def find_user_message_count_per_hour_by_user_id(self, user_id: int) -> List[Optional[UserMessageCountPerHour]]:
|
||||||
umcphs = List(UserMessageCountPerHour)
|
|
||||||
sql = UserMessageCountPerHour.get_select_by_user_id_string(user_id)
|
sql = UserMessageCountPerHour.get_select_by_user_id_string(user_id)
|
||||||
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
||||||
results = self._context.select(sql)
|
return List(UserMessageCountPerHour, [self._from_result(umcphs) for umcphs in self._context.select(sql)])
|
||||||
if results is None or len(results) == 0:
|
|
||||||
return umcphs
|
|
||||||
|
|
||||||
for result in results:
|
|
||||||
self._logger.trace(__name__, f"Get user message count per hour with id {result[0]}")
|
|
||||||
umcphs.append(self._from_result(result))
|
|
||||||
|
|
||||||
return umcphs
|
|
||||||
|
|
||||||
def get_user_message_count_per_hour_by_user_id_and_date(
|
def get_user_message_count_per_hour_by_user_id_and_date(
|
||||||
self, user_id: int, date: datetime
|
self, user_id: int, date: datetime
|
||||||
) -> UserMessageCountPerHour:
|
) -> UserMessageCountPerHour:
|
||||||
sql = UserMessageCountPerHour.get_select_by_user_id_and_date_string(user_id, date)
|
sql = UserMessageCountPerHour.get_select_by_user_id_and_date_string(user_id, date)
|
||||||
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
self._logger.trace(__name__, f"Send SQL command: {sql}")
|
||||||
result = self._context.select(sql)[0]
|
return self._from_result(self._context.select(sql)[0])
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def find_user_message_count_per_hour_by_user_id_and_date(
|
def find_user_message_count_per_hour_by_user_id_and_date(
|
||||||
self, user_id: int, date: datetime
|
self, user_id: int, date: datetime
|
||||||
|
@ -2,6 +2,7 @@ import datetime
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
from cpl_core.type import T, R
|
||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
|
|
||||||
from bot_core.logging.database_logger import DatabaseLogger
|
from bot_core.logging.database_logger import DatabaseLogger
|
||||||
@ -38,14 +39,10 @@ class UserRepositoryService(UserRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_users(self) -> List[User]:
|
def get_users(self) -> List[User]:
|
||||||
users = List(User)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {User.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {User.get_select_all_string()}")
|
||||||
results = self._context.select(User.get_select_all_string())
|
return List(
|
||||||
for result in results:
|
User, [self._from_result(user) for user in self._context.select(User.get_select_all_string())]
|
||||||
self._logger.trace(__name__, f"Get user with id {result[0]}")
|
).for_each(lambda x: self._set_user_activity(x))
|
||||||
users.append(self._from_result(result))
|
|
||||||
|
|
||||||
return users
|
|
||||||
|
|
||||||
def get_user_by_id(self, id: int) -> User:
|
def get_user_by_id(self, id: int) -> User:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {User.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {User.get_select_by_id_string(id)}")
|
||||||
@ -59,42 +56,50 @@ class UserRepositoryService(UserRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
||||||
users = List(User)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {User.get_select_by_discord_id_string(discord_id)}",
|
f"Send SQL command: {User.get_select_by_discord_id_string(discord_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(User.get_select_by_discord_id_string(discord_id))
|
return List(
|
||||||
for result in results:
|
User,
|
||||||
users.append(self._from_result(result))
|
[
|
||||||
|
self._from_result(user)
|
||||||
return users
|
for user in self._context.select(User.get_select_by_discord_id_string(discord_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
||||||
users = List(User)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {User.get_select_by_server_id_string(server_id)}",
|
f"Send SQL command: {User.get_select_by_server_id_string(server_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(User.get_select_by_server_id_string(server_id))
|
return List(
|
||||||
for result in results:
|
User,
|
||||||
users.append(self._from_result(result))
|
[self._from_result(user) for user in self._context.select(User.get_select_by_server_id_string(server_id))],
|
||||||
|
)
|
||||||
|
|
||||||
return users
|
def get_users_with_activity_by_server_id(self, server_id: int) -> List[User]:
|
||||||
|
self._logger.trace(
|
||||||
|
__name__,
|
||||||
|
f"Send SQL command: {User.get_select_by_server_id_string(server_id)}",
|
||||||
|
)
|
||||||
|
return List(
|
||||||
|
User,
|
||||||
|
[self._from_result(user) for user in self._context.select(User.get_select_by_server_id_string(server_id))],
|
||||||
|
).for_each(lambda x: self._set_user_activity(x))
|
||||||
|
|
||||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}",
|
f"Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}",
|
||||||
)
|
)
|
||||||
result = self._context.select(User.get_select_by_discord_id_and_server_id_string(discord_id, server_id))[0]
|
|
||||||
|
|
||||||
return self._from_result(result)
|
return self._from_result(
|
||||||
|
self._context.select(User.get_select_by_discord_id_and_server_id_string(discord_id, server_id))[0]
|
||||||
|
)
|
||||||
|
|
||||||
def find_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[User]:
|
def find_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[User]:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
@ -105,9 +110,7 @@ class UserRepositoryService(UserRepositoryABC):
|
|||||||
if result is None or len(result) == 0:
|
if result is None or len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result = result[0]
|
return self._from_result(result[0])
|
||||||
|
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def add_user(self, user: User):
|
def add_user(self, user: User):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user.insert_string}")
|
||||||
@ -120,3 +123,91 @@ class UserRepositoryService(UserRepositoryABC):
|
|||||||
def delete_user(self, user: User):
|
def delete_user(self, user: User):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user.delete_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user.delete_string}")
|
||||||
self._context.cursor.execute(user.delete_string)
|
self._context.cursor.execute(user.delete_string)
|
||||||
|
|
||||||
|
def _set_user_activity(self, user):
|
||||||
|
days = (datetime.date.today() - (datetime.date.today() - datetime.timedelta(days=7))).days
|
||||||
|
query = f"""
|
||||||
|
SELECT (
|
||||||
|
(
|
||||||
|
SELECT Count(UserGotAchievements.CreatedAt)
|
||||||
|
FROM UserGotAchievements
|
||||||
|
INNER JOIN Achievements ON UserGotAchievements.AchievementId = Achievements.Id
|
||||||
|
INNER JOIN Users ON UserGotAchievements.UserId = Users.UserId
|
||||||
|
WHERE Users.ServerId = {user.server.id}
|
||||||
|
AND Users.UserId = {user.id}
|
||||||
|
AND UserGotAchievements.CreatedAt >= "{datetime.date.today() - datetime.timedelta(days=7)}"
|
||||||
|
) +
|
||||||
|
(
|
||||||
|
SELECT SUM(
|
||||||
|
UserMessageCountPerHour.XPCount / (
|
||||||
|
SELECT XpPerMessage
|
||||||
|
FROM CFG_Server
|
||||||
|
WHERE ServerId = {user.server.id}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
FROM UserMessageCountPerHour
|
||||||
|
INNER JOIN Users ON UserMessageCountPerHour.UserId = Users.UserId
|
||||||
|
WHERE Users.ServerId = {user.server.id}
|
||||||
|
AND Users.UserId = {user.id}
|
||||||
|
AND UserMessageCountPerHour.CreatedAt >= "{datetime.date.today() - datetime.timedelta(days=7)}"
|
||||||
|
) +
|
||||||
|
(
|
||||||
|
SELECT Count(UserJoinedVoiceChannel.CreatedAt)
|
||||||
|
FROM UserJoinedVoiceChannel
|
||||||
|
INNER JOIN Users ON UserJoinedVoiceChannel.UserId = Users.UserId
|
||||||
|
WHERE Users.ServerId = {user.server.id}
|
||||||
|
AND Users.UserId = {user.id}
|
||||||
|
AND UserJoinedVoiceChannel.CreatedAt >= "{datetime.date.today() - datetime.timedelta(days=7)}"
|
||||||
|
) +
|
||||||
|
(
|
||||||
|
SELECT IFNULL(ROUND(SUM(TIME_TO_SEC(
|
||||||
|
TIMEDIFF(UserJoinedVoiceChannel.LeavedOn, UserJoinedVoiceChannel.JoinedOn)
|
||||||
|
) / 3600), 2), 0)
|
||||||
|
FROM UserJoinedVoiceChannel
|
||||||
|
INNER JOIN Users ON UserJoinedVoiceChannel.UserId = Users.UserId
|
||||||
|
WHERE Users.ServerId = {user.server.id}
|
||||||
|
AND Users.UserId = {user.id}
|
||||||
|
AND UserJoinedVoiceChannel.CreatedAt >= "{datetime.date.today() - datetime.timedelta(days=7)}"
|
||||||
|
) +
|
||||||
|
(
|
||||||
|
SELECT Count(UserJoinedGameServer.CreatedAt)
|
||||||
|
FROM UserJoinedGameServer
|
||||||
|
INNER JOIN Users ON UserJoinedGameServer.UserId = Users.UserId
|
||||||
|
WHERE Users.ServerId = {user.server.id}
|
||||||
|
AND Users.UserId = {user.id}
|
||||||
|
AND UserJoinedGameServer.CreatedAt >= "{datetime.date.today() - datetime.timedelta(days=7)}"
|
||||||
|
) +
|
||||||
|
(
|
||||||
|
SELECT IFNULL(ROUND(SUM(TIME_TO_SEC(
|
||||||
|
TIMEDIFF(UserJoinedGameServer.LeavedOn, UserJoinedGameServer.JoinedOn)
|
||||||
|
) / 3600), 2), 0)
|
||||||
|
FROM UserJoinedGameServer
|
||||||
|
INNER JOIN Users ON UserJoinedGameServer.UserId = Users.UserId
|
||||||
|
WHERE Users.ServerId = {user.server.id}
|
||||||
|
AND Users.UserId = {user.id}
|
||||||
|
AND UserJoinedGameServer.CreatedAt >= "{datetime.date.today() - datetime.timedelta(days=7)}"
|
||||||
|
) -
|
||||||
|
(
|
||||||
|
SELECT COUNT(UserWarnings.CreatedAt)
|
||||||
|
FROM UserWarnings
|
||||||
|
INNER JOIN Users ON UserWarnings.UserId = Users.UserId
|
||||||
|
WHERE Users.ServerId = {user.server.id}
|
||||||
|
AND Users.UserId = {user.id}
|
||||||
|
AND UserWarnings.CreatedAt >= "{datetime.date.today() - datetime.timedelta(days=7)}"
|
||||||
|
)
|
||||||
|
) / {days} * 1000 as count;
|
||||||
|
"""
|
||||||
|
user.activity = self._cast_query_result(query, int)
|
||||||
|
|
||||||
|
def _cast_query_result(self, query: str, r_type: T) -> Optional[R]:
|
||||||
|
results = self._context.select(query)
|
||||||
|
if len(results) == 0 or len(results[0]) == 0:
|
||||||
|
return None
|
||||||
|
result = results[0][0]
|
||||||
|
default = None
|
||||||
|
if r_type is int or r_type is float:
|
||||||
|
default = 0
|
||||||
|
elif r_type is str:
|
||||||
|
default = ""
|
||||||
|
|
||||||
|
return r_type(result) if result is not None else default
|
||||||
|
@ -46,30 +46,29 @@ class UserWarningsRepositoryService(UserWarningsRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_user_warnings(self) -> List[UserWarnings]:
|
def get_user_warnings(self) -> List[UserWarnings]:
|
||||||
warnings = List(UserWarnings)
|
|
||||||
self._logger.trace(__name__, f"Send SQL command: {UserWarnings.get_select_all_string()}")
|
self._logger.trace(__name__, f"Send SQL command: {UserWarnings.get_select_all_string()}")
|
||||||
results = self._context.select(UserWarnings.get_select_all_string())
|
return List(
|
||||||
for result in results:
|
UserWarnings,
|
||||||
warnings.append(self._from_result(result))
|
[self._from_result(warning) for warning in self._context.select(UserWarnings.get_select_all_string())],
|
||||||
|
)
|
||||||
return warnings
|
|
||||||
|
|
||||||
def get_user_warnings_by_id(self, id: int) -> UserWarnings:
|
def get_user_warnings_by_id(self, id: int) -> UserWarnings:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {UserWarnings.get_select_by_id_string(id)}")
|
self._logger.trace(__name__, f"Send SQL command: {UserWarnings.get_select_by_id_string(id)}")
|
||||||
result = self._context.select(UserWarnings.get_select_by_id_string(id))[0]
|
return self._from_result(self._context.select(UserWarnings.get_select_by_id_string(id))[0])
|
||||||
return self._from_result(result)
|
|
||||||
|
|
||||||
def get_user_warnings_by_user_id(self, user_id: int) -> List[UserWarnings]:
|
def get_user_warnings_by_user_id(self, user_id: int) -> List[UserWarnings]:
|
||||||
warnings = List(UserWarnings)
|
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
f"Send SQL command: {UserWarnings.get_select_by_user_id_string(user_id)}",
|
f"Send SQL command: {UserWarnings.get_select_by_user_id_string(user_id)}",
|
||||||
)
|
)
|
||||||
results = self._context.select(UserWarnings.get_select_by_user_id_string(user_id))
|
|
||||||
for result in results:
|
|
||||||
warnings.append(self._from_result(result))
|
|
||||||
|
|
||||||
return warnings
|
return List(
|
||||||
|
UserWarnings,
|
||||||
|
[
|
||||||
|
self._from_result(warning)
|
||||||
|
for warning in self._context.select(UserWarnings.get_select_by_user_id_string(user_id))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def add_user_warnings(self, user_warnings: UserWarnings):
|
def add_user_warnings(self, user_warnings: UserWarnings):
|
||||||
self._logger.trace(__name__, f"Send SQL command: {user_warnings.insert_string}")
|
self._logger.trace(__name__, f"Send SQL command: {user_warnings.insert_string}")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_graphql"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_graphql.abc"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -12,6 +12,7 @@ from bot_api.exception.service_exception import ServiceException
|
|||||||
from bot_api.route.route import Route
|
from bot_api.route.route import Route
|
||||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
from bot_core.environment_variables import MAINTENANCE
|
from bot_core.environment_variables import MAINTENANCE
|
||||||
|
from bot_core.service.permission_service import PermissionService
|
||||||
from bot_data.model.achievement import Achievement
|
from bot_data.model.achievement import Achievement
|
||||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||||
from bot_data.model.auth_user import AuthUser
|
from bot_data.model.auth_user import AuthUser
|
||||||
@ -32,7 +33,6 @@ from bot_data.model.user_role_enum import UserRoleEnum
|
|||||||
from bot_graphql.abc.filter_abc import FilterABC
|
from bot_graphql.abc.filter_abc import FilterABC
|
||||||
from bot_graphql.filter.page import Page
|
from bot_graphql.filter.page import Page
|
||||||
from bot_graphql.filter.sort import Sort
|
from bot_graphql.filter.sort import Sort
|
||||||
from modules.permission.service.permission_service import PermissionService
|
|
||||||
|
|
||||||
|
|
||||||
class QueryABC(ObjectType):
|
class QueryABC(ObjectType):
|
||||||
@ -64,11 +64,9 @@ class QueryABC(ObjectType):
|
|||||||
if user == "system" or user.auth_role == AuthRoleEnum.admin:
|
if user == "system" or user.auth_role == AuthRoleEnum.admin:
|
||||||
return self._resolve_collection(collection, *args, **kwargs)
|
return self._resolve_collection(collection, *args, **kwargs)
|
||||||
|
|
||||||
for x in collection.to_list():
|
return self._resolve_collection(
|
||||||
if not self._can_user_see_element(user, x):
|
collection.where(lambda x: self._can_user_see_element(user, x)), *args, **kwargs
|
||||||
collection.remove(x)
|
)
|
||||||
|
|
||||||
return self._resolve_collection(collection, *args, **kwargs)
|
|
||||||
|
|
||||||
self.set_field(f"{name}s", wrapper)
|
self.set_field(f"{name}s", wrapper)
|
||||||
self.set_field(f"{name}Count", lambda *args: wrapper(*args).count())
|
self.set_field(f"{name}Count", lambda *args: wrapper(*args).count())
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "1",
|
"Major": "1",
|
||||||
"Minor": "2",
|
"Minor": "2",
|
||||||
"Micro": "2"
|
"Micro": "3"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_graphql.filter"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -52,4 +52,5 @@ type Query {
|
|||||||
discord: Discord
|
discord: Discord
|
||||||
|
|
||||||
hasFeatureFlag(flag: String): FeatureFlag
|
hasFeatureFlag(flag: String): FeatureFlag
|
||||||
|
featureFlags: [FeatureFlag]
|
||||||
}
|
}
|
@ -40,6 +40,7 @@ type Server implements TableWithHistoryQuery {
|
|||||||
|
|
||||||
config: ServerConfig
|
config: ServerConfig
|
||||||
hasFeatureFlag(flag: String): FeatureFlag
|
hasFeatureFlag(flag: String): FeatureFlag
|
||||||
|
featureFlags: [FeatureFlag]
|
||||||
|
|
||||||
statistic(date: String): ServerStatistic
|
statistic(date: String): ServerStatistic
|
||||||
|
|
||||||
|
@ -7,7 +7,9 @@ type User implements TableWithHistoryQuery {
|
|||||||
reactionCount: Int
|
reactionCount: Int
|
||||||
birthday: String
|
birthday: String
|
||||||
ontime: Float
|
ontime: Float
|
||||||
|
gameOntime: Float
|
||||||
level: Level
|
level: Level
|
||||||
|
activityScore: Int
|
||||||
|
|
||||||
joinedServers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [UserJoinedServer]
|
joinedServers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [UserJoinedServer]
|
||||||
joinedServerCount: Int
|
joinedServerCount: Int
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_graphql.model"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_graphql.mutations"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -6,7 +6,7 @@ from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
|||||||
from bot_data.model.achievement import Achievement
|
from bot_data.model.achievement import Achievement
|
||||||
from bot_data.model.user_role_enum import UserRoleEnum
|
from bot_data.model.user_role_enum import UserRoleEnum
|
||||||
from bot_graphql.abc.query_abc import QueryABC
|
from bot_graphql.abc.query_abc import QueryABC
|
||||||
from modules.permission.service.permission_service import PermissionService
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class AchievementMutation(QueryABC):
|
class AchievementMutation(QueryABC):
|
||||||
|
@ -10,7 +10,7 @@ from bot_data.model.scheduled_event import ScheduledEvent
|
|||||||
from bot_data.model.scheduled_event_interval_enum import ScheduledEventIntervalEnum
|
from bot_data.model.scheduled_event_interval_enum import ScheduledEventIntervalEnum
|
||||||
from bot_data.model.user_role_enum import UserRoleEnum
|
from bot_data.model.user_role_enum import UserRoleEnum
|
||||||
from bot_graphql.abc.query_abc import QueryABC
|
from bot_graphql.abc.query_abc import QueryABC
|
||||||
from modules.permission.service.permission_service import PermissionService
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class ScheduledEventMutation(QueryABC):
|
class ScheduledEventMutation(QueryABC):
|
||||||
|
@ -13,6 +13,7 @@ from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
|||||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||||
from bot_data.model.user_role_enum import UserRoleEnum
|
from bot_data.model.user_role_enum import UserRoleEnum
|
||||||
from bot_graphql.abc.query_abc import QueryABC
|
from bot_graphql.abc.query_abc import QueryABC
|
||||||
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class ServerConfigMutation(QueryABC):
|
class ServerConfigMutation(QueryABC):
|
||||||
@ -24,6 +25,7 @@ class ServerConfigMutation(QueryABC):
|
|||||||
server_configs: ServerConfigRepositoryABC,
|
server_configs: ServerConfigRepositoryABC,
|
||||||
db: DatabaseContextABC,
|
db: DatabaseContextABC,
|
||||||
config_service: ConfigService,
|
config_service: ConfigService,
|
||||||
|
permissions: PermissionService,
|
||||||
):
|
):
|
||||||
QueryABC.__init__(self, "ServerConfigMutation")
|
QueryABC.__init__(self, "ServerConfigMutation")
|
||||||
|
|
||||||
@ -33,6 +35,7 @@ class ServerConfigMutation(QueryABC):
|
|||||||
self._server_configs = server_configs
|
self._server_configs = server_configs
|
||||||
self._db = db
|
self._db = db
|
||||||
self._config_service = config_service
|
self._config_service = config_service
|
||||||
|
self._permissions = permissions
|
||||||
|
|
||||||
self.set_field("updateServerConfig", self.resolve_update_server_config)
|
self.set_field("updateServerConfig", self.resolve_update_server_config)
|
||||||
|
|
||||||
@ -175,11 +178,13 @@ class ServerConfigMutation(QueryABC):
|
|||||||
|
|
||||||
def _update_team_role_ids(self, new_config: ServerConfig):
|
def _update_team_role_ids(self, new_config: ServerConfig):
|
||||||
old_config = self._server_configs.get_server_config_by_server(new_config.server.id)
|
old_config = self._server_configs.get_server_config_by_server(new_config.server.id)
|
||||||
|
has_update = False
|
||||||
for role_id in old_config.team_role_ids:
|
for role_id in old_config.team_role_ids:
|
||||||
if role_id.role_id in new_config.team_role_ids.select(lambda x: int(x.role_id)):
|
if role_id.role_id in new_config.team_role_ids.select(lambda x: int(x.role_id)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._server_configs.delete_server_team_role_id_config(role_id)
|
self._server_configs.delete_server_team_role_id_config(role_id)
|
||||||
|
has_update = True
|
||||||
|
|
||||||
for role_id in new_config.team_role_ids:
|
for role_id in new_config.team_role_ids:
|
||||||
guild = self._bot.get_guild(new_config.server.discord_id)
|
guild = self._bot.get_guild(new_config.server.discord_id)
|
||||||
@ -192,3 +197,7 @@ class ServerConfigMutation(QueryABC):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
self._server_configs.add_server_team_role_id_config(role_id)
|
self._server_configs.add_server_team_role_id_config(role_id)
|
||||||
|
has_update = True
|
||||||
|
|
||||||
|
if has_update:
|
||||||
|
self._permissions.reset_cache()
|
||||||
|
@ -6,7 +6,7 @@ from bot_data.abc.short_role_name_repository_abc import ShortRoleNameRepositoryA
|
|||||||
from bot_data.model.short_role_name import ShortRoleName
|
from bot_data.model.short_role_name import ShortRoleName
|
||||||
from bot_data.model.user_role_enum import UserRoleEnum
|
from bot_data.model.user_role_enum import UserRoleEnum
|
||||||
from bot_graphql.abc.query_abc import QueryABC
|
from bot_graphql.abc.query_abc import QueryABC
|
||||||
from modules.permission.service.permission_service import PermissionService
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class ShortRoleNameMutation(QueryABC):
|
class ShortRoleNameMutation(QueryABC):
|
||||||
|
@ -16,6 +16,7 @@ from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig
|
|||||||
from bot_data.model.user_role_enum import UserRoleEnum
|
from bot_data.model.user_role_enum import UserRoleEnum
|
||||||
from bot_data.service.technician_config_seeder import TechnicianConfigSeeder
|
from bot_data.service.technician_config_seeder import TechnicianConfigSeeder
|
||||||
from bot_graphql.abc.query_abc import QueryABC
|
from bot_graphql.abc.query_abc import QueryABC
|
||||||
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class TechnicianConfigMutation(QueryABC):
|
class TechnicianConfigMutation(QueryABC):
|
||||||
@ -30,6 +31,7 @@ class TechnicianConfigMutation(QueryABC):
|
|||||||
config_service: ConfigService,
|
config_service: ConfigService,
|
||||||
tech_seeder: TechnicianConfigSeeder,
|
tech_seeder: TechnicianConfigSeeder,
|
||||||
client_utils: ClientUtilsABC,
|
client_utils: ClientUtilsABC,
|
||||||
|
permissions: PermissionService,
|
||||||
):
|
):
|
||||||
QueryABC.__init__(self, "TechnicianConfigMutation")
|
QueryABC.__init__(self, "TechnicianConfigMutation")
|
||||||
|
|
||||||
@ -42,6 +44,7 @@ class TechnicianConfigMutation(QueryABC):
|
|||||||
self._config_service = config_service
|
self._config_service = config_service
|
||||||
self._tech_seeder = tech_seeder
|
self._tech_seeder = tech_seeder
|
||||||
self._client_utils = client_utils
|
self._client_utils = client_utils
|
||||||
|
self._permissions = permissions
|
||||||
|
|
||||||
self.set_field("updateTechnicianConfig", self.resolve_update_technician_config)
|
self.set_field("updateTechnicianConfig", self.resolve_update_technician_config)
|
||||||
|
|
||||||
@ -126,11 +129,13 @@ class TechnicianConfigMutation(QueryABC):
|
|||||||
|
|
||||||
def _update_technician_ids(self, new_config: TechnicianConfig):
|
def _update_technician_ids(self, new_config: TechnicianConfig):
|
||||||
old_config = self._technician_configs.get_technician_config()
|
old_config = self._technician_configs.get_technician_config()
|
||||||
|
has_update = False
|
||||||
for technician_id in old_config.technician_ids:
|
for technician_id in old_config.technician_ids:
|
||||||
if technician_id in new_config.technician_ids:
|
if technician_id in new_config.technician_ids:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._technician_configs.delete_technician_id_config(TechnicianIdConfig(technician_id))
|
self._technician_configs.delete_technician_id_config(TechnicianIdConfig(technician_id))
|
||||||
|
has_update = True
|
||||||
|
|
||||||
for technician_id in new_config.technician_ids:
|
for technician_id in new_config.technician_ids:
|
||||||
user = self._bot.get_user(technician_id)
|
user = self._bot.get_user(technician_id)
|
||||||
@ -142,3 +147,7 @@ class TechnicianConfigMutation(QueryABC):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
self._technician_configs.add_technician_id_config(TechnicianIdConfig(technician_id))
|
self._technician_configs.add_technician_id_config(TechnicianIdConfig(technician_id))
|
||||||
|
has_update = True
|
||||||
|
|
||||||
|
if has_update:
|
||||||
|
self._permissions.reset_cache()
|
||||||
|
@ -24,7 +24,7 @@ from bot_data.model.server_config import ServerConfig
|
|||||||
from bot_data.model.user_joined_game_server import UserJoinedGameServer
|
from bot_data.model.user_joined_game_server import UserJoinedGameServer
|
||||||
from bot_data.model.user_role_enum import UserRoleEnum
|
from bot_data.model.user_role_enum import UserRoleEnum
|
||||||
from bot_graphql.abc.query_abc import QueryABC
|
from bot_graphql.abc.query_abc import QueryABC
|
||||||
from modules.permission.service.permission_service import PermissionService
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class UserJoinedGameServerMutation(QueryABC):
|
class UserJoinedGameServerMutation(QueryABC):
|
||||||
|
@ -13,7 +13,7 @@ from bot_data.model.user_role_enum import UserRoleEnum
|
|||||||
from bot_graphql.abc.query_abc import QueryABC
|
from bot_graphql.abc.query_abc import QueryABC
|
||||||
from modules.base.service.user_warnings_service import UserWarningsService
|
from modules.base.service.user_warnings_service import UserWarningsService
|
||||||
from modules.level.service.level_service import LevelService
|
from modules.level.service.level_service import LevelService
|
||||||
from modules.permission.service.permission_service import PermissionService
|
from bot_core.service.permission_service import PermissionService
|
||||||
|
|
||||||
|
|
||||||
class UserMutation(QueryABC):
|
class UserMutation(QueryABC):
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_graphql.queries"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "bot_graphql.queries.discord"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -86,7 +86,7 @@ class ServerQuery(DataQueryWithHistoryABC):
|
|||||||
)
|
)
|
||||||
self.add_collection(
|
self.add_collection(
|
||||||
"user",
|
"user",
|
||||||
lambda server, *_: self._users.get_users_by_server_id(server.id),
|
lambda server, *_: self._users.get_users_with_activity_by_server_id(server.id),
|
||||||
UserFilter,
|
UserFilter,
|
||||||
)
|
)
|
||||||
self.add_collection(
|
self.add_collection(
|
||||||
@ -116,6 +116,10 @@ class ServerQuery(DataQueryWithHistoryABC):
|
|||||||
"hasFeatureFlag",
|
"hasFeatureFlag",
|
||||||
lambda server, *_, **kwargs: self._resolve_has_feature_flag(server, *_, **kwargs),
|
lambda server, *_, **kwargs: self._resolve_has_feature_flag(server, *_, **kwargs),
|
||||||
)
|
)
|
||||||
|
self.set_field(
|
||||||
|
"featureFlags",
|
||||||
|
lambda server, *_, **kwargs: self._resolve_feature_flags(server, *_),
|
||||||
|
)
|
||||||
self.set_field("statistic", lambda server, *_, **kwargs: ServerStatistics(server, kwargs))
|
self.set_field("statistic", lambda server, *_, **kwargs: ServerStatistics(server, kwargs))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -142,3 +146,13 @@ class ServerQuery(DataQueryWithHistoryABC):
|
|||||||
"key": kwargs["flag"],
|
"key": kwargs["flag"],
|
||||||
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _resolve_feature_flags(self, server: Server, *_) -> list[dict]:
|
||||||
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}")
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"key": flag,
|
||||||
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(flag)),
|
||||||
|
}
|
||||||
|
for flag in [e.value for e in FeatureFlagsEnum]
|
||||||
|
]
|
||||||
|
@ -114,7 +114,9 @@ class ServerStatisticQuery(QueryABC):
|
|||||||
|
|
||||||
def _resolve_voice_channel_ontime(self, server, *_):
|
def _resolve_voice_channel_ontime(self, server, *_):
|
||||||
query = f"""
|
query = f"""
|
||||||
SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedVoiceChannel.LeavedOn, UserJoinedVoiceChannel.JoinedOn)) / 3600),{server.server.id}) FROM UserJoinedVoiceChannel
|
SELECT IFNULL(ROUND(SUM(
|
||||||
|
TIME_TO_SEC(TIMEDIFF(UserJoinedVoiceChannel.LeavedOn, UserJoinedVoiceChannel.JoinedOn)) / 3600
|
||||||
|
), 2), 0) FROM UserJoinedVoiceChannel
|
||||||
INNER JOIN Users ON UserJoinedVoiceChannel.UserId = Users.UserId
|
INNER JOIN Users ON UserJoinedVoiceChannel.UserId = Users.UserId
|
||||||
WHERE Users.ServerId = {server.server.id}
|
WHERE Users.ServerId = {server.server.id}
|
||||||
AND UserJoinedVoiceChannel.CreatedAt >= "{self._get_date(**server.kwargs)}";
|
AND UserJoinedVoiceChannel.CreatedAt >= "{self._get_date(**server.kwargs)}";
|
||||||
@ -132,7 +134,10 @@ class ServerStatisticQuery(QueryABC):
|
|||||||
|
|
||||||
def _resolve_game_server_ontime(self, server, *_):
|
def _resolve_game_server_ontime(self, server, *_):
|
||||||
query = f"""
|
query = f"""
|
||||||
SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedGameServer.LeavedOn, UserJoinedGameServer.JoinedOn)) / 3600),{server.server.id}) FROM UserJoinedGameServer
|
SELECT IFNULL(ROUND(SUM(
|
||||||
|
TIME_TO_SEC(TIMEDIFF(UserJoinedGameServer.LeavedOn, UserJoinedGameServer.JoinedOn)) / 3600
|
||||||
|
), 2), 0)
|
||||||
|
FROM UserJoinedGameServer
|
||||||
INNER JOIN Users ON UserJoinedGameServer.UserId = Users.UserId
|
INNER JOIN Users ON UserJoinedGameServer.UserId = Users.UserId
|
||||||
WHERE Users.ServerId = {server.server.id}
|
WHERE Users.ServerId = {server.server.id}
|
||||||
AND UserJoinedGameServer.CreatedAt >= "{self._get_date(**server.kwargs)}";
|
AND UserJoinedGameServer.CreatedAt >= "{self._get_date(**server.kwargs)}";
|
||||||
|
@ -2,6 +2,7 @@ from cpl_core.database.context import DatabaseContextABC
|
|||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||||
|
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||||
from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC
|
from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC
|
||||||
from bot_data.abc.user_joined_game_server_repository_abc import (
|
from bot_data.abc.user_joined_game_server_repository_abc import (
|
||||||
UserJoinedGameServerRepositoryABC,
|
UserJoinedGameServerRepositoryABC,
|
||||||
@ -11,7 +12,6 @@ from bot_data.abc.user_joined_voice_channel_repository_abc import (
|
|||||||
UserJoinedVoiceChannelRepositoryABC,
|
UserJoinedVoiceChannelRepositoryABC,
|
||||||
)
|
)
|
||||||
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
||||||
from bot_data.model.user import User
|
|
||||||
from bot_data.model.user_history import UserHistory
|
from bot_data.model.user_history import UserHistory
|
||||||
from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC
|
from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC
|
||||||
from bot_graphql.filter.achievement_filter import AchievementFilter
|
from bot_graphql.filter.achievement_filter import AchievementFilter
|
||||||
@ -22,7 +22,6 @@ from bot_graphql.filter.user_joined_voice_channel_filter import (
|
|||||||
)
|
)
|
||||||
from bot_graphql.filter.user_warning_filter import UserWarningFilter
|
from bot_graphql.filter.user_warning_filter import UserWarningFilter
|
||||||
from modules.level.service.level_service import LevelService
|
from modules.level.service.level_service import LevelService
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
|
||||||
|
|
||||||
|
|
||||||
class UserQuery(DataQueryWithHistoryABC):
|
class UserQuery(DataQueryWithHistoryABC):
|
||||||
@ -50,15 +49,17 @@ class UserQuery(DataQueryWithHistoryABC):
|
|||||||
self._permissions = permissions
|
self._permissions = permissions
|
||||||
self._achievements = achievements
|
self._achievements = achievements
|
||||||
|
|
||||||
self.set_field("id", self.resolve_id)
|
self.set_field("id", lambda user, *_: user.id)
|
||||||
self.set_field("discordId", self.resolve_discord_id)
|
self.set_field("discordId", lambda user, *_: user.discord_id)
|
||||||
self.set_field("name", self.resolve_name)
|
self.set_field("name", lambda user, *_: user.name)
|
||||||
self.set_field("xp", self.resolve_xp)
|
self.set_field("xp", lambda user, *_: user.xp)
|
||||||
self.set_field("messageCount", lambda x, *_: x.message_count)
|
self.set_field("messageCount", lambda x, *_: x.message_count)
|
||||||
self.set_field("reactionCount", lambda x, *_: x.reaction_count)
|
self.set_field("reactionCount", lambda x, *_: x.reaction_count)
|
||||||
self.set_field("birthday", lambda x, *_: None if x.birthday is None else x.birthday.strftime("%d.%m.%Y"))
|
self.set_field("birthday", lambda x, *_: None if x.birthday is None else x.birthday.strftime("%d.%m.%Y"))
|
||||||
self.set_field("ontime", self.resolve_ontime)
|
self.set_field("ontime", lambda user, *_: user.ontime)
|
||||||
self.set_field("level", self.resolve_level)
|
self.set_field("gameOntime", lambda user, *_: user.game_ontime)
|
||||||
|
self.set_field("level", lambda user, *_: user.level)
|
||||||
|
self.set_field("activityScore", lambda user, *_: user.activity)
|
||||||
self.add_collection(
|
self.add_collection(
|
||||||
"joinedServer",
|
"joinedServer",
|
||||||
lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.id),
|
lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.id),
|
||||||
@ -85,37 +86,5 @@ class UserQuery(DataQueryWithHistoryABC):
|
|||||||
UserWarningFilter,
|
UserWarningFilter,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.set_field("server", self.resolve_server)
|
self.set_field("server", lambda user, *_: user.server)
|
||||||
self.set_field("leftServer", self.resolve_left_server)
|
self.set_field("leftServer", lambda user, *_: user.left_server)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_id(user: User, *_):
|
|
||||||
return user.id
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_discord_id(user: User, *_):
|
|
||||||
return user.discord_id
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_name(user: User, *_):
|
|
||||||
return user.name
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_xp(user: User, *_):
|
|
||||||
return user.xp
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_ontime(user: User, *_):
|
|
||||||
return user.ontime
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_level(user: User, *_):
|
|
||||||
return user.level
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_server(user: User, *_):
|
|
||||||
return user.server
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_left_server(user: User, *_):
|
|
||||||
return user.left_server
|
|
||||||
|
@ -131,6 +131,10 @@ class Query(QueryABC):
|
|||||||
"hasFeatureFlag",
|
"hasFeatureFlag",
|
||||||
lambda *_, **kwargs: self._resolve_has_feature_flag(*_, **kwargs),
|
lambda *_, **kwargs: self._resolve_has_feature_flag(*_, **kwargs),
|
||||||
)
|
)
|
||||||
|
self.set_field(
|
||||||
|
"featureFlags",
|
||||||
|
lambda *_, **kwargs: self._resolve_feature_flags(*_),
|
||||||
|
)
|
||||||
|
|
||||||
def _resolve_has_feature_flag(self, *_, **kwargs):
|
def _resolve_has_feature_flag(self, *_, **kwargs):
|
||||||
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
|
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
|
||||||
@ -140,3 +144,13 @@ class Query(QueryABC):
|
|||||||
"key": kwargs["flag"],
|
"key": kwargs["flag"],
|
||||||
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _resolve_feature_flags(self, *_) -> list[dict]:
|
||||||
|
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"key": flag,
|
||||||
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(flag)),
|
||||||
|
}
|
||||||
|
for flag in [e.value for e in FeatureFlagsEnum]
|
||||||
|
]
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "modules.achievements"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "1",
|
"Major": "1",
|
||||||
"Minor": "2",
|
"Minor": "2",
|
||||||
"Micro": "2"
|
"Micro": "3"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "modules.achievements.commands"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "modules.achievements.events"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
@ -15,7 +15,7 @@ __title__ = "modules.achievements.model"
|
|||||||
__author__ = "Sven Heidemann"
|
__author__ = "Sven Heidemann"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||||
__version__ = "1.2.2"
|
__version__ = "1.2.3"
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
|||||||
# imports
|
# imports
|
||||||
|
|
||||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||||
version_info = VersionInfo(major="1", minor="2", micro="2")
|
version_info = VersionInfo(major="1", minor="2", micro="3")
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user