diff --git a/.gitea/workflows/deploy_dev.yaml b/.gitea/workflows/deploy_dev.yaml index 7d1db445..9e7850ab 100644 --- a/.gitea/workflows/deploy_dev.yaml +++ b/.gitea/workflows/deploy_dev.yaml @@ -14,6 +14,7 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.10.12" + token: ${{ secrets.CI_GITHUB_ACCESS_TOKEN }} - run: python -v - name: Setup docker @@ -22,36 +23,48 @@ jobs: - name: Clone Repository uses: https://github.com/actions/checkout@v3 - - - name: Shutdown stack - run: docker stack rm kdb_staging + with: + token: ${{ secrets.CI_ACCESS_TOKEN }} + submodules: true - name: Prepare bot build run: | - cd kdb-bot + cd bot pip install --extra-index-url https://pip.sh-edraft.de cpl-cli cpl i - - name: Build docker bot - run: | - cd kdb-bot - docker image prune -f - cpl docker-build - - name: Setup node uses: https://github.com/actions/setup-node@v3 - name: Prepare web build run: | - cd kdb-web + cd web npm install -g ts-node - npm i + npm ci + + - name: Shutdown stack + run: docker stack rm sdb_dev + + - name: Build docker bot + run: | + cd bot + docker image prune -f + cpl build + docker build -t sh-edraft.de/sdb-bot:$(cpl gv)-dev . - name: Build docker web run: | - cd kdb-web + cd web docker image prune -f - npm run docker-build + cp src/favicon.dev.ico src/favicon.ico + npm run build + docker build -t sh-edraft.de/sdb-web:$(npm run -s gv)-dev . + + - name: Set version + run: | + cd bot/docker + chmod +x ./set-docker-compose-image-version.sh + ./set-docker-compose-image-version.sh sh-edraft.de/sdb-bot:$(cd ../; cpl gv)-dev sh-edraft.de/sdb-web:$(cd ../../web; npm run -s gv;)-dev - name: Deploy Stack to sh-edraft.de uses: https://github.com/kgierke/portainer-stack-deployment@v1 @@ -60,6 +73,6 @@ jobs: portainer-username: "gitea_job" portainer-password: "${{ secrets.docker_job }}" portainer-endpoint: 2 - name: kdb_staging - file: ./docker-compose.staging.yml + name: sdb_dev + file: bot/docker/docker-compose.dev.yml variables: '{}' diff --git a/.gitea/workflows/deploy_prod.yaml b/.gitea/workflows/deploy_prod.yaml index 08273018..d205e167 100644 --- a/.gitea/workflows/deploy_prod.yaml +++ b/.gitea/workflows/deploy_prod.yaml @@ -1,5 +1,5 @@ -name: Deploy dev on push -run-name: Deploy dev on push +name: Deploy prod on push +run-name: Deploy prod on push on: push: branches: @@ -14,6 +14,7 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.10.12" + token: ${{ secrets.CI_GITHUB_ACCESS_TOKEN }} - run: python -v - name: Setup docker @@ -22,36 +23,47 @@ jobs: - name: Clone Repository uses: https://github.com/actions/checkout@v3 - - - name: Shutdown stack - run: docker stack rm kdb_prod + with: + token: ${{ secrets.CI_ACCESS_TOKEN }} + submodules: true - name: Prepare bot build run: | - cd kdb-bot + cd bot pip install --extra-index-url https://pip.sh-edraft.de cpl-cli cpl i - - name: Build docker bot - run: | - cd kdb-bot - docker image prune -f - cpl docker-build - - name: Setup node uses: https://github.com/actions/setup-node@v3 - name: Prepare web build run: | - cd kdb-web + cd web npm install -g ts-node - npm i + npm ci + + - name: Shutdown stack + run: docker stack rm sdb_prod + + - name: Build docker bot + run: | + cd bot + docker image prune -f + cpl build + docker build -t sh-edraft.de/sdb-bot:$(cpl gv) . - name: Build docker web run: | - cd kdb-web + cd web docker image prune -f - npm run docker-build + npm run build + docker build -t sh-edraft.de/sdb-web:$(npm run -s gv) . + + - name: Set version + run: | + cd bot/docker + chmod +x ./set-docker-compose-image-version.sh + ./set-docker-compose-image-version.sh sh-edraft.de/sdb-bot:$(cd ../; cpl gv) sh-edraft.de/sdb-web:$(cd ../../web; npm run -s gv;) - name: Deploy Stack to sh-edraft.de uses: https://github.com/kgierke/portainer-stack-deployment@v1 @@ -60,6 +72,6 @@ jobs: portainer-username: "gitea_job" portainer-password: "${{ secrets.docker_job }}" portainer-endpoint: 2 - name: kdb_prod - file: ./docker-compose.yml + name: sdb_prod + file: bot/docker/docker-compose.yml variables: '{}' diff --git a/.gitea/workflows/deploy_staging.yaml b/.gitea/workflows/deploy_staging.yaml new file mode 100644 index 00000000..7eabe8cd --- /dev/null +++ b/.gitea/workflows/deploy_staging.yaml @@ -0,0 +1,78 @@ +name: Deploy staging on push +run-name: Deploy staging on push +on: + push: + branches: + - staging + +jobs: + on-push-deploy_sh-edraft: + runs-on: [ dobby.sh-edraft.de, ubuntu-latest ] + container: catthehacker/ubuntu:act-latest + steps: + - name: Setup Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10.12" + token: ${{ secrets.CI_GITHUB_ACCESS_TOKEN }} + - run: python -v + + - name: Setup docker + uses: https://github.com/papodaca/install-docker-action@main + - run: docker -v + + - name: Clone Repository + uses: https://github.com/actions/checkout@v3 + with: + token: ${{ secrets.CI_ACCESS_TOKEN }} + submodules: true + + - name: Prepare bot build + run: | + cd bot + pip install --extra-index-url https://pip.sh-edraft.de cpl-cli + cpl i + + - name: Setup node + uses: https://github.com/actions/setup-node@v3 + + - name: Prepare web build + run: | + cd web + npm install -g ts-node + npm ci + + - name: Shutdown stack + run: docker stack rm sdb_staging + + - name: Build docker bot + run: | + cd bot + docker image prune -f + cpl build + docker build -t sh-edraft.de/sdb-bot:$(cpl gv)-staging . + + - name: Build docker web + run: | + cd web + docker image prune -f + cp src/favicon.staging.ico src/favicon.ico + npm run build + docker build -t sh-edraft.de/sdb-web:$(npm run -s gv)-staging . + + - name: Set version + run: | + cd bot/docker + chmod +x ./set-docker-compose-image-version.sh + ./set-docker-compose-image-version.sh sh-edraft.de/sdb-bot:$(cd ../; cpl gv)-staging sh-edraft.de/sdb-web:$(cd ../../web; npm run -s gv;)-staging + + - name: Deploy Stack to sh-edraft.de + uses: https://github.com/kgierke/portainer-stack-deployment@v1 + with: + portainer-url: "https://docker.sh-edraft.de" + portainer-username: "gitea_job" + portainer-password: "${{ secrets.docker_job }}" + portainer-endpoint: 2 + name: sdb_staging + file: bot/docker/docker-compose.staging.yml + variables: '{}' diff --git a/.gitmodules b/.gitmodules index ca793c6c..f72ea2ba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ -[submodule "kdb-bot/src/bot/config"] - path = kdb-bot/src/bot/config - url = https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot.config.git -[submodule "kdb-bot/src/bot_api/config"] - path = kdb-bot/src/bot_api/config - url = https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot.api.config.git -[submodule "kdb-bot/docker"] - path = kdb-bot/docker - url = https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot.docker.git +[submodule "bot/src/bot/config"] + path = bot/src/bot/config + url = https://git.sh-edraft.de/sh-edraft.de/sh_discord_bot.config.git +[submodule "bot/src/bot_api/config"] + path = bot/src/bot_api/config + url = https://git.sh-edraft.de/sh-edraft.de/sh_discord_bot.api.config.git +[submodule "bot/docker"] + path = bot/docker + url = https://git.sh-edraft.de/sh-edraft.de/sh_discord_bot.docker.git diff --git a/kdb-bot/.cpl/schematic_db_table.py b/bot/.cpl/schematic_db_table.py similarity index 100% rename from kdb-bot/.cpl/schematic_db_table.py rename to bot/.cpl/schematic_db_table.py diff --git a/kdb-bot/.cpl/schematic_migration.py b/bot/.cpl/schematic_migration.py similarity index 100% rename from kdb-bot/.cpl/schematic_migration.py rename to bot/.cpl/schematic_migration.py diff --git a/kdb-bot/.cpl/schematic_query.py b/bot/.cpl/schematic_query.py similarity index 100% rename from kdb-bot/.cpl/schematic_query.py rename to bot/.cpl/schematic_query.py diff --git a/kdb-bot/LICENSE b/bot/LICENSE similarity index 100% rename from kdb-bot/LICENSE rename to bot/LICENSE diff --git a/kdb-bot/README.md b/bot/README.md similarity index 100% rename from kdb-bot/README.md rename to bot/README.md diff --git a/kdb-bot/cpl-workspace.json b/bot/cpl-workspace.json similarity index 83% rename from kdb-bot/cpl-workspace.json rename to bot/cpl-workspace.json index 8e010570..d08ceb87 100644 --- a/kdb-bot/cpl-workspace.json +++ b/bot/cpl-workspace.json @@ -17,6 +17,7 @@ "permission": "src/modules/permission/permission.json", "technician": "src/modules/technician/technician.json", "short-role-name": "src/modules/short_role_name/short-role-name.json", + "special-offers": "src/modules/special_offers/special-offers.json", "checks": "tools/checks/checks.json", "get-version": "tools/get_version/get-version.json", "post-build": "tools/post_build/post-build.json", @@ -31,12 +32,12 @@ "pre-build": "cpl set-version $ARGS; black ./;", "post-build": "cpl run post-build --dev; black ./;", "pre-prod": "cpl build", - "prod": "export KDB_ENVIRONMENT=production; export KDB_NAME=KDB-Prod; cpl start;", + "prod": "export SDB_ENVIRONMENT=production; export SDB_NAME=SDB-Prod; cpl start;", "pre-stage": "cpl build", - "stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;", + "stage": "export SDB_ENVIRONMENT=staging; export SDB_NAME=SDB-Stage; cpl start;", "pre-dev": "cpl build", - "dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;", - "docker-build": "cpl build $ARGS; docker build -t sh-edraft.de/kdb-bot:$(cpl gv) .;", + "dev": "export SDB_ENVIRONMENT=development; export SDB_NAME=SDB-Dev; cpl start;", + "docker-build": "cpl build $ARGS; docker build -t sh-edraft.de/sdb-bot:$(cpl gv) .;", "dc-up": "docker-compose up -d", "dc-down": "docker-compose down", "docker": "cpl dc-down; cpl docker-build; cpl dc-up;" diff --git a/bot/docker b/bot/docker new file mode 160000 index 00000000..8063944d --- /dev/null +++ b/bot/docker @@ -0,0 +1 @@ +Subproject commit 8063944d871d88a1400e45d3fdac29ee69485eb5 diff --git a/kdb-bot/dockerfile b/bot/dockerfile similarity index 94% rename from kdb-bot/dockerfile rename to bot/dockerfile index 478bf7e7..ad507c89 100644 --- a/kdb-bot/dockerfile +++ b/bot/dockerfile @@ -2,7 +2,7 @@ FROM python:3.10.4-alpine WORKDIR /app -COPY ./dist/bot/build/kdb-bot/ . +COPY ./dist/bot/build/bot/ . COPY ./dist/bot/build/requirements.txt . RUN python -m pip install --upgrade pip diff --git a/kdb-bot/pyproject.toml b/bot/pyproject.toml similarity index 100% rename from kdb-bot/pyproject.toml rename to bot/pyproject.toml diff --git a/kdb-bot/src/bot/__init__.py b/bot/src/bot/__init__.py similarity index 84% rename from kdb-bot/src/bot/__init__.py rename to bot/src/bot/__init__.py index 19b2ab5c..17f979c1 100644 --- a/kdb-bot/src/bot/__init__.py +++ b/bot/src/bot/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot/application.py b/bot/src/bot/application.py similarity index 91% rename from kdb-bot/src/bot/application.py rename to bot/src/bot/application.py index 13d46815..aff7b618 100644 --- a/kdb-bot/src/bot/application.py +++ b/bot/src/bot/application.py @@ -8,8 +8,10 @@ from cpl_discord.service import DiscordBotServiceABC, DiscordBotService from cpl_translation import TranslatePipe, TranslationServiceABC, TranslationSettings from bot_api.api_thread import ApiThread +from bot_core.abc.task_abc import TaskABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.environment_variables import MAINTENANCE from bot_core.service.data_integrity_service import DataIntegrityService @@ -29,6 +31,8 @@ class Application(DiscordBotApplicationABC): # cpl-translation self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC) self._t: TranslatePipe = services.get_service(TranslatePipe) + # internal stuff + self._tasks = services.get_services(TaskABC) self._feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings) @@ -55,6 +59,10 @@ class Application(DiscordBotApplicationABC): return self._logger.info(__name__, f"Try to start {DiscordBotService.__name__}") + if not self._config.get_configuration(MAINTENANCE): + for task in self._tasks: + await self._bot.add_cog(task) + await self._bot.start_async() await self._bot.stop_async() except Exception as e: diff --git a/kdb-bot/src/bot/bot b/bot/src/bot/bot similarity index 100% rename from kdb-bot/src/bot/bot rename to bot/src/bot/bot diff --git a/kdb-bot/src/bot/bot.json b/bot/src/bot/bot.json similarity index 82% rename from kdb-bot/src/bot/bot.json rename to bot/src/bot/bot.json index 6cfefe9a..2db04199 100644 --- a/kdb-bot/src/bot/bot.json +++ b/bot/src/bot/bot.json @@ -3,8 +3,8 @@ "Name": "bot", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,22 +16,24 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core==2023.4.0.post5", + "cpl-core==2023.10.0", "cpl-translation==2023.4.0.post1", - "cpl-query==2023.4.0.post1", - "cpl-discord==2023.4.0.post3", - "Flask==2.3.2", - "Flask-Classful==0.14.2", + "cpl-query==2023.10.0", + "cpl-discord==2023.10.0.post1", + "Flask==3.0.0", + "Flask-Classful==0.16.0", "Flask-Cors==4.0.0", "PyJWT==2.8.0", "waitress==2.1.2", - "Flask-SocketIO==5.3.4", + "Flask-SocketIO==5.3.6", "eventlet==0.33.3", "requests-oauthlib==1.3.1", - "icmplib==3.0.3", + "icmplib==3.0.4", "ariadne==0.20.1", - "cryptography==41.0.2", - "discord>=2.3.2" + "cryptography==41.0.4", + "discord==2.3.2", + "bs4==0.0.1", + "lxml==4.9.3" ], "DevDependencies": [ "cpl-cli==2023.4.0.post3", @@ -69,6 +71,7 @@ "../modules/level/level.json", "../modules/permission/permission.json", "../modules/short_role_name/short-role-name.json", + "../modules/special_offers/special-offers.json", "../modules/technician/technician.json" ] } diff --git a/bot/src/bot/config b/bot/src/bot/config new file mode 160000 index 00000000..c11ca6f2 --- /dev/null +++ b/bot/src/bot/config @@ -0,0 +1 @@ +Subproject commit c11ca6f2e8e54bacdf16da677fbcf03705ff9780 diff --git a/kdb-bot/src/bot/extension/__init__.py b/bot/src/bot/extension/__init__.py similarity index 84% rename from kdb-bot/src/bot/extension/__init__.py rename to bot/src/bot/extension/__init__.py index 613907d1..56d79a66 100644 --- a/kdb-bot/src/bot/extension/__init__.py +++ b/bot/src/bot/extension/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot.extension" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot/extension/init_bot_extension.py b/bot/src/bot/extension/init_bot_extension.py similarity index 100% rename from kdb-bot/src/bot/extension/init_bot_extension.py rename to bot/src/bot/extension/init_bot_extension.py diff --git a/kdb-bot/src/bot/main.py b/bot/src/bot/main.py similarity index 97% rename from kdb-bot/src/bot/main.py rename to bot/src/bot/main.py index c004dd7d..1efe7d63 100644 --- a/kdb-bot/src/bot/main.py +++ b/bot/src/bot/main.py @@ -9,7 +9,7 @@ from bot.application import Application from bot.extension.init_bot_extension import InitBotExtension from bot.startup import Startup from bot.startup_discord_extension import StartupDiscordExtension -from bot.startup_migration_extension import StartupMigrationExtension +from bot_data.startup_migration_extension import StartupMigrationExtension from bot.startup_module_extension import StartupModuleExtension from bot.startup_settings_extension import StartupSettingsExtension from bot_api.app_api_extension import AppApiExtension diff --git a/kdb-bot/src/bot/module_list.py b/bot/src/bot/module_list.py similarity index 93% rename from kdb-bot/src/bot/module_list.py rename to bot/src/bot/module_list.py index 810a0851..88e99721 100644 --- a/kdb-bot/src/bot/module_list.py +++ b/bot/src/bot/module_list.py @@ -14,6 +14,7 @@ from modules.database.database_module import DatabaseModule 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.special_offers.special_offers_module import SteamSpecialOffersModule from modules.technician.technician_module import TechnicianModule @@ -37,6 +38,7 @@ class ModuleList: TechnicianModule, AchievementsModule, ShortRoleNameModule, + SteamSpecialOffersModule, # has to be last! BootLogModule, CoreExtensionModule, diff --git a/kdb-bot/src/bot/startup.py b/bot/src/bot/startup.py similarity index 95% rename from kdb-bot/src/bot/startup.py rename to bot/src/bot/startup.py index 6895ddc8..0a5422d2 100644 --- a/kdb-bot/src/bot/startup.py +++ b/bot/src/bot/startup.py @@ -16,6 +16,7 @@ from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.logging.command_logger import CommandLogger from bot_core.logging.database_logger import DatabaseLogger from bot_core.logging.message_logger import MessageLogger +from bot_core.logging.task_logger import TaskLogger from bot_data.db_context import DBContext @@ -43,6 +44,7 @@ class Startup(StartupABC): services.add_singleton(CustomFileLoggerABC, CommandLogger) services.add_singleton(CustomFileLoggerABC, DatabaseLogger) services.add_singleton(CustomFileLoggerABC, MessageLogger) + services.add_singleton(CustomFileLoggerABC, TaskLogger) if self._feature_flags.get_flag(FeatureFlagsEnum.api_module): services.add_singleton(CustomFileLoggerABC, ApiLogger) diff --git a/kdb-bot/src/bot/startup_discord_extension.py b/bot/src/bot/startup_discord_extension.py similarity index 100% rename from kdb-bot/src/bot/startup_discord_extension.py rename to bot/src/bot/startup_discord_extension.py diff --git a/kdb-bot/src/bot/startup_module_extension.py b/bot/src/bot/startup_module_extension.py similarity index 100% rename from kdb-bot/src/bot/startup_module_extension.py rename to bot/src/bot/startup_module_extension.py diff --git a/kdb-bot/src/bot/startup_settings_extension.py b/bot/src/bot/startup_settings_extension.py similarity index 84% rename from kdb-bot/src/bot/startup_settings_extension.py rename to bot/src/bot/startup_settings_extension.py index caf34f19..c3db171a 100644 --- a/kdb-bot/src/bot/startup_settings_extension.py +++ b/bot/src/bot/startup_settings_extension.py @@ -8,6 +8,7 @@ from cpl_core.dependency_injection import ServiceCollectionABC from cpl_core.environment import ApplicationEnvironmentABC from bot_core.configuration.bot_logging_settings import BotLoggingSettings +from bot_core.environment_variables import MAINTENANCE, MIGRATION_ONLY class StartupSettingsExtension(StartupExtensionABC): @@ -17,8 +18,14 @@ class StartupSettingsExtension(StartupExtensionABC): def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironmentABC): # this shit has to be done here because we need settings in subsequent startup extensions environment.set_working_directory(os.path.dirname(os.path.realpath(__file__))) - configuration.add_environment_variables("KDB_") + configuration.add_environment_variables("SDB_") configuration.add_environment_variables("DISCORD_") + configuration.add_configuration( + MAINTENANCE, configuration.get_configuration(MAINTENANCE) in [True, "true", "True"] + ) + configuration.add_configuration( + MIGRATION_ONLY, configuration.get_configuration(MIGRATION_ONLY) in [True, "true", "True"] + ) configuration.add_json_file(f"config/appsettings.json", optional=False) configuration.add_json_file(f"config/appsettings.{environment.environment_name}.json", optional=True) diff --git a/kdb-bot/src/bot/translation/de.json b/bot/src/bot/translation/de.json similarity index 97% rename from kdb-bot/src/bot/translation/de.json rename to bot/src/bot/translation/de.json index c1390bdf..45f64e14 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/bot/src/bot/translation/de.json @@ -90,10 +90,16 @@ "booting": "Ich fahre gerade hoch...", "restart": "Muss neue Kekse holen...", "running": "Ich esse Kekse :D", - "shutdown": "Ich werde bestimmt wieder kommen..." + "shutdown": "Ich werde bestimmt wieder kommen...", + "maintenance": "In Wartung!" } }, "modules": { + "special_offers": { + "price": "Preis", + "discount": "Rabatt", + "discount_price": "Neuer Preis" + }, "achievements": { "commands": { "check": "Alles klar, ich schaue eben nach... nom nom" @@ -229,6 +235,11 @@ "success": "Verlinkung wurde entfernt :D" }, "user": { + "birthday": { + "has_birthday": "Alles Gute zum Geburtag {} :D", + "success": "Dein Geburtstag wurde eingetragen.", + "success_team": "{} hat seinen Geburtstag eingetragen: {}" + }, "add": { "xp": "Die {} von {} wurden um {} erhöht" }, diff --git a/kdb-bot/src/bot_api/__init__.py b/bot/src/bot_api/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/__init__.py rename to bot/src/bot_api/__init__.py index bc48f01b..6a63c058 100644 --- a/kdb-bot/src/bot_api/__init__.py +++ b/bot/src/bot_api/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/abc/__init__.py b/bot/src/bot_api/abc/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/abc/__init__.py rename to bot/src/bot_api/abc/__init__.py index 6213503f..2133612b 100644 --- a/kdb-bot/src/bot_api/abc/__init__.py +++ b/bot/src/bot_api/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.abc" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/abc/auth_service_abc.py b/bot/src/bot_api/abc/auth_service_abc.py similarity index 100% rename from kdb-bot/src/bot_api/abc/auth_service_abc.py rename to bot/src/bot_api/abc/auth_service_abc.py diff --git a/kdb-bot/src/bot_api/abc/dto_abc.py b/bot/src/bot_api/abc/dto_abc.py similarity index 100% rename from kdb-bot/src/bot_api/abc/dto_abc.py rename to bot/src/bot_api/abc/dto_abc.py diff --git a/kdb-bot/src/bot_api/abc/select_criteria_abc.py b/bot/src/bot_api/abc/select_criteria_abc.py similarity index 100% rename from kdb-bot/src/bot_api/abc/select_criteria_abc.py rename to bot/src/bot_api/abc/select_criteria_abc.py diff --git a/kdb-bot/src/bot_api/abc/transformer_abc.py b/bot/src/bot_api/abc/transformer_abc.py similarity index 100% rename from kdb-bot/src/bot_api/abc/transformer_abc.py rename to bot/src/bot_api/abc/transformer_abc.py diff --git a/kdb-bot/src/bot_api/api.py b/bot/src/bot_api/api.py similarity index 97% rename from kdb-bot/src/bot_api/api.py rename to bot/src/bot_api/api.py index dd086b2d..84184695 100644 --- a/kdb-bot/src/bot_api/api.py +++ b/bot/src/bot_api/api.py @@ -149,7 +149,10 @@ class Api(Flask): return response def start(self): - self._logger.info(__name__, f"Starting API {self._api_settings.host}:{self._api_settings.port}") + self._logger.info( + __name__, + f"Starting API {self._api_settings.host}:{self._api_settings.port}", + ) self._register_routes() self.secret_key = CredentialManager.decrypt(self._auth_settings.secret_key) # from waitress import serve diff --git a/kdb-bot/src/bot_api/api_module.py b/bot/src/bot_api/api_module.py similarity index 96% rename from kdb-bot/src/bot_api/api_module.py rename to bot/src/bot_api/api_module.py index 8f40f95e..b2695e12 100644 --- a/kdb-bot/src/bot_api/api_module.py +++ b/bot/src/bot_api/api_module.py @@ -48,4 +48,4 @@ class ApiModule(ModuleABC): services.add_transient(GraphQLController) # cpl-discord - self._dc.add_event(DiscordEventTypesEnum.on_ready.value, BotApiOnReadyEvent) + services.add_transient(DiscordEventTypesEnum.on_ready.value, BotApiOnReadyEvent) diff --git a/kdb-bot/src/bot_api/api_thread.py b/bot/src/bot_api/api_thread.py similarity index 100% rename from kdb-bot/src/bot_api/api_thread.py rename to bot/src/bot_api/api_thread.py diff --git a/kdb-bot/src/bot_api/app_api_extension.py b/bot/src/bot_api/app_api_extension.py similarity index 100% rename from kdb-bot/src/bot_api/app_api_extension.py rename to bot/src/bot_api/app_api_extension.py diff --git a/kdb-bot/src/bot_api/bot-api.json b/bot/src/bot_api/bot-api.json similarity index 95% rename from kdb-bot/src/bot_api/bot-api.json rename to bot/src/bot_api/bot-api.json index cc6404cc..a4529c34 100644 --- a/kdb-bot/src/bot_api/bot-api.json +++ b/bot/src/bot_api/bot-api.json @@ -3,8 +3,8 @@ "Name": "bot-api", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", diff --git a/bot/src/bot_api/config b/bot/src/bot_api/config new file mode 160000 index 00000000..521951b8 --- /dev/null +++ b/bot/src/bot_api/config @@ -0,0 +1 @@ +Subproject commit 521951b8abb0f784b59b6d3e0210606fa193e60a diff --git a/kdb-bot/src/bot_api/configuration/__init__.py b/bot/src/bot_api/configuration/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/configuration/__init__.py rename to bot/src/bot_api/configuration/__init__.py index f71552cc..36ddf985 100644 --- a/kdb-bot/src/bot_api/configuration/__init__.py +++ b/bot/src/bot_api/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.configuration" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/configuration/api_settings.py b/bot/src/bot_api/configuration/api_settings.py similarity index 100% rename from kdb-bot/src/bot_api/configuration/api_settings.py rename to bot/src/bot_api/configuration/api_settings.py diff --git a/kdb-bot/src/bot_api/configuration/authentication_settings.py b/bot/src/bot_api/configuration/authentication_settings.py similarity index 100% rename from kdb-bot/src/bot_api/configuration/authentication_settings.py rename to bot/src/bot_api/configuration/authentication_settings.py diff --git a/kdb-bot/src/bot_api/configuration/discord_authentication_settings.py b/bot/src/bot_api/configuration/discord_authentication_settings.py similarity index 100% rename from kdb-bot/src/bot_api/configuration/discord_authentication_settings.py rename to bot/src/bot_api/configuration/discord_authentication_settings.py diff --git a/kdb-bot/src/bot_api/configuration/frontend_settings.py b/bot/src/bot_api/configuration/frontend_settings.py similarity index 100% rename from kdb-bot/src/bot_api/configuration/frontend_settings.py rename to bot/src/bot_api/configuration/frontend_settings.py diff --git a/kdb-bot/src/bot_api/controller/__init__.py b/bot/src/bot_api/controller/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/controller/__init__.py rename to bot/src/bot_api/controller/__init__.py index 7739be1a..71f6b6d6 100644 --- a/kdb-bot/src/bot_api/controller/__init__.py +++ b/bot/src/bot_api/controller/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.controller" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/controller/auth_controller.py b/bot/src/bot_api/controller/auth_controller.py similarity index 100% rename from kdb-bot/src/bot_api/controller/auth_controller.py rename to bot/src/bot_api/controller/auth_controller.py diff --git a/kdb-bot/src/bot_api/controller/auth_discord_controller.py b/bot/src/bot_api/controller/auth_discord_controller.py similarity index 100% rename from kdb-bot/src/bot_api/controller/auth_discord_controller.py rename to bot/src/bot_api/controller/auth_discord_controller.py diff --git a/kdb-bot/src/bot_api/controller/graphql_controller.py b/bot/src/bot_api/controller/graphql_controller.py similarity index 100% rename from kdb-bot/src/bot_api/controller/graphql_controller.py rename to bot/src/bot_api/controller/graphql_controller.py diff --git a/kdb-bot/src/bot_api/controller/gui_controller.py b/bot/src/bot_api/controller/gui_controller.py similarity index 100% rename from kdb-bot/src/bot_api/controller/gui_controller.py rename to bot/src/bot_api/controller/gui_controller.py diff --git a/kdb-bot/src/bot_api/event/__init__.py b/bot/src/bot_api/event/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/event/__init__.py rename to bot/src/bot_api/event/__init__.py index afcad881..9b08b3f9 100644 --- a/kdb-bot/src/bot_api/event/__init__.py +++ b/bot/src/bot_api/event/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.event" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/event/bot_api_on_ready_event.py b/bot/src/bot_api/event/bot_api_on_ready_event.py similarity index 100% rename from kdb-bot/src/bot_api/event/bot_api_on_ready_event.py rename to bot/src/bot_api/event/bot_api_on_ready_event.py diff --git a/kdb-bot/src/bot_api/exception/__init__.py b/bot/src/bot_api/exception/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/exception/__init__.py rename to bot/src/bot_api/exception/__init__.py index 2b9e3b21..472e48c6 100644 --- a/kdb-bot/src/bot_api/exception/__init__.py +++ b/bot/src/bot_api/exception/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.exception" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/exception/service_error_code_enum.py b/bot/src/bot_api/exception/service_error_code_enum.py similarity index 100% rename from kdb-bot/src/bot_api/exception/service_error_code_enum.py rename to bot/src/bot_api/exception/service_error_code_enum.py diff --git a/kdb-bot/src/bot_api/exception/service_exception.py b/bot/src/bot_api/exception/service_exception.py similarity index 100% rename from kdb-bot/src/bot_api/exception/service_exception.py rename to bot/src/bot_api/exception/service_exception.py diff --git a/kdb-bot/src/bot_api/filter/__init__.py b/bot/src/bot_api/filter/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/filter/__init__.py rename to bot/src/bot_api/filter/__init__.py index bf6ccb2e..4629177d 100644 --- a/kdb-bot/src/bot_api/filter/__init__.py +++ b/bot/src/bot_api/filter/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.filter" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/filter/auth_user_select_criteria.py b/bot/src/bot_api/filter/auth_user_select_criteria.py similarity index 100% rename from kdb-bot/src/bot_api/filter/auth_user_select_criteria.py rename to bot/src/bot_api/filter/auth_user_select_criteria.py diff --git a/kdb-bot/src/bot_api/filter/discord/__init__.py b/bot/src/bot_api/filter/discord/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/filter/discord/__init__.py rename to bot/src/bot_api/filter/discord/__init__.py index 4c116cef..81083cb5 100644 --- a/kdb-bot/src/bot_api/filter/discord/__init__.py +++ b/bot/src/bot_api/filter/discord/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.filter.discord" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/filter/discord/server_select_criteria.py b/bot/src/bot_api/filter/discord/server_select_criteria.py similarity index 100% rename from kdb-bot/src/bot_api/filter/discord/server_select_criteria.py rename to bot/src/bot_api/filter/discord/server_select_criteria.py diff --git a/kdb-bot/src/bot_api/json_processor.py b/bot/src/bot_api/json_processor.py similarity index 100% rename from kdb-bot/src/bot_api/json_processor.py rename to bot/src/bot_api/json_processor.py diff --git a/kdb-bot/src/bot_api/logging/__init__.py b/bot/src/bot_api/logging/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/logging/__init__.py rename to bot/src/bot_api/logging/__init__.py index de51a5e8..28229873 100644 --- a/kdb-bot/src/bot_api/logging/__init__.py +++ b/bot/src/bot_api/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.logging" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/logging/api_logger.py b/bot/src/bot_api/logging/api_logger.py similarity index 100% rename from kdb-bot/src/bot_api/logging/api_logger.py rename to bot/src/bot_api/logging/api_logger.py diff --git a/kdb-bot/src/bot_api/model/__init__.py b/bot/src/bot_api/model/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/model/__init__.py rename to bot/src/bot_api/model/__init__.py index 6738fef5..428e3ced 100644 --- a/kdb-bot/src/bot_api/model/__init__.py +++ b/bot/src/bot_api/model/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.model" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/model/auth_user_dto.py b/bot/src/bot_api/model/auth_user_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/auth_user_dto.py rename to bot/src/bot_api/model/auth_user_dto.py diff --git a/kdb-bot/src/bot_api/model/auth_user_filtered_result_dto.py b/bot/src/bot_api/model/auth_user_filtered_result_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/auth_user_filtered_result_dto.py rename to bot/src/bot_api/model/auth_user_filtered_result_dto.py diff --git a/kdb-bot/src/bot_api/model/discord/__init__.py b/bot/src/bot_api/model/discord/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/model/discord/__init__.py rename to bot/src/bot_api/model/discord/__init__.py index cc131151..0b731ed3 100644 --- a/kdb-bot/src/bot_api/model/discord/__init__.py +++ b/bot/src/bot_api/model/discord/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.model.discord" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/model/discord/server_dto.py b/bot/src/bot_api/model/discord/server_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/discord/server_dto.py rename to bot/src/bot_api/model/discord/server_dto.py diff --git a/kdb-bot/src/bot_api/model/discord/server_filtered_result_dto.py b/bot/src/bot_api/model/discord/server_filtered_result_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/discord/server_filtered_result_dto.py rename to bot/src/bot_api/model/discord/server_filtered_result_dto.py diff --git a/kdb-bot/src/bot_api/model/email_string_dto.py b/bot/src/bot_api/model/email_string_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/email_string_dto.py rename to bot/src/bot_api/model/email_string_dto.py diff --git a/kdb-bot/src/bot_api/model/error_dto.py b/bot/src/bot_api/model/error_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/error_dto.py rename to bot/src/bot_api/model/error_dto.py diff --git a/kdb-bot/src/bot_api/model/o_auth_dto.py b/bot/src/bot_api/model/o_auth_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/o_auth_dto.py rename to bot/src/bot_api/model/o_auth_dto.py diff --git a/kdb-bot/src/bot_api/model/reset_password_dto.py b/bot/src/bot_api/model/reset_password_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/reset_password_dto.py rename to bot/src/bot_api/model/reset_password_dto.py diff --git a/kdb-bot/src/bot_api/model/settings_dto.py b/bot/src/bot_api/model/settings_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/settings_dto.py rename to bot/src/bot_api/model/settings_dto.py diff --git a/kdb-bot/src/bot_api/model/token_dto.py b/bot/src/bot_api/model/token_dto.py similarity index 82% rename from kdb-bot/src/bot_api/model/token_dto.py rename to bot/src/bot_api/model/token_dto.py index 88ff8501..f8c98922 100644 --- a/kdb-bot/src/bot_api/model/token_dto.py +++ b/bot/src/bot_api/model/token_dto.py @@ -27,4 +27,8 @@ class TokenDTO(DtoABC): self._first_login = values["firstLogin"] def to_dict(self) -> dict: - return {"token": self._token, "refreshToken": self._refresh_token, "firstLogin": self._first_login} + return { + "token": self._token, + "refreshToken": self._refresh_token, + "firstLogin": self._first_login, + } diff --git a/kdb-bot/src/bot_api/model/update_auth_user_dto.py b/bot/src/bot_api/model/update_auth_user_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/update_auth_user_dto.py rename to bot/src/bot_api/model/update_auth_user_dto.py diff --git a/kdb-bot/src/bot_api/model/user_dto.py b/bot/src/bot_api/model/user_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/user_dto.py rename to bot/src/bot_api/model/user_dto.py diff --git a/kdb-bot/src/bot_api/model/version_dto.py b/bot/src/bot_api/model/version_dto.py similarity index 100% rename from kdb-bot/src/bot_api/model/version_dto.py rename to bot/src/bot_api/model/version_dto.py diff --git a/kdb-bot/src/bot_api/route/__init__.py b/bot/src/bot_api/route/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/route/__init__.py rename to bot/src/bot_api/route/__init__.py index 388aa4b0..81792f2e 100644 --- a/kdb-bot/src/bot_api/route/__init__.py +++ b/bot/src/bot_api/route/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.route" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/route/route.py b/bot/src/bot_api/route/route.py similarity index 94% rename from kdb-bot/src/bot_api/route/route.py rename to bot/src/bot_api/route/route.py index 74278f28..a72b28e3 100644 --- a/kdb-bot/src/bot_api/route/route.py +++ b/bot/src/bot_api/route/route.py @@ -25,7 +25,12 @@ class Route: @classmethod @ServiceProviderABC.inject - def init_authorize(cls, env: ApplicationEnvironmentABC, auth_users: AuthUserRepositoryABC, auth: AuthServiceABC): + def init_authorize( + cls, + env: ApplicationEnvironmentABC, + auth_users: AuthUserRepositoryABC, + auth: AuthServiceABC, + ): cls._auth_users = auth_users cls._auth = auth cls._env = env.environment_name @@ -52,7 +57,13 @@ class Route: return user @classmethod - def authorize(cls, f: Callable = None, role: AuthRoleEnum = None, skip_in_dev=False, by_api_key=False): + def authorize( + cls, + f: Callable = None, + role: AuthRoleEnum = None, + skip_in_dev=False, + by_api_key=False, + ): if f is None: return functools.partial(cls.authorize, role=role, skip_in_dev=skip_in_dev, by_api_key=by_api_key) diff --git a/kdb-bot/src/bot_api/service/__init__.py b/bot/src/bot_api/service/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/service/__init__.py rename to bot/src/bot_api/service/__init__.py index 90c30c61..234af1ca 100644 --- a/kdb-bot/src/bot_api/service/__init__.py +++ b/bot/src/bot_api/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/service/auth_service.py b/bot/src/bot_api/service/auth_service.py similarity index 100% rename from kdb-bot/src/bot_api/service/auth_service.py rename to bot/src/bot_api/service/auth_service.py diff --git a/kdb-bot/src/bot_api/service/discord_service.py b/bot/src/bot_api/service/discord_service.py similarity index 100% rename from kdb-bot/src/bot_api/service/discord_service.py rename to bot/src/bot_api/service/discord_service.py diff --git a/kdb-bot/src/bot_api/transformer/__init__.py b/bot/src/bot_api/transformer/__init__.py similarity index 84% rename from kdb-bot/src/bot_api/transformer/__init__.py rename to bot/src/bot_api/transformer/__init__.py index 4e1c7916..f1f8e791 100644 --- a/kdb-bot/src/bot_api/transformer/__init__.py +++ b/bot/src/bot_api/transformer/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_api.transformer" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_api/transformer/auth_user_transformer.py b/bot/src/bot_api/transformer/auth_user_transformer.py similarity index 100% rename from kdb-bot/src/bot_api/transformer/auth_user_transformer.py rename to bot/src/bot_api/transformer/auth_user_transformer.py diff --git a/kdb-bot/src/bot_api/transformer/server_transformer.py b/bot/src/bot_api/transformer/server_transformer.py similarity index 100% rename from kdb-bot/src/bot_api/transformer/server_transformer.py rename to bot/src/bot_api/transformer/server_transformer.py diff --git a/kdb-bot/src/bot_core/__init__.py b/bot/src/bot_core/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/__init__.py rename to bot/src/bot_core/__init__.py index 805ee627..762b31f9 100644 --- a/kdb-bot/src/bot_core/__init__.py +++ b/bot/src/bot_core/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/abc/__init__.py b/bot/src/bot_core/abc/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/abc/__init__.py rename to bot/src/bot_core/abc/__init__.py index f6eea2b3..09549563 100644 --- a/kdb-bot/src/bot_core/abc/__init__.py +++ b/bot/src/bot_core/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.abc" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/abc/client_utils_abc.py b/bot/src/bot_core/abc/client_utils_abc.py similarity index 88% rename from kdb-bot/src/bot_core/abc/client_utils_abc.py rename to bot/src/bot_core/abc/client_utils_abc.py index 045228cb..66e25500 100644 --- a/kdb-bot/src/bot_core/abc/client_utils_abc.py +++ b/bot/src/bot_core/abc/client_utils_abc.py @@ -64,10 +64,18 @@ class ClientUtilsABC(ABC): @abstractmethod async def react_to_message_by_auto_role_rule( - self, discord_channel_id: int, discord_message_id: int, rule: AutoRoleRule, guild: discord.Guild + self, + discord_channel_id: int, + discord_message_id: int, + rule: AutoRoleRule, + guild: discord.Guild, ): pass @abstractmethod async def check_default_role(self, member: Union[discord.User, discord.Member]): pass + + @abstractmethod + async def set_maintenance_mode(self, state: bool): + pass diff --git a/kdb-bot/src/bot_core/abc/custom_file_logger_abc.py b/bot/src/bot_core/abc/custom_file_logger_abc.py similarity index 100% rename from kdb-bot/src/bot_core/abc/custom_file_logger_abc.py rename to bot/src/bot_core/abc/custom_file_logger_abc.py diff --git a/kdb-bot/src/bot_core/abc/message_service_abc.py b/bot/src/bot_core/abc/message_service_abc.py similarity index 100% rename from kdb-bot/src/bot_core/abc/message_service_abc.py rename to bot/src/bot_core/abc/message_service_abc.py diff --git a/kdb-bot/src/bot_core/abc/module_abc.py b/bot/src/bot_core/abc/module_abc.py similarity index 100% rename from kdb-bot/src/bot_core/abc/module_abc.py rename to bot/src/bot_core/abc/module_abc.py diff --git a/bot/src/bot_core/abc/task_abc.py b/bot/src/bot_core/abc/task_abc.py new file mode 100644 index 00000000..5f578a99 --- /dev/null +++ b/bot/src/bot_core/abc/task_abc.py @@ -0,0 +1,33 @@ +import asyncio +from abc import abstractmethod + +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceProviderABC +from cpl_discord.service import DiscordBotServiceABC +from discord.ext import commands + +from bot_core.environment_variables import MAINTENANCE +from bot_core.logging.task_logger import TaskLogger + + +class TaskABC(commands.Cog): + @abstractmethod + def __init__(self): + commands.Cog.__init__(self) + + @ServiceProviderABC.inject + def _is_maintenance(self, config: ConfigurationABC) -> bool: + return config.get_configuration(MAINTENANCE) is True + + @ServiceProviderABC.inject + async def _wait_until_ready(self, config: ConfigurationABC, logger: TaskLogger, bot: DiscordBotServiceABC): + logger.debug(__name__, f"Waiting before {type(self).__name__}") + await bot.wait_until_ready() + + async def wait(): + is_ready = config.get_configuration("IS_READY") is True + if not is_ready: + await asyncio.sleep(1) + await wait() + + await wait() diff --git a/kdb-bot/src/bot_core/bot-core.json b/bot/src/bot_core/bot-core.json similarity index 96% rename from kdb-bot/src/bot_core/bot-core.json rename to bot/src/bot_core/bot-core.json index c8a158d2..9cf7075d 100644 --- a/kdb-bot/src/bot_core/bot-core.json +++ b/bot/src/bot_core/bot-core.json @@ -3,8 +3,8 @@ "Name": "bot-core", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/bot_core/configuration/__init__.py b/bot/src/bot_core/configuration/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/configuration/__init__.py rename to bot/src/bot_core/configuration/__init__.py index 5e342ba4..609f8642 100644 --- a/kdb-bot/src/bot_core/configuration/__init__.py +++ b/bot/src/bot_core/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.configuration" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/configuration/bot_logging_settings.py b/bot/src/bot_core/configuration/bot_logging_settings.py similarity index 100% rename from kdb-bot/src/bot_core/configuration/bot_logging_settings.py rename to bot/src/bot_core/configuration/bot_logging_settings.py diff --git a/kdb-bot/src/bot_core/configuration/feature_flags_enum.py b/bot/src/bot_core/configuration/feature_flags_enum.py similarity index 88% rename from kdb-bot/src/bot_core/configuration/feature_flags_enum.py rename to bot/src/bot_core/configuration/feature_flags_enum.py index f56f06b0..6d051b0c 100644 --- a/kdb-bot/src/bot_core/configuration/feature_flags_enum.py +++ b/bot/src/bot_core/configuration/feature_flags_enum.py @@ -17,6 +17,7 @@ class FeatureFlagsEnum(Enum): moderator_module = "ModeratorModule" permission_module = "PermissionModule" short_role_name_module = "ShortRoleNameModule" + steam_special_offers_module = "SteamSpecialOffersModule" # features api_only = "ApiOnly" presence = "Presence" @@ -25,3 +26,4 @@ class FeatureFlagsEnum(Enum): sync_xp = "SyncXp" short_role_name = "ShortRoleName" technician_full_access = "TechnicianFullAccess" + steam_special_offers = "SteamSpecialOffers" diff --git a/kdb-bot/src/bot_core/configuration/feature_flags_settings.py b/bot/src/bot_core/configuration/feature_flags_settings.py similarity index 94% rename from kdb-bot/src/bot_core/configuration/feature_flags_settings.py rename to bot/src/bot_core/configuration/feature_flags_settings.py index 37c17483..0ed95e71 100644 --- a/kdb-bot/src/bot_core/configuration/feature_flags_settings.py +++ b/bot/src/bot_core/configuration/feature_flags_settings.py @@ -19,6 +19,7 @@ class FeatureFlagsSettings(ConfigurationModelABC): FeatureFlagsEnum.permission_module.value: True, # 02.10.2022 #48 FeatureFlagsEnum.config_module.value: True, # 19.07.2023 #127 FeatureFlagsEnum.short_role_name_module.value: True, # 28.09.2023 #378 + FeatureFlagsEnum.steam_special_offers_module.value: True, # 11.10.2023 #188 # features FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70 FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56 @@ -27,6 +28,7 @@ class FeatureFlagsSettings(ConfigurationModelABC): FeatureFlagsEnum.sync_xp.value: False, # 25.09.2023 #366 FeatureFlagsEnum.short_role_name.value: False, # 28.09.2023 #378 FeatureFlagsEnum.technician_full_access.value: False, # 03.10.2023 #393 + FeatureFlagsEnum.steam_special_offers.value: False, # 11.10.2023 #188 } def __init__(self, **kwargs: dict): diff --git a/kdb-bot/src/bot_core/configuration/file_logging_settings.py b/bot/src/bot_core/configuration/file_logging_settings.py similarity index 100% rename from kdb-bot/src/bot_core/configuration/file_logging_settings.py rename to bot/src/bot_core/configuration/file_logging_settings.py diff --git a/kdb-bot/src/bot_core/core_extension/__init__.py b/bot/src/bot_core/core_extension/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/core_extension/__init__.py rename to bot/src/bot_core/core_extension/__init__.py index 97f48599..3ce1acb8 100644 --- a/kdb-bot/src/bot_core/core_extension/__init__.py +++ b/bot/src/bot_core/core_extension/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.core_extension" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/core_extension/core_extension.py b/bot/src/bot_core/core_extension/core_extension.py similarity index 100% rename from kdb-bot/src/bot_core/core_extension/core_extension.py rename to bot/src/bot_core/core_extension/core_extension.py diff --git a/kdb-bot/src/bot_core/core_extension/core_extension_module.py b/bot/src/bot_core/core_extension/core_extension_module.py similarity index 90% rename from kdb-bot/src/bot_core/core_extension/core_extension_module.py rename to bot/src/bot_core/core_extension/core_extension_module.py index d6cba99b..ef16529f 100644 --- a/kdb-bot/src/bot_core/core_extension/core_extension_module.py +++ b/bot/src/bot_core/core_extension/core_extension_module.py @@ -19,4 +19,4 @@ class CoreExtensionModule(ModuleABC): pass def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): - self._dc.add_event(DiscordEventTypesEnum.on_ready.value, CoreExtensionOnReadyEvent) + services.add_transient(DiscordEventTypesEnum.on_ready.value, CoreExtensionOnReadyEvent) diff --git a/kdb-bot/src/bot_core/core_extension/core_extension_on_ready_event.py b/bot/src/bot_core/core_extension/core_extension_on_ready_event.py similarity index 75% rename from kdb-bot/src/bot_core/core_extension/core_extension_on_ready_event.py rename to bot/src/bot_core/core_extension/core_extension_on_ready_event.py index 78992473..277cf566 100644 --- a/kdb-bot/src/bot_core/core_extension/core_extension_on_ready_event.py +++ b/bot/src/bot_core/core_extension/core_extension_on_ready_event.py @@ -1,16 +1,19 @@ import asyncio +from cpl_core.configuration import ConfigurationABC from cpl_core.logging import LoggerABC from cpl_discord.events import OnReadyABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe from bot_core.abc.client_utils_abc import ClientUtilsABC +from bot_core.environment_variables import MAINTENANCE class CoreExtensionOnReadyEvent(OnReadyABC): def __init__( self, + config: ConfigurationABC, logger: LoggerABC, bot: DiscordBotServiceABC, client_utils: ClientUtilsABC, @@ -18,6 +21,7 @@ class CoreExtensionOnReadyEvent(OnReadyABC): ): OnReadyABC.__init__(self) + self._config = config self._logger = logger self._bot = bot self._client_utils = client_utils @@ -27,5 +31,5 @@ class CoreExtensionOnReadyEvent(OnReadyABC): async def on_ready(self): self._logger.debug(__name__, f"Module {type(self)} started") - await self._client_utils.presence_game("common.presence.running") + await self._client_utils.set_maintenance_mode(self._config.get_configuration(MAINTENANCE)) self._logger.trace(__name__, f"Module {type(self)} stopped") diff --git a/kdb-bot/src/bot_core/core_module.py b/bot/src/bot_core/core_module.py similarity index 94% rename from kdb-bot/src/bot_core/core_module.py rename to bot/src/bot_core/core_module.py index fcb06333..02611684 100644 --- a/kdb-bot/src/bot_core/core_module.py +++ b/bot/src/bot_core/core_module.py @@ -32,4 +32,4 @@ class CoreModule(ModuleABC): # pipes services.add_transient(DateTimeOffsetPipe) - self._dc.add_event(DiscordEventTypesEnum.on_ready.value, CoreOnReadyEvent) + services.add_transient(DiscordEventTypesEnum.on_ready.value, CoreOnReadyEvent) diff --git a/bot/src/bot_core/environment_variables.py b/bot/src/bot_core/environment_variables.py new file mode 100644 index 00000000..74a9dc01 --- /dev/null +++ b/bot/src/bot_core/environment_variables.py @@ -0,0 +1,2 @@ +MIGRATION_ONLY = "MIGRATION_ONLY" +MAINTENANCE = "MAINTENANCE" diff --git a/kdb-bot/src/bot_core/events/__init__.py b/bot/src/bot_core/events/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/events/__init__.py rename to bot/src/bot_core/events/__init__.py index e5c7148f..a0543256 100644 --- a/kdb-bot/src/bot_core/events/__init__.py +++ b/bot/src/bot_core/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/events/core_on_ready_event.py b/bot/src/bot_core/events/core_on_ready_event.py similarity index 100% rename from kdb-bot/src/bot_core/events/core_on_ready_event.py rename to bot/src/bot_core/events/core_on_ready_event.py diff --git a/kdb-bot/src/bot_core/exception/__init__.py b/bot/src/bot_core/exception/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/exception/__init__.py rename to bot/src/bot_core/exception/__init__.py index 4b561eeb..8e7daf7e 100644 --- a/kdb-bot/src/bot_core/exception/__init__.py +++ b/bot/src/bot_core/exception/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.exception" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/exception/check_error.py b/bot/src/bot_core/exception/check_error.py similarity index 100% rename from kdb-bot/src/bot_core/exception/check_error.py rename to bot/src/bot_core/exception/check_error.py diff --git a/kdb-bot/src/bot_core/helper/__init__.py b/bot/src/bot_core/helper/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/helper/__init__.py rename to bot/src/bot_core/helper/__init__.py index cc9f6ade..b597c6fd 100644 --- a/kdb-bot/src/bot_core/helper/__init__.py +++ b/bot/src/bot_core/helper/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.helper" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/helper/command_checks.py b/bot/src/bot_core/helper/command_checks.py similarity index 100% rename from kdb-bot/src/bot_core/helper/command_checks.py rename to bot/src/bot_core/helper/command_checks.py diff --git a/kdb-bot/src/bot_core/helper/event_checks.py b/bot/src/bot_core/helper/event_checks.py similarity index 50% rename from kdb-bot/src/bot_core/helper/event_checks.py rename to bot/src/bot_core/helper/event_checks.py index 5639a3da..e94f10cf 100644 --- a/kdb-bot/src/bot_core/helper/event_checks.py +++ b/bot/src/bot_core/helper/event_checks.py @@ -1,3 +1,4 @@ +import inspect from typing import Optional from discord.ext import commands @@ -17,11 +18,18 @@ class EventChecks: cls._client_utils = client_utils @classmethod - def check_is_ready(cls): - async def check_if_bot_is_ready() -> bool: + def check_is_ready(cls, func): + async def check_if_bot_is_ready(*args, **kwargs): result = await cls._client_utils.check_if_bot_is_ready_yet() if not result: - raise CheckError(f"Bot is not ready") - return result - return commands.check(check_if_bot_is_ready) + def empty(*args, **kwargs): + return + + return empty + return await func(*args, **kwargs) + + check_if_bot_is_ready.__name__ = func.__name__ + sig = inspect.signature(func) + check_if_bot_is_ready.__signature__ = sig.replace(parameters=tuple(sig.parameters.values())[1:]) + return check_if_bot_is_ready diff --git a/kdb-bot/src/bot_core/helper/log_message_helper.py b/bot/src/bot_core/helper/log_message_helper.py similarity index 100% rename from kdb-bot/src/bot_core/helper/log_message_helper.py rename to bot/src/bot_core/helper/log_message_helper.py diff --git a/kdb-bot/src/bot_core/logging/__init__.py b/bot/src/bot_core/logging/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/logging/__init__.py rename to bot/src/bot_core/logging/__init__.py index 8564fabb..1622cb57 100644 --- a/kdb-bot/src/bot_core/logging/__init__.py +++ b/bot/src/bot_core/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.logging" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/logging/command_logger.py b/bot/src/bot_core/logging/command_logger.py similarity index 100% rename from kdb-bot/src/bot_core/logging/command_logger.py rename to bot/src/bot_core/logging/command_logger.py diff --git a/kdb-bot/src/bot_core/logging/database_logger.py b/bot/src/bot_core/logging/database_logger.py similarity index 100% rename from kdb-bot/src/bot_core/logging/database_logger.py rename to bot/src/bot_core/logging/database_logger.py diff --git a/kdb-bot/src/bot_core/logging/message_logger.py b/bot/src/bot_core/logging/message_logger.py similarity index 100% rename from kdb-bot/src/bot_core/logging/message_logger.py rename to bot/src/bot_core/logging/message_logger.py diff --git a/bot/src/bot_core/logging/task_logger.py b/bot/src/bot_core/logging/task_logger.py new file mode 100644 index 00000000..fc4a637c --- /dev/null +++ b/bot/src/bot_core/logging/task_logger.py @@ -0,0 +1,15 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_core.time import TimeFormatSettings + +from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC + + +class TaskLogger(CustomFileLoggerABC): + def __init__( + self, + config: ConfigurationABC, + time_format: TimeFormatSettings, + env: ApplicationEnvironmentABC, + ): + CustomFileLoggerABC.__init__(self, "Task", config, time_format, env) diff --git a/kdb-bot/src/bot_core/pipes/__init__.py b/bot/src/bot_core/pipes/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/pipes/__init__.py rename to bot/src/bot_core/pipes/__init__.py index 9bde3a5f..9b035bbb 100644 --- a/kdb-bot/src/bot_core/pipes/__init__.py +++ b/bot/src/bot_core/pipes/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.pipes" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/pipes/date_time_offset_pipe.py b/bot/src/bot_core/pipes/date_time_offset_pipe.py similarity index 100% rename from kdb-bot/src/bot_core/pipes/date_time_offset_pipe.py rename to bot/src/bot_core/pipes/date_time_offset_pipe.py diff --git a/kdb-bot/src/bot_core/service/__init__.py b/bot/src/bot_core/service/__init__.py similarity index 84% rename from kdb-bot/src/bot_core/service/__init__.py rename to bot/src/bot_core/service/__init__.py index 895cf293..74bbfed6 100644 --- a/kdb-bot/src/bot_core/service/__init__.py +++ b/bot/src/bot_core/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_core.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_core/service/client_utils_service.py b/bot/src/bot_core/service/client_utils_service.py similarity index 91% rename from kdb-bot/src/bot_core/service/client_utils_service.py rename to bot/src/bot_core/service/client_utils_service.py index 24143dbb..e316bf03 100644 --- a/kdb-bot/src/bot_core/service/client_utils_service.py +++ b/bot/src/bot_core/service/client_utils_service.py @@ -16,6 +16,7 @@ from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.environment_variables import MAINTENANCE from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_voice_channel_repository_abc import ( @@ -87,7 +88,14 @@ class ClientUtilsService(ClientUtilsABC): return client async def check_if_bot_is_ready_yet(self) -> bool: - if self._config.get_configuration("IS_READY") == "true": + if self._config.get_configuration(MAINTENANCE): + self._logger.warn( + __name__, + f"Bot is in maintenance mode", + ) + return False + + if self._config.get_configuration("IS_READY") is True: return True self._logger.debug( @@ -131,7 +139,7 @@ class ClientUtilsService(ClientUtilsABC): if current in sl: sl = sl.skip(sl.index_of(current)) - _l = _l.where(lambda x: x.name in sl) + _l = _l.where(lambda x: select(x) in sl) return _l.take(25) @@ -196,7 +204,11 @@ class ClientUtilsService(ClientUtilsABC): ) async def react_to_message_by_auto_role_rule( - self, discord_channel_id: int, discord_message_id: int, rule: AutoRoleRule, guild: discord.Guild + self, + discord_channel_id: int, + discord_message_id: int, + rule: AutoRoleRule, + guild: discord.Guild, ): try: guild: Guild = self._bot.guilds.where(lambda g: g == guild).single() @@ -235,3 +247,10 @@ class ClientUtilsService(ClientUtilsABC): except Exception as e: self._logger.error(__name__, f"Cannot check for default role for member {member.id}", e) + + async def set_maintenance_mode(self, state: bool): + self._config.add_configuration(MAINTENANCE, state) + if state: + await self.presence_game("common.presence.maintenance") + else: + await self.presence_game("common.presence.running") diff --git a/kdb-bot/src/bot_core/service/config_service.py b/bot/src/bot_core/service/config_service.py similarity index 68% rename from kdb-bot/src/bot_core/service/config_service.py rename to bot/src/bot_core/service/config_service.py index 6aa29b83..9e231168 100644 --- a/kdb-bot/src/bot_core/service/config_service.py +++ b/bot/src/bot_core/service/config_service.py @@ -7,6 +7,7 @@ from bot_data.abc.technician_config_repository_abc import TechnicianConfigReposi from bot_data.model.server import Server from bot_data.model.technician_config import TechnicianConfig from bot_data.service.server_config_seeder import ServerConfigSeeder +from bot_data.service.technician_config_seeder import TechnicianConfigSeeder class ConfigService: @@ -16,19 +17,29 @@ class ConfigService: services: ServiceProviderABC, technician_config_repo: TechnicianConfigRepositoryABC, server_config_repo: ServerConfigRepositoryABC, + technician_seeder: TechnicianConfigSeeder, server_seeder: ServerConfigSeeder, ): self._config = config self._services = services self._technician_config_repo = technician_config_repo + self._technician_seeder = technician_seeder self._server_config_repo = server_config_repo self._server_seeder = server_seeder - def reload_technician_config(self): - technician_config = self._technician_config_repo.get_technician_config() + async def reload_technician_config(self): + try: + technician_config = self._technician_config_repo.get_technician_config() + except Exception as e: + await self._technician_seeder.seed() + technician_config = self._technician_config_repo.get_technician_config() + self._config.add_configuration(TechnicianConfig, technician_config) - self._config.add_configuration(FeatureFlagsSettings, FeatureFlagsSettings(**technician_config.feature_flags)) + self._config.add_configuration( + FeatureFlagsSettings, + FeatureFlagsSettings(**technician_config.feature_flags), + ) async def reload_server_config(self, server: Server): if not self._server_config_repo.does_server_config_exists(server.id): @@ -36,5 +47,6 @@ class ConfigService: server_config = self._server_config_repo.get_server_config_by_server(server.id) self._config.add_configuration( - f"{type(server_config).__name__}_{server_config.server.discord_id}", server_config + f"{type(server_config).__name__}_{server_config.server.discord_id}", + server_config, ) diff --git a/kdb-bot/src/bot_core/service/data_integrity_service.py b/bot/src/bot_core/service/data_integrity_service.py similarity index 96% rename from kdb-bot/src/bot_core/service/data_integrity_service.py rename to bot/src/bot_core/service/data_integrity_service.py index 9a2e613e..cb3c0f6f 100644 --- a/kdb-bot/src/bot_core/service/data_integrity_service.py +++ b/bot/src/bot_core/service/data_integrity_service.py @@ -11,7 +11,9 @@ from bot_core.logging.database_logger import DatabaseLogger from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC -from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC +from bot_data.abc.user_joined_game_server_repository_abc import ( + UserJoinedGameServerRepositoryABC, +) from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_joined_voice_channel_repository_abc import ( UserJoinedVoiceChannelRepositoryABC, @@ -174,7 +176,7 @@ class DataIntegrityService: 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, server)) + self._users.add_user(User(u.id, 0, 0, 0, None, server)) self._db_context.save_changes() self._logger.debug(__name__, f"Added User: {u.id}") @@ -387,6 +389,19 @@ class DataIntegrityService: for member in guild.members: await self._client_utils.check_default_role(member) + def _check_for_bots(self): + for guild in self._bot.guilds: + server = self._servers.get_server_by_discord_id(guild.id) + + 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 + + self._user_joins_vc.delete_user_joined_voice_channel_by_user_id(user.id) + self._users.delete_user(user) + 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 @@ -400,3 +415,4 @@ class DataIntegrityService: self._check_user_joins_vc() self._check_user_joined_gs() await self._check_for_user_achievements() + self._check_for_bots() diff --git a/kdb-bot/src/bot_core/service/message_service.py b/bot/src/bot_core/service/message_service.py similarity index 97% rename from kdb-bot/src/bot_core/service/message_service.py rename to bot/src/bot_core/service/message_service.py index 71caa831..9140742f 100644 --- a/kdb-bot/src/bot_core/service/message_service.py +++ b/bot/src/bot_core/service/message_service.py @@ -71,7 +71,7 @@ class MessageService(MessageServiceABC): async def send_channel_message( self, channel: discord.TextChannel, - message: Union[str, discord.Embed], + message: Union[str, discord.Embed, list[discord.Embed]], is_persistent: bool = False, wait_before_delete: int = None, without_tracking=False, @@ -81,6 +81,8 @@ class MessageService(MessageServiceABC): try: if isinstance(message, discord.Embed): msg = await channel.send(embed=message) + elif isinstance(message, list): + msg = await channel.send(embeds=message) else: msg = await channel.send(message) except Exception as e: diff --git a/kdb-bot/src/bot_data/__init__.py b/bot/src/bot_data/__init__.py similarity index 84% rename from kdb-bot/src/bot_data/__init__.py rename to bot/src/bot_data/__init__.py index 7f7f0a26..dba7fc2c 100644 --- a/kdb-bot/src/bot_data/__init__.py +++ b/bot/src/bot_data/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_data" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_data/abc/__init__.py b/bot/src/bot_data/abc/__init__.py similarity index 84% rename from kdb-bot/src/bot_data/abc/__init__.py rename to bot/src/bot_data/abc/__init__.py index bcdb8b20..4341c756 100644 --- a/kdb-bot/src/bot_data/abc/__init__.py +++ b/bot/src/bot_data/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_data.abc" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_data/abc/achievement_repository_abc.py b/bot/src/bot_data/abc/achievement_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/achievement_repository_abc.py rename to bot/src/bot_data/abc/achievement_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/api_key_repository_abc.py b/bot/src/bot_data/abc/api_key_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/api_key_repository_abc.py rename to bot/src/bot_data/abc/api_key_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/auth_user_repository_abc.py b/bot/src/bot_data/abc/auth_user_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/auth_user_repository_abc.py rename to bot/src/bot_data/abc/auth_user_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/auto_role_repository_abc.py b/bot/src/bot_data/abc/auto_role_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/auto_role_repository_abc.py rename to bot/src/bot_data/abc/auto_role_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/client_repository_abc.py b/bot/src/bot_data/abc/client_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/client_repository_abc.py rename to bot/src/bot_data/abc/client_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/data_seeder_abc.py b/bot/src/bot_data/abc/data_seeder_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/data_seeder_abc.py rename to bot/src/bot_data/abc/data_seeder_abc.py diff --git a/kdb-bot/src/bot_data/abc/game_server_repository_abc.py b/bot/src/bot_data/abc/game_server_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/game_server_repository_abc.py rename to bot/src/bot_data/abc/game_server_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/history_table_abc.py b/bot/src/bot_data/abc/history_table_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/history_table_abc.py rename to bot/src/bot_data/abc/history_table_abc.py diff --git a/kdb-bot/src/bot_data/abc/known_user_repository_abc.py b/bot/src/bot_data/abc/known_user_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/known_user_repository_abc.py rename to bot/src/bot_data/abc/known_user_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/level_repository_abc.py b/bot/src/bot_data/abc/level_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/level_repository_abc.py rename to bot/src/bot_data/abc/level_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/migration_abc.py b/bot/src/bot_data/abc/migration_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/migration_abc.py rename to bot/src/bot_data/abc/migration_abc.py diff --git a/kdb-bot/src/bot_data/abc/server_config_repository_abc.py b/bot/src/bot_data/abc/server_config_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/server_config_repository_abc.py rename to bot/src/bot_data/abc/server_config_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/server_repository_abc.py b/bot/src/bot_data/abc/server_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/server_repository_abc.py rename to bot/src/bot_data/abc/server_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/short_role_name_repository_abc.py b/bot/src/bot_data/abc/short_role_name_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/short_role_name_repository_abc.py rename to bot/src/bot_data/abc/short_role_name_repository_abc.py diff --git a/bot/src/bot_data/abc/steam_special_offer_repository_abc.py b/bot/src/bot_data/abc/steam_special_offer_repository_abc.py new file mode 100644 index 00000000..7f412730 --- /dev/null +++ b/bot/src/bot_data/abc/steam_special_offer_repository_abc.py @@ -0,0 +1,32 @@ +from abc import ABC, abstractmethod +from typing import Optional + +from cpl_query.extension import List + +from bot_data.model.steam_special_offer import SteamSpecialOffer + + +class SteamSpecialOfferRepositoryABC(ABC): + @abstractmethod + def __init__(self): + pass + + @abstractmethod + def get_steam_special_offers(self) -> List[SteamSpecialOffer]: + pass + + @abstractmethod + def get_steam_special_offer_by_name(self, name: str) -> SteamSpecialOffer: + pass + + @abstractmethod + def add_steam_special_offer(self, steam_special_offer: SteamSpecialOffer): + pass + + @abstractmethod + def update_steam_special_offer(self, steam_special_offer: SteamSpecialOffer): + pass + + @abstractmethod + def delete_steam_special_offer(self, steam_special_offer: SteamSpecialOffer): + pass diff --git a/kdb-bot/src/bot_data/abc/table_with_id_abc.py b/bot/src/bot_data/abc/table_with_id_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/table_with_id_abc.py rename to bot/src/bot_data/abc/table_with_id_abc.py diff --git a/kdb-bot/src/bot_data/abc/technician_config_repository_abc.py b/bot/src/bot_data/abc/technician_config_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/technician_config_repository_abc.py rename to bot/src/bot_data/abc/technician_config_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/user_game_ident_repository_abc.py b/bot/src/bot_data/abc/user_game_ident_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/user_game_ident_repository_abc.py rename to bot/src/bot_data/abc/user_game_ident_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/user_joined_game_server_repository_abc.py b/bot/src/bot_data/abc/user_joined_game_server_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/user_joined_game_server_repository_abc.py rename to bot/src/bot_data/abc/user_joined_game_server_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/user_joined_server_repository_abc.py b/bot/src/bot_data/abc/user_joined_server_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/user_joined_server_repository_abc.py rename to bot/src/bot_data/abc/user_joined_server_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/user_joined_voice_channel_repository_abc.py b/bot/src/bot_data/abc/user_joined_voice_channel_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/user_joined_voice_channel_repository_abc.py rename to bot/src/bot_data/abc/user_joined_voice_channel_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/user_message_count_per_hour_repository_abc.py b/bot/src/bot_data/abc/user_message_count_per_hour_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/user_message_count_per_hour_repository_abc.py rename to bot/src/bot_data/abc/user_message_count_per_hour_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/user_repository_abc.py b/bot/src/bot_data/abc/user_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/user_repository_abc.py rename to bot/src/bot_data/abc/user_repository_abc.py diff --git a/kdb-bot/src/bot_data/abc/user_warnings_repository_abc.py b/bot/src/bot_data/abc/user_warnings_repository_abc.py similarity index 100% rename from kdb-bot/src/bot_data/abc/user_warnings_repository_abc.py rename to bot/src/bot_data/abc/user_warnings_repository_abc.py diff --git a/kdb-bot/src/bot_data/bot-data.json b/bot/src/bot_data/bot-data.json similarity index 96% rename from kdb-bot/src/bot_data/bot-data.json rename to bot/src/bot_data/bot-data.json index 3e0dac07..8300b491 100644 --- a/kdb-bot/src/bot_data/bot-data.json +++ b/bot/src/bot_data/bot-data.json @@ -3,8 +3,8 @@ "Name": "bot-data", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/bot_data/data_module.py b/bot/src/bot_data/data_module.py similarity index 87% rename from kdb-bot/src/bot_data/data_module.py rename to bot/src/bot_data/data_module.py index 427c9cc6..cec9cb37 100644 --- a/kdb-bot/src/bot_data/data_module.py +++ b/bot/src/bot_data/data_module.py @@ -17,9 +17,14 @@ from bot_data.abc.level_repository_abc import LevelRepositoryABC from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.short_role_name_repository_abc import ShortRoleNameRepositoryABC +from bot_data.abc.steam_special_offer_repository_abc import ( + SteamSpecialOfferRepositoryABC, +) from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC -from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC +from bot_data.abc.user_joined_game_server_repository_abc import ( + UserJoinedGameServerRepositoryABC, +) from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_joined_voice_channel_repository_abc import ( UserJoinedVoiceChannelRepositoryABC, @@ -29,7 +34,9 @@ from bot_data.abc.user_message_count_per_hour_repository_abc import ( ) from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC -from bot_data.service.achievements_repository_service import AchievementRepositoryService +from bot_data.service.achievements_repository_service import ( + AchievementRepositoryService, +) from bot_data.service.api_key_repository_service import ApiKeyRepositoryService from bot_data.service.auth_user_repository_service import AuthUserRepositoryService from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService @@ -39,14 +46,27 @@ from bot_data.service.game_server_repository_service import GameServerRepository from bot_data.service.known_user_repository_service import KnownUserRepositoryService from bot_data.service.level_repository_service import LevelRepositoryService from bot_data.service.seeder_service import SeederService -from bot_data.service.server_config_repository_service import ServerConfigRepositoryService +from bot_data.service.server_config_repository_service import ( + ServerConfigRepositoryService, +) from bot_data.service.server_config_seeder import ServerConfigSeeder from bot_data.service.server_repository_service import ServerRepositoryService -from bot_data.service.short_role_name_repository_service import ShortRoleNameRepositoryService -from bot_data.service.technician_config_repository_service import TechnicianConfigRepositoryService +from bot_data.service.short_role_name_repository_service import ( + ShortRoleNameRepositoryService, +) +from bot_data.service.steam_special_offer_repository_service import ( + SteamSpecialOfferRepositoryService, +) +from bot_data.service.technician_config_repository_service import ( + TechnicianConfigRepositoryService, +) from bot_data.service.technician_config_seeder import TechnicianConfigSeeder -from bot_data.service.user_game_ident_repository_service import UserGameIdentRepositoryService -from bot_data.service.user_joined_game_server_repository_service import UserJoinedGameServerRepositoryService +from bot_data.service.user_game_ident_repository_service import ( + UserGameIdentRepositoryService, +) +from bot_data.service.user_joined_game_server_repository_service import ( + UserJoinedGameServerRepositoryService, +) from bot_data.service.user_joined_server_repository_service import ( UserJoinedServerRepositoryService, ) @@ -57,7 +77,9 @@ from bot_data.service.user_message_count_per_hour_repository_service import ( UserMessageCountPerHourRepositoryService, ) from bot_data.service.user_repository_service import UserRepositoryService -from bot_data.service.user_warnings_repository_service import UserWarningsRepositoryService +from bot_data.service.user_warnings_repository_service import ( + UserWarningsRepositoryService, +) class DataModule(ModuleABC): @@ -92,6 +114,7 @@ class DataModule(ModuleABC): services.add_transient(TechnicianConfigRepositoryABC, TechnicianConfigRepositoryService) services.add_transient(ServerConfigRepositoryABC, ServerConfigRepositoryService) services.add_transient(ShortRoleNameRepositoryABC, ShortRoleNameRepositoryService) + services.add_transient(SteamSpecialOfferRepositoryABC, SteamSpecialOfferRepositoryService) services.add_transient(SeederService) services.add_transient(DataSeederABC, TechnicianConfigSeeder) diff --git a/kdb-bot/src/bot_data/db_context.py b/bot/src/bot_data/db_context.py similarity index 100% rename from kdb-bot/src/bot_data/db_context.py rename to bot/src/bot_data/db_context.py diff --git a/kdb-bot/src/bot_data/filtered_result.py b/bot/src/bot_data/filtered_result.py similarity index 100% rename from kdb-bot/src/bot_data/filtered_result.py rename to bot/src/bot_data/filtered_result.py diff --git a/kdb-bot/src/bot_data/migration/__init__.py b/bot/src/bot_data/migration/__init__.py similarity index 84% rename from kdb-bot/src/bot_data/migration/__init__.py rename to bot/src/bot_data/migration/__init__.py index 2999899d..fb9a7c01 100644 --- a/kdb-bot/src/bot_data/migration/__init__.py +++ b/bot/src/bot_data/migration/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_data.migration" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_data/migration/achievements_migration.py b/bot/src/bot_data/migration/achievements_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/achievements_migration.py rename to bot/src/bot_data/migration/achievements_migration.py diff --git a/kdb-bot/src/bot_data/migration/api_key_migration.py b/bot/src/bot_data/migration/api_key_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/api_key_migration.py rename to bot/src/bot_data/migration/api_key_migration.py diff --git a/kdb-bot/src/bot_data/migration/api_migration.py b/bot/src/bot_data/migration/api_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/api_migration.py rename to bot/src/bot_data/migration/api_migration.py diff --git a/kdb-bot/src/bot_data/migration/auto_role_fix1_migration.py b/bot/src/bot_data/migration/auto_role_fix1_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/auto_role_fix1_migration.py rename to bot/src/bot_data/migration/auto_role_fix1_migration.py diff --git a/kdb-bot/src/bot_data/migration/auto_role_migration.py b/bot/src/bot_data/migration/auto_role_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/auto_role_migration.py rename to bot/src/bot_data/migration/auto_role_migration.py diff --git a/bot/src/bot_data/migration/birthday_migration.py b/bot/src/bot_data/migration/birthday_migration.py new file mode 100644 index 00000000..607de4d3 --- /dev/null +++ b/bot/src/bot_data/migration/birthday_migration.py @@ -0,0 +1,84 @@ +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.migration_abc import MigrationABC +from bot_data.db_context import DBContext + + +class BirthdayMigration(MigrationABC): + name = "1.2.0_BirthdayMigration" + + def __init__(self, logger: DatabaseLogger, db: DBContext): + MigrationABC.__init__(self) + self._logger = logger + self._db = db + self._cursor = db.cursor + + def upgrade(self): + self._logger.debug(__name__, "Running upgrade") + + self._cursor.execute( + str( + f""" + ALTER TABLE Users + ADD Birthday DATE NULL AFTER MessageCount; + """ + ) + ) + + self._cursor.execute( + str( + f""" + ALTER TABLE UsersHistory + ADD Birthday DATE NULL AFTER MessageCount; + """ + ) + ) + self._exec(__file__, "users.sql") + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Server + ADD XpForBirthday BIGINT(20) NOT NULL DEFAULT 0 AFTER XpPerAchievement; + """ + ) + ) + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_ServerHistory + ADD XpForBirthday BIGINT(20) NOT NULL DEFAULT 0 AFTER XpPerAchievement; + """ + ) + ) + self._exec(__file__, "config/server.sql") + + def downgrade(self): + self._cursor.execute( + str( + f""" + ALTER TABLE Users DROP COLUMN Birthday; + """ + ) + ) + self._cursor.execute( + str( + f""" + ALTER TABLE UsersHistory DROP COLUMN Birthday; + """ + ) + ) + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Server DROP COLUMN XpForBirthday; + """ + ) + ) + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_ServerHistory DROP COLUMN XpForBirthday; + """ + ) + ) diff --git a/kdb-bot/src/bot_data/migration/config_feature_flags_migration.py b/bot/src/bot_data/migration/config_feature_flags_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/config_feature_flags_migration.py rename to bot/src/bot_data/migration/config_feature_flags_migration.py diff --git a/kdb-bot/src/bot_data/migration/config_migration.py b/bot/src/bot_data/migration/config_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/config_migration.py rename to bot/src/bot_data/migration/config_migration.py diff --git a/kdb-bot/src/bot_data/migration/db_history_migration.py b/bot/src/bot_data/migration/db_history_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_migration.py rename to bot/src/bot_data/migration/db_history_migration.py diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/api_keys.sql b/bot/src/bot_data/migration/db_history_scripts/api_keys.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/api_keys.sql rename to bot/src/bot_data/migration/db_history_scripts/api_keys.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/auth_user_users_relation.sql b/bot/src/bot_data/migration/db_history_scripts/auth_user_users_relation.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/auth_user_users_relation.sql rename to bot/src/bot_data/migration/db_history_scripts/auth_user_users_relation.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/auth_users.sql b/bot/src/bot_data/migration/db_history_scripts/auth_users.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/auth_users.sql rename to bot/src/bot_data/migration/db_history_scripts/auth_users.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/auto_role_rules.sql b/bot/src/bot_data/migration/db_history_scripts/auto_role_rules.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/auto_role_rules.sql rename to bot/src/bot_data/migration/db_history_scripts/auto_role_rules.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/auto_roles.sql b/bot/src/bot_data/migration/db_history_scripts/auto_roles.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/auto_roles.sql rename to bot/src/bot_data/migration/db_history_scripts/auto_roles.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/clients.sql b/bot/src/bot_data/migration/db_history_scripts/clients.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/clients.sql rename to bot/src/bot_data/migration/db_history_scripts/clients.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/config/server.sql b/bot/src/bot_data/migration/db_history_scripts/config/server.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/config/server.sql rename to bot/src/bot_data/migration/db_history_scripts/config/server.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/config/server_afk_channels.sql b/bot/src/bot_data/migration/db_history_scripts/config/server_afk_channels.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/config/server_afk_channels.sql rename to bot/src/bot_data/migration/db_history_scripts/config/server_afk_channels.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/config/server_team_roles.sql b/bot/src/bot_data/migration/db_history_scripts/config/server_team_roles.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/config/server_team_roles.sql rename to bot/src/bot_data/migration/db_history_scripts/config/server_team_roles.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/config/technician.sql b/bot/src/bot_data/migration/db_history_scripts/config/technician.sql similarity index 83% rename from kdb-bot/src/bot_data/migration/db_history_scripts/config/technician.sql rename to bot/src/bot_data/migration/db_history_scripts/config/technician.sql index 2256cbc8..3866f88f 100644 --- a/kdb-bot/src/bot_data/migration/db_history_scripts/config/technician.sql +++ b/bot/src/bot_data/migration/db_history_scripts/config/technician.sql @@ -5,6 +5,8 @@ CREATE TABLE IF NOT EXISTS `CFG_TechnicianHistory` `WaitForRestart` BIGINT NOT NULL DEFAULT 8, `WaitForShutdown` BIGINT NOT NULL DEFAULT 8, `CacheMaxMessages` BIGINT NOT NULL DEFAULT 1000000, + `MaxSteamOfferCount` BIGINT NOT NULL DEFAULT 250, + `Maintenance` BOOLEAN DEFAULT FALSE, `FeatureFlags` JSON NULL DEFAULT ('{}'), `Deleted` BOOL DEFAULT FALSE, `DateFrom` DATETIME(6) NOT NULL, @@ -23,6 +25,8 @@ BEGIN `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`, + `MaxSteamOfferCount`, + `Maintenance`, `FeatureFlags`, `DateFrom`, `DateTo`) @@ -31,6 +35,8 @@ BEGIN OLD.WaitForRestart, OLD.WaitForShutdown, OLD.CacheMaxMessages, + OLD.MaxSteamOfferCount, + OLD.Maintenance, OLD.FeatureFlags, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)); @@ -48,6 +54,8 @@ BEGIN `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`, + `MaxSteamOfferCount`, + `Maintenance`, `FeatureFlags`, `Deleted`, `DateFrom`, @@ -57,6 +65,8 @@ BEGIN OLD.WaitForRestart, OLD.WaitForShutdown, OLD.CacheMaxMessages, + OLD.MaxSteamOfferCount, + OLD.Maintenance, OLD.FeatureFlags, TRUE, OLD.LastModifiedAt, diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/config/technician_ids.sql b/bot/src/bot_data/migration/db_history_scripts/config/technician_ids.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/config/technician_ids.sql rename to bot/src/bot_data/migration/db_history_scripts/config/technician_ids.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/config/technician_ping_urls.sql b/bot/src/bot_data/migration/db_history_scripts/config/technician_ping_urls.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/config/technician_ping_urls.sql rename to bot/src/bot_data/migration/db_history_scripts/config/technician_ping_urls.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/game_servers.sql b/bot/src/bot_data/migration/db_history_scripts/game_servers.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/game_servers.sql rename to bot/src/bot_data/migration/db_history_scripts/game_servers.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/known_users.sql b/bot/src/bot_data/migration/db_history_scripts/known_users.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/known_users.sql rename to bot/src/bot_data/migration/db_history_scripts/known_users.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/levels.sql b/bot/src/bot_data/migration/db_history_scripts/levels.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/levels.sql rename to bot/src/bot_data/migration/db_history_scripts/levels.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/servers.sql b/bot/src/bot_data/migration/db_history_scripts/servers.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/servers.sql rename to bot/src/bot_data/migration/db_history_scripts/servers.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql b/bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql rename to bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/user_game_idents.sql b/bot/src/bot_data/migration/db_history_scripts/user_game_idents.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/user_game_idents.sql rename to bot/src/bot_data/migration/db_history_scripts/user_game_idents.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/user_joined_game_servers.sql b/bot/src/bot_data/migration/db_history_scripts/user_joined_game_servers.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/user_joined_game_servers.sql rename to bot/src/bot_data/migration/db_history_scripts/user_joined_game_servers.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/user_joined_servers.sql b/bot/src/bot_data/migration/db_history_scripts/user_joined_servers.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/user_joined_servers.sql rename to bot/src/bot_data/migration/db_history_scripts/user_joined_servers.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/user_joined_voice_channel.sql b/bot/src/bot_data/migration/db_history_scripts/user_joined_voice_channel.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/user_joined_voice_channel.sql rename to bot/src/bot_data/migration/db_history_scripts/user_joined_voice_channel.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/user_message_count_per_hour.sql b/bot/src/bot_data/migration/db_history_scripts/user_message_count_per_hour.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/user_message_count_per_hour.sql rename to bot/src/bot_data/migration/db_history_scripts/user_message_count_per_hour.sql diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/user_warnings.sql b/bot/src/bot_data/migration/db_history_scripts/user_warnings.sql similarity index 100% rename from kdb-bot/src/bot_data/migration/db_history_scripts/user_warnings.sql rename to bot/src/bot_data/migration/db_history_scripts/user_warnings.sql diff --git a/bot/src/bot_data/migration/db_history_scripts/users.sql b/bot/src/bot_data/migration/db_history_scripts/users.sql new file mode 100644 index 00000000..a91cf560 --- /dev/null +++ b/bot/src/bot_data/migration/db_history_scripts/users.sql @@ -0,0 +1,45 @@ +ALTER TABLE `Users` + CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6); + +ALTER TABLE `Users` + CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6); + +CREATE TABLE IF NOT EXISTS `UsersHistory` +( + `Id` BIGINT(20) NOT NULL, + `DiscordId` BIGINT(20) NOT NULL, + `XP` BIGINT(20) NOT NULL DEFAULT 0, + `ReactionCount` BIGINT(20) NOT NULL DEFAULT 0, + `MessageCount` BIGINT(20) NOT NULL DEFAULT 0, + `Birthday` DATE NULL, + `ServerId` BIGINT(20) DEFAULT NULL, + `Deleted` BOOL DEFAULT FALSE, + `DateFrom` DATETIME(6) NOT NULL, + `DateTo` DATETIME(6) NOT NULL +); + +DROP TRIGGER IF EXISTS `TR_UsersUpdate`; + +CREATE TRIGGER `TR_UsersUpdate` + AFTER UPDATE + ON `Users` + FOR EACH ROW +BEGIN + INSERT INTO `UsersHistory` (`Id`, `DiscordId`, `XP`, `ReactionCount`, `MessageCount`, `Birthday`, `ServerId`, + `DateFrom`, `DateTo`) + VALUES (OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ReactionCount, OLD.MessageCount, OLD.Birthday, OLD.ServerId, + OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)); +END; + +DROP TRIGGER IF EXISTS `TR_UsersDelete`; + +CREATE TRIGGER `TR_UsersDelete` + AFTER DELETE + ON `Users` + FOR EACH ROW +BEGIN + INSERT INTO `UsersHistory` (`Id`, `DiscordId`, `XP`, `ReactionCount`, `MessageCount`, `Birthday`, `ServerId`, + `Deleted`, `DateFrom`, `DateTo`) + VALUES (OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ReactionCount, OLD.MessageCount, OLD.Birthday, OLD.ServerId, TRUE, + OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)); +END; \ No newline at end of file diff --git a/kdb-bot/src/bot_data/migration/default_role_migration.py b/bot/src/bot_data/migration/default_role_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/default_role_migration.py rename to bot/src/bot_data/migration/default_role_migration.py diff --git a/kdb-bot/src/bot_data/migration/fix_updates_migration.py b/bot/src/bot_data/migration/fix_updates_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/fix_updates_migration.py rename to bot/src/bot_data/migration/fix_updates_migration.py diff --git a/bot/src/bot_data/migration/fix_user_history_migration.py b/bot/src/bot_data/migration/fix_user_history_migration.py new file mode 100644 index 00000000..b39ec429 --- /dev/null +++ b/bot/src/bot_data/migration/fix_user_history_migration.py @@ -0,0 +1,45 @@ +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.migration_abc import MigrationABC +from bot_data.db_context import DBContext + + +class FixUserHistoryMigration(MigrationABC): + name = "1.2.0_FixUserHistoryMigration" + + def __init__(self, logger: DatabaseLogger, db: DBContext): + MigrationABC.__init__(self) + self._logger = logger + self._db = db + self._cursor = db.cursor + + def upgrade(self): + self._logger.debug(__name__, "Running upgrade") + + # fix 1.1.0_AchievementsMigration + self._cursor.execute( + str( + f"""ALTER TABLE UsersHistory ADD COLUMN IF NOT EXISTS ReactionCount BIGINT NOT NULL DEFAULT 0 AFTER XP;""" + ) + ) + self._cursor.execute( + str( + f"""ALTER TABLE UsersHistory ADD COLUMN IF NOT EXISTS MessageCount BIGINT NOT NULL DEFAULT 0 AFTER ReactionCount;""" + ) + ) + self._exec(__file__, "users.sql") + + def downgrade(self): + self._cursor.execute( + str( + f""" + ALTER TABLE UsersHistory DROP COLUMN MessageCount; + """ + ) + ) + self._cursor.execute( + str( + f""" + ALTER TABLE UsersHistory DROP COLUMN ReactionCount; + """ + ) + ) diff --git a/kdb-bot/src/bot_data/migration/initial_migration.py b/bot/src/bot_data/migration/initial_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/initial_migration.py rename to bot/src/bot_data/migration/initial_migration.py diff --git a/kdb-bot/src/bot_data/migration/level_migration.py b/bot/src/bot_data/migration/level_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/level_migration.py rename to bot/src/bot_data/migration/level_migration.py diff --git a/bot/src/bot_data/migration/maintenance_mode_migration.py b/bot/src/bot_data/migration/maintenance_mode_migration.py new file mode 100644 index 00000000..467c8604 --- /dev/null +++ b/bot/src/bot_data/migration/maintenance_mode_migration.py @@ -0,0 +1,51 @@ +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.migration_abc import MigrationABC +from bot_data.db_context import DBContext + + +class MaintenanceModeMigration(MigrationABC): + name = "1.2.0_MaintenanceModeMigration" + + def __init__(self, logger: DatabaseLogger, db: DBContext): + MigrationABC.__init__(self) + self._logger = logger + self._db = db + self._cursor = db.cursor + + def upgrade(self): + self._logger.debug(__name__, "Running upgrade") + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Technician + ADD Maintenance BOOLEAN DEFAULT FALSE AFTER MaxSteamOfferCount; + """ + ) + ) + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_TechnicianHistory + ADD Maintenance BOOLEAN DEFAULT FALSE AFTER MaxSteamOfferCount; + """ + ) + ) + self._exec(__file__, "config/technician.sql") + + def downgrade(self): + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Technician DROP COLUMN Maintenance; + """ + ) + ) + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_TechnicianHistory DROP COLUMN Maintenance; + """ + ) + ) diff --git a/bot/src/bot_data/migration/max_steam_offer_count_migration.py b/bot/src/bot_data/migration/max_steam_offer_count_migration.py new file mode 100644 index 00000000..fe926c24 --- /dev/null +++ b/bot/src/bot_data/migration/max_steam_offer_count_migration.py @@ -0,0 +1,51 @@ +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.migration_abc import MigrationABC +from bot_data.db_context import DBContext + + +class MaxSteamOfferCountMigration(MigrationABC): + name = "1.2.0_MaxSteamOfferCountMigration" + + def __init__(self, logger: DatabaseLogger, db: DBContext): + MigrationABC.__init__(self) + self._logger = logger + self._db = db + self._cursor = db.cursor + + def upgrade(self): + self._logger.debug(__name__, "Running upgrade") + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Technician + ADD MaxSteamOfferCount BIGINT NOT NULL DEFAULT 250 AFTER CacheMaxMessages; + """ + ) + ) + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_TechnicianHistory + ADD MaxSteamOfferCount BIGINT NOT NULL DEFAULT 250 AFTER CacheMaxMessages; + """ + ) + ) + self._exec(__file__, "config/technician.sql") + + def downgrade(self): + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Technician DROP COLUMN MaxSteamOfferCount; + """ + ) + ) + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_TechnicianHistory DROP COLUMN MaxSteamOfferCount; + """ + ) + ) diff --git a/kdb-bot/src/bot_data/migration/remove_stats_migration.py b/bot/src/bot_data/migration/remove_stats_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/remove_stats_migration.py rename to bot/src/bot_data/migration/remove_stats_migration.py diff --git a/kdb-bot/src/bot_data/migration/short_role_name_migration.py b/bot/src/bot_data/migration/short_role_name_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/short_role_name_migration.py rename to bot/src/bot_data/migration/short_role_name_migration.py diff --git a/kdb-bot/src/bot_data/migration/short_role_name_only_highest_migration.py b/bot/src/bot_data/migration/short_role_name_only_highest_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/short_role_name_only_highest_migration.py rename to bot/src/bot_data/migration/short_role_name_only_highest_migration.py diff --git a/kdb-bot/src/bot_data/migration/stats_migration.py b/bot/src/bot_data/migration/stats_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/stats_migration.py rename to bot/src/bot_data/migration/stats_migration.py diff --git a/bot/src/bot_data/migration/steam_special_offer_migration.py b/bot/src/bot_data/migration/steam_special_offer_migration.py new file mode 100644 index 00000000..18813ae7 --- /dev/null +++ b/bot/src/bot_data/migration/steam_special_offer_migration.py @@ -0,0 +1,68 @@ +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.migration_abc import MigrationABC +from bot_data.db_context import DBContext + + +class SteamSpecialOfferMigration(MigrationABC): + name = "1.2.0_SteamSpecialOfferMigration" + + def __init__(self, logger: DatabaseLogger, db: DBContext): + MigrationABC.__init__(self) + self._logger = logger + self._db = db + self._cursor = db.cursor + + def upgrade(self): + self._logger.debug(__name__, "Running upgrade") + + self._cursor.execute( + str( + f""" + CREATE TABLE IF NOT EXISTS `SteamSpecialOffers` ( + `Id` BIGINT NOT NULL AUTO_INCREMENT, + `Game` VARCHAR(255) NOT NULL, + `OriginalPrice` FLOAT NOT NULL, + `DiscountPrice` FLOAT NOT NULL, + `DiscountPct` BIGINT NOT NULL, + `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6), + `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + PRIMARY KEY(`Id`) + ); + """ + ) + ) + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Server + ADD COLUMN IF NOT EXISTS GameOfferNotificationChatId BIGINT NULL AFTER ShortRoleNameSetOnlyHighest; + """ + ) + ) + + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_ServerHistory + ADD COLUMN IF NOT EXISTS GameOfferNotificationChatId BIGINT NULL AFTER ShortRoleNameSetOnlyHighest; + """ + ) + ) + + def downgrade(self): + self._cursor.execute("DROP TABLE `SteamSpecialOffers`;") + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_Server DROP COLUMN ShortRoleNameSetOnlyHighest; + """ + ) + ) + self._cursor.execute( + str( + f""" + ALTER TABLE CFG_ServerHistory DROP COLUMN ShortRoleNameSetOnlyHighest; + """ + ) + ) diff --git a/kdb-bot/src/bot_data/migration/user_joined_game_server_migration.py b/bot/src/bot_data/migration/user_joined_game_server_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/user_joined_game_server_migration.py rename to bot/src/bot_data/migration/user_joined_game_server_migration.py diff --git a/kdb-bot/src/bot_data/migration/user_message_count_per_hour_migration.py b/bot/src/bot_data/migration/user_message_count_per_hour_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/user_message_count_per_hour_migration.py rename to bot/src/bot_data/migration/user_message_count_per_hour_migration.py diff --git a/kdb-bot/src/bot_data/migration/user_warning_migration.py b/bot/src/bot_data/migration/user_warning_migration.py similarity index 100% rename from kdb-bot/src/bot_data/migration/user_warning_migration.py rename to bot/src/bot_data/migration/user_warning_migration.py diff --git a/kdb-bot/src/bot_data/model/__init__.py b/bot/src/bot_data/model/__init__.py similarity index 84% rename from kdb-bot/src/bot_data/model/__init__.py rename to bot/src/bot_data/model/__init__.py index c06c1f3e..fc71a463 100644 --- a/kdb-bot/src/bot_data/model/__init__.py +++ b/bot/src/bot_data/model/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_data.model" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_data/model/achievement.py b/bot/src/bot_data/model/achievement.py similarity index 100% rename from kdb-bot/src/bot_data/model/achievement.py rename to bot/src/bot_data/model/achievement.py diff --git a/kdb-bot/src/bot_data/model/achievement_history.py b/bot/src/bot_data/model/achievement_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/achievement_history.py rename to bot/src/bot_data/model/achievement_history.py diff --git a/kdb-bot/src/bot_data/model/api_key.py b/bot/src/bot_data/model/api_key.py similarity index 100% rename from kdb-bot/src/bot_data/model/api_key.py rename to bot/src/bot_data/model/api_key.py diff --git a/kdb-bot/src/bot_data/model/auth_role_enum.py b/bot/src/bot_data/model/auth_role_enum.py similarity index 100% rename from kdb-bot/src/bot_data/model/auth_role_enum.py rename to bot/src/bot_data/model/auth_role_enum.py diff --git a/kdb-bot/src/bot_data/model/auth_user.py b/bot/src/bot_data/model/auth_user.py similarity index 100% rename from kdb-bot/src/bot_data/model/auth_user.py rename to bot/src/bot_data/model/auth_user.py diff --git a/kdb-bot/src/bot_data/model/auth_user_users_relation.py b/bot/src/bot_data/model/auth_user_users_relation.py similarity index 100% rename from kdb-bot/src/bot_data/model/auth_user_users_relation.py rename to bot/src/bot_data/model/auth_user_users_relation.py diff --git a/kdb-bot/src/bot_data/model/auto_role.py b/bot/src/bot_data/model/auto_role.py similarity index 100% rename from kdb-bot/src/bot_data/model/auto_role.py rename to bot/src/bot_data/model/auto_role.py diff --git a/kdb-bot/src/bot_data/model/auto_role_history.py b/bot/src/bot_data/model/auto_role_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/auto_role_history.py rename to bot/src/bot_data/model/auto_role_history.py diff --git a/kdb-bot/src/bot_data/model/auto_role_rule.py b/bot/src/bot_data/model/auto_role_rule.py similarity index 100% rename from kdb-bot/src/bot_data/model/auto_role_rule.py rename to bot/src/bot_data/model/auto_role_rule.py diff --git a/kdb-bot/src/bot_data/model/auto_role_rule_history.py b/bot/src/bot_data/model/auto_role_rule_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/auto_role_rule_history.py rename to bot/src/bot_data/model/auto_role_rule_history.py diff --git a/kdb-bot/src/bot_data/model/client.py b/bot/src/bot_data/model/client.py similarity index 100% rename from kdb-bot/src/bot_data/model/client.py rename to bot/src/bot_data/model/client.py diff --git a/kdb-bot/src/bot_data/model/client_history.py b/bot/src/bot_data/model/client_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/client_history.py rename to bot/src/bot_data/model/client_history.py diff --git a/kdb-bot/src/bot_data/model/game_server.py b/bot/src/bot_data/model/game_server.py similarity index 100% rename from kdb-bot/src/bot_data/model/game_server.py rename to bot/src/bot_data/model/game_server.py diff --git a/kdb-bot/src/bot_data/model/known_user.py b/bot/src/bot_data/model/known_user.py similarity index 100% rename from kdb-bot/src/bot_data/model/known_user.py rename to bot/src/bot_data/model/known_user.py diff --git a/kdb-bot/src/bot_data/model/known_user_history.py b/bot/src/bot_data/model/known_user_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/known_user_history.py rename to bot/src/bot_data/model/known_user_history.py diff --git a/kdb-bot/src/bot_data/model/level.py b/bot/src/bot_data/model/level.py similarity index 100% rename from kdb-bot/src/bot_data/model/level.py rename to bot/src/bot_data/model/level.py diff --git a/kdb-bot/src/bot_data/model/level_history.py b/bot/src/bot_data/model/level_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/level_history.py rename to bot/src/bot_data/model/level_history.py diff --git a/kdb-bot/src/bot_data/model/migration_history.py b/bot/src/bot_data/model/migration_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/migration_history.py rename to bot/src/bot_data/model/migration_history.py diff --git a/kdb-bot/src/bot_data/model/server.py b/bot/src/bot_data/model/server.py similarity index 100% rename from kdb-bot/src/bot_data/model/server.py rename to bot/src/bot_data/model/server.py diff --git a/kdb-bot/src/bot_data/model/server_afk_channel_ids_config.py b/bot/src/bot_data/model/server_afk_channel_ids_config.py similarity index 100% rename from kdb-bot/src/bot_data/model/server_afk_channel_ids_config.py rename to bot/src/bot_data/model/server_afk_channel_ids_config.py diff --git a/kdb-bot/src/bot_data/model/server_config.py b/bot/src/bot_data/model/server_config.py similarity index 91% rename from kdb-bot/src/bot_data/model/server_config.py rename to bot/src/bot_data/model/server_config.py index 8a36ac6f..cf220355 100644 --- a/kdb-bot/src/bot_data/model/server_config.py +++ b/bot/src/bot_data/model/server_config.py @@ -24,12 +24,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): xp_per_ontime_hour: int, xp_per_event_participation: int, xp_per_achievement: int, + xp_for_birthday: int, afk_command_channel_id: int, help_voice_channel_id: int, team_channel_id: int, login_message_channel_id: int, default_role_id: Optional[int], short_role_name_only_set_highest_role: bool, + game_offer_notification_chat_id: int, feature_flags: dict[FeatureFlagsEnum], server: Server, afk_channel_ids: List[int], @@ -48,12 +50,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): self._xp_per_ontime_hour = xp_per_ontime_hour self._xp_per_event_participation = xp_per_event_participation self._xp_per_achievement = xp_per_achievement + self._xp_for_birthday = xp_for_birthday self._afk_command_channel_id = afk_command_channel_id self._help_voice_channel_id = help_voice_channel_id self._team_channel_id = team_channel_id self._login_message_channel_id = login_message_channel_id self._default_role_id = default_role_id self._short_role_name_only_set_highest_role = short_role_name_only_set_highest_role + self._game_offer_notification_chat_id = game_offer_notification_chat_id self._feature_flags = feature_flags self._server = server @@ -76,12 +80,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): 10, 10, 10, + 10, guild.system_channel.id, guild.system_channel.id, guild.system_channel.id, guild.system_channel.id, None, False, + guild.system_channel.id, {}, server, List(int), @@ -164,6 +170,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): def xp_per_achievement(self, value: int): self._xp_per_achievement = value + @property + def xp_for_birthday(self) -> int: + return self._xp_for_birthday + + @xp_for_birthday.setter + def xp_for_birthday(self, value: int): + self._xp_for_birthday = value + @property def afk_command_channel_id(self) -> int: return self._afk_command_channel_id @@ -212,6 +226,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): def short_role_name_only_set_highest_role(self, value: bool): self._short_role_name_only_set_highest_role = value + @property + def game_offer_notification_chat_id(self) -> int: + return self._game_offer_notification_chat_id + + @game_offer_notification_chat_id.setter + def game_offer_notification_chat_id(self, value: int): + self._game_offer_notification_chat_id = value + @property def feature_flags(self) -> dict[FeatureFlagsEnum]: return self._feature_flags @@ -280,12 +302,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): `XpPerOntimeHour`, `XpPerEventParticipation`, `XpPerAchievement`, + `XpForBirthday`, `AFKCommandChannelId`, `HelpVoiceChannelId`, `TeamChannelId`, `LoginMessageChannelId`, `DefaultRoleId`, `ShortRoleNameSetOnlyHighest`, + `GameOfferNotificationChatId`, `FeatureFlags`, `ServerId` ) VALUES ( @@ -298,12 +322,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): {self._xp_per_ontime_hour}, {self._xp_per_event_participation}, {self._xp_per_achievement}, + '{self._xp_for_birthday}', {self._afk_command_channel_id}, {self._help_voice_channel_id}, {self._team_channel_id}, {self._login_message_channel_id}, {"NULL" if self._default_role_id is None else self._default_role_id}, {self._short_role_name_only_set_highest_role}, + {self._game_offer_notification_chat_id}, '{json.dumps(self._feature_flags)}', {self._server.id} ); @@ -324,12 +350,14 @@ class ServerConfig(TableABC, ConfigurationModelABC): `XpPerOntimeHour` = {self._xp_per_ontime_hour}, `XpPerEventParticipation` = {self._xp_per_event_participation}, `XpPerAchievement` = {self._xp_per_achievement}, + `XpForBirthday` = {self._xp_for_birthday}, `AFKCommandChannelId` = {self._afk_command_channel_id}, `HelpVoiceChannelId` = {self._help_voice_channel_id}, `TeamChannelId` = {self._team_channel_id}, `LoginMessageChannelId` = {self._login_message_channel_id}, `DefaultRoleId` = {"NULL" if self._default_role_id is None else self._default_role_id}, `ShortRoleNameSetOnlyHighest` = {self._short_role_name_only_set_highest_role}, + `GameOfferNotificationChatId` = {self._game_offer_notification_chat_id}, `FeatureFlags` = '{json.dumps(self._feature_flags)}', `ServerId` = {self._server.id} WHERE `Id` = {self._id}; diff --git a/kdb-bot/src/bot_data/model/server_config_history.py b/bot/src/bot_data/model/server_config_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/server_config_history.py rename to bot/src/bot_data/model/server_config_history.py diff --git a/kdb-bot/src/bot_data/model/server_history.py b/bot/src/bot_data/model/server_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/server_history.py rename to bot/src/bot_data/model/server_history.py diff --git a/kdb-bot/src/bot_data/model/server_team_role_ids_config.py b/bot/src/bot_data/model/server_team_role_ids_config.py similarity index 100% rename from kdb-bot/src/bot_data/model/server_team_role_ids_config.py rename to bot/src/bot_data/model/server_team_role_ids_config.py diff --git a/kdb-bot/src/bot_data/model/short_role_name.py b/bot/src/bot_data/model/short_role_name.py similarity index 100% rename from kdb-bot/src/bot_data/model/short_role_name.py rename to bot/src/bot_data/model/short_role_name.py diff --git a/kdb-bot/src/bot_data/model/short_role_name_history.py b/bot/src/bot_data/model/short_role_name_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/short_role_name_history.py rename to bot/src/bot_data/model/short_role_name_history.py diff --git a/kdb-bot/src/bot_data/model/short_role_name_position_enum.py b/bot/src/bot_data/model/short_role_name_position_enum.py similarity index 100% rename from kdb-bot/src/bot_data/model/short_role_name_position_enum.py rename to bot/src/bot_data/model/short_role_name_position_enum.py diff --git a/bot/src/bot_data/model/steam_special_offer.py b/bot/src/bot_data/model/steam_special_offer.py new file mode 100644 index 00000000..76301dc4 --- /dev/null +++ b/bot/src/bot_data/model/steam_special_offer.py @@ -0,0 +1,115 @@ +from datetime import datetime + +from cpl_core.database import TableABC + + +class SteamSpecialOffer(TableABC): + def __init__( + self, + name: str, + original_price: float, + discount_price: float, + discount_pct: int, + created_at: datetime = None, + modified_at: datetime = None, + id=0, + ): + self._id = id + self._name = name + self._original_price = original_price + self._discount_price = discount_price + self._discount_pct = discount_pct + + TableABC.__init__(self) + self._created_at = created_at if created_at is not None else self._created_at + self._modified_at = modified_at if modified_at is not None else self._modified_at + + @property + def id(self) -> int: + return self._id + + @property + def name(self) -> str: + return self._name + + @name.setter + def name(self, value: str): + self._name = value + + @property + def original_price(self) -> float: + return self._original_price + + @original_price.setter + def original_price(self, value: float): + self._original_price = value + + @property + def discount_price(self) -> float: + return self._discount_price + + @discount_price.setter + def discount_price(self, value: float): + self._discount_price = value + + @property + def discount_pct(self) -> int: + return self._discount_pct + + @discount_pct.setter + def discount_pct(self, value: int): + self._discount_pct = value + + @staticmethod + def get_select_all_string() -> str: + return str( + f""" + SELECT * FROM `SteamSpecialOffers`; + """ + ) + + @staticmethod + def get_select_by_name_string(name: str) -> str: + return str( + f""" + SELECT * FROM `SteamSpecialOffers` + WHERE `Game` = '{name}'; + """ + ) + + @property + def insert_string(self) -> str: + return str( + f""" + INSERT INTO `SteamSpecialOffers` ( + `Game`, `OriginalPrice`, `DiscountPrice`, `DiscountPct` + ) VALUES ( + '{self._name}', + {self._original_price}, + {self._discount_price}, + {self._discount_pct} + ); + """ + ) + + @property + def udpate_string(self) -> str: + return str( + f""" + UPDATE `SteamSpecialOffers` + SET `Game` = '{self._name}', + `OriginalPrice` = {self._original_price}, + `DiscountPrice` = {self._discount_price}, + `DiscountPct` = {self._discount_pct} + WHERE `Id` = {self._id}; + """ + ) + + @property + def delete_string(self) -> str: + return str( + f""" + DELETE FROM `SteamSpecialOffers` + WHERE `Id` = {self._id}; + """ + ) diff --git a/kdb-bot/src/bot_data/model/team_member_type_enum.py b/bot/src/bot_data/model/team_member_type_enum.py similarity index 100% rename from kdb-bot/src/bot_data/model/team_member_type_enum.py rename to bot/src/bot_data/model/team_member_type_enum.py diff --git a/kdb-bot/src/bot_data/model/technician_config.py b/bot/src/bot_data/model/technician_config.py similarity index 85% rename from kdb-bot/src/bot_data/model/technician_config.py rename to bot/src/bot_data/model/technician_config.py index 1390f4b8..e3c4f5f3 100644 --- a/kdb-bot/src/bot_data/model/technician_config.py +++ b/bot/src/bot_data/model/technician_config.py @@ -15,6 +15,8 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): wait_for_restart: int, wait_for_shutdown: int, cache_max_messages: int, + max_steam_offer_count: int, + maintenance: bool, feature_flags: dict[FeatureFlagsEnum], technician_ids: List[int], ping_urls: List[str], @@ -27,6 +29,9 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): self._wait_for_restart = wait_for_restart self._wait_for_shutdown = wait_for_shutdown self._cache_max_messages = cache_max_messages + self._max_steam_offer_count = max_steam_offer_count + self._maintenance = maintenance + self._feature_flags = feature_flags self._technician_ids = technician_ids self._ping_urls = ping_urls @@ -71,6 +76,14 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): def cache_max_messages(self, value: int): self._cache_max_messages = value + @property + def max_steam_offer_count(self) -> int: + return self._max_steam_offer_count + + @max_steam_offer_count.setter + def max_steam_offer_count(self, value: int): + self._max_steam_offer_count = value + @property def feature_flags(self) -> dict[FeatureFlagsEnum]: return self._feature_flags @@ -95,6 +108,14 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): def ping_urls(self, value: List[str]): self._ping_urls = value + @property + def maintenance(self) -> bool: + return self._maintenance + + @maintenance.setter + def maintenance(self, value: bool): + self._maintenance = value + @staticmethod def get_select_all_string() -> str: return str( @@ -117,12 +138,13 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): return str( f""" INSERT INTO `CFG_Technician` ( - `HelpCommandReferenceUrl`, `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`, `FeatureFlags` + `HelpCommandReferenceUrl`, `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`, `MaxSteamOfferCount`, `FeatureFlags` ) VALUES ( '{self._help_command_reference_url}', {self._wait_for_restart}, {self._wait_for_shutdown}, {self._cache_max_messages}, + {self._max_steam_offer_count}, '{json.dumps(self._feature_flags)}' ); """ @@ -137,6 +159,7 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): `WaitForRestart` = {self._wait_for_restart}, `WaitForShutdown` = {self._wait_for_shutdown}, `CacheMaxMessages` = {self._cache_max_messages}, + `MaxSteamOfferCount` = {self._max_steam_offer_count}, `FeatureFlags` = '{json.dumps(self._feature_flags)}' WHERE `Id` = {self._id}; """ diff --git a/kdb-bot/src/bot_data/model/technician_config_history.py b/bot/src/bot_data/model/technician_config_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/technician_config_history.py rename to bot/src/bot_data/model/technician_config_history.py diff --git a/kdb-bot/src/bot_data/model/technician_id_config.py b/bot/src/bot_data/model/technician_id_config.py similarity index 100% rename from kdb-bot/src/bot_data/model/technician_id_config.py rename to bot/src/bot_data/model/technician_id_config.py diff --git a/kdb-bot/src/bot_data/model/technician_id_config_history.py b/bot/src/bot_data/model/technician_id_config_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/technician_id_config_history.py rename to bot/src/bot_data/model/technician_id_config_history.py diff --git a/kdb-bot/src/bot_data/model/technician_ping_url_config.py b/bot/src/bot_data/model/technician_ping_url_config.py similarity index 100% rename from kdb-bot/src/bot_data/model/technician_ping_url_config.py rename to bot/src/bot_data/model/technician_ping_url_config.py diff --git a/kdb-bot/src/bot_data/model/technician_ping_url_config_history.py b/bot/src/bot_data/model/technician_ping_url_config_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/technician_ping_url_config_history.py rename to bot/src/bot_data/model/technician_ping_url_config_history.py diff --git a/kdb-bot/src/bot_data/model/user.py b/bot/src/bot_data/model/user.py similarity index 89% rename from kdb-bot/src/bot_data/model/user.py rename to bot/src/bot_data/model/user.py index 57e1cc67..c5766eb6 100644 --- a/kdb-bot/src/bot_data/model/user.py +++ b/bot/src/bot_data/model/user.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, date from typing import Optional from cpl_core.database import TableABC @@ -17,6 +17,7 @@ class User(TableABC): xp: int, reaction_count: int, message_count: int, + birthday: Optional[date], server: Optional[Server], created_at: datetime = None, modified_at: datetime = None, @@ -27,6 +28,7 @@ class User(TableABC): self._xp = xp self._reaction_count = reaction_count self._message_count = message_count + self._birthday = birthday self._server = server TableABC.__init__(self) @@ -79,6 +81,14 @@ class User(TableABC): def reaction_count(self, value: int): self._reaction_count = value + @property + def birthday(self) -> Optional[datetime]: + return self._birthday + + @birthday.setter + def birthday(self, value: Optional[datetime]): + self._birthday = value + @property @ServiceProviderABC.inject def ontime(self, services: ServiceProviderABC) -> float: @@ -105,7 +115,9 @@ class User(TableABC): self, services: ServiceProviderABC, ) -> bool: - from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC + from bot_data.abc.user_joined_server_repository_abc import ( + UserJoinedServerRepositoryABC, + ) ujs: UserJoinedServerRepositoryABC = services.get_service(UserJoinedServerRepositoryABC) return ujs.find_active_user_joined_server_by_user_id(self.id) is None @@ -116,7 +128,9 @@ class User(TableABC): self, services: ServiceProviderABC, ) -> List["UserGameIdent"]: - from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC + from bot_data.abc.user_game_ident_repository_abc import ( + UserGameIdentRepositoryABC, + ) game_idents_repo: UserGameIdentRepositoryABC = services.get_service(UserGameIdentRepositoryABC) return game_idents_repo.get_user_game_idents_by_user_id(self.id) @@ -171,12 +185,13 @@ class User(TableABC): return str( f""" INSERT INTO `Users` ( - `DiscordId`, `XP`, `MessageCount`, `ReactionCount`, `ServerId` + `DiscordId`, `XP`, `MessageCount`, `ReactionCount`, `Birthday`, `ServerId` ) VALUES ( {self._discord_id}, {self._xp}, {self._message_count}, {self._reaction_count}, + {"NULL" if self._birthday is None else f"'{self._birthday}'"}, {self._server.id} ); """ @@ -189,7 +204,8 @@ class User(TableABC): UPDATE `Users` SET `XP` = {self._xp}, `MessageCount` = {self._message_count}, - `ReactionCount` = {self._reaction_count} + `ReactionCount` = {self._reaction_count}, + `Birthday` = {"NULL" if self._birthday is None else f"'{self._birthday}'"} WHERE `UserId` = {self._user_id}; """ ) diff --git a/kdb-bot/src/bot_data/model/user_game_ident.py b/bot/src/bot_data/model/user_game_ident.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_game_ident.py rename to bot/src/bot_data/model/user_game_ident.py diff --git a/kdb-bot/src/bot_data/model/user_got_achievement.py b/bot/src/bot_data/model/user_got_achievement.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_got_achievement.py rename to bot/src/bot_data/model/user_got_achievement.py diff --git a/kdb-bot/src/bot_data/model/user_history.py b/bot/src/bot_data/model/user_history.py similarity index 94% rename from kdb-bot/src/bot_data/model/user_history.py rename to bot/src/bot_data/model/user_history.py index 2bf39954..357c854a 100644 --- a/kdb-bot/src/bot_data/model/user_history.py +++ b/bot/src/bot_data/model/user_history.py @@ -60,7 +60,9 @@ class UserHistory(HistoryTableABC): self, services: ServiceProviderABC, ) -> bool: - from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC + from bot_data.abc.user_joined_server_repository_abc import ( + UserJoinedServerRepositoryABC, + ) ujs: UserJoinedServerRepositoryABC = services.get_service(UserJoinedServerRepositoryABC) return ujs.find_active_user_joined_server_by_user_id(self.id) is None @@ -71,7 +73,9 @@ class UserHistory(HistoryTableABC): self, services: ServiceProviderABC, ) -> List["UserGameIdent"]: - from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC + from bot_data.abc.user_game_ident_repository_abc import ( + UserGameIdentRepositoryABC, + ) game_idents_repo: UserGameIdentRepositoryABC = services.get_service(UserGameIdentRepositoryABC) return game_idents_repo.get_user_game_idents_by_user_id(self.id) diff --git a/kdb-bot/src/bot_data/model/user_joined_game_server.py b/bot/src/bot_data/model/user_joined_game_server.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_joined_game_server.py rename to bot/src/bot_data/model/user_joined_game_server.py diff --git a/kdb-bot/src/bot_data/model/user_joined_game_server_history.py b/bot/src/bot_data/model/user_joined_game_server_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_joined_game_server_history.py rename to bot/src/bot_data/model/user_joined_game_server_history.py diff --git a/kdb-bot/src/bot_data/model/user_joined_server.py b/bot/src/bot_data/model/user_joined_server.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_joined_server.py rename to bot/src/bot_data/model/user_joined_server.py diff --git a/kdb-bot/src/bot_data/model/user_joined_server_history.py b/bot/src/bot_data/model/user_joined_server_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_joined_server_history.py rename to bot/src/bot_data/model/user_joined_server_history.py diff --git a/kdb-bot/src/bot_data/model/user_joined_voice_channel.py b/bot/src/bot_data/model/user_joined_voice_channel.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_joined_voice_channel.py rename to bot/src/bot_data/model/user_joined_voice_channel.py diff --git a/kdb-bot/src/bot_data/model/user_joined_voice_channel_history.py b/bot/src/bot_data/model/user_joined_voice_channel_history.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_joined_voice_channel_history.py rename to bot/src/bot_data/model/user_joined_voice_channel_history.py diff --git a/kdb-bot/src/bot_data/model/user_message_count_per_hour.py b/bot/src/bot_data/model/user_message_count_per_hour.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_message_count_per_hour.py rename to bot/src/bot_data/model/user_message_count_per_hour.py diff --git a/kdb-bot/src/bot_data/model/user_role_enum.py b/bot/src/bot_data/model/user_role_enum.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_role_enum.py rename to bot/src/bot_data/model/user_role_enum.py diff --git a/kdb-bot/src/bot_data/model/user_warnings.py b/bot/src/bot_data/model/user_warnings.py similarity index 100% rename from kdb-bot/src/bot_data/model/user_warnings.py rename to bot/src/bot_data/model/user_warnings.py diff --git a/bot/src/bot_data/model/user_warnings_history.py b/bot/src/bot_data/model/user_warnings_history.py new file mode 100644 index 00000000..a0ddef24 --- /dev/null +++ b/bot/src/bot_data/model/user_warnings_history.py @@ -0,0 +1,43 @@ +from typing import Optional + +from bot_data.abc.history_table_abc import HistoryTableABC + + +# had to name it UserWarnings instead of UserWarning because UserWarning is a builtin class +class UserWarningsHistory(HistoryTableABC): + def __init__( + self, + description: str, + user: int, + author: Optional[int], + deleted: bool, + date_from: str, + date_to: str, + id=0, + ): + HistoryTableABC.__init__(self) + + self._id = id + self._description = description + self._user = user + self._author = author + + self._deleted = deleted + self._date_from = date_from + self._date_to = date_to + + @property + def id(self) -> int: + return self._id + + @property + def description(self) -> str: + return self._description + + @property + def user(self) -> int: + return self._user + + @property + def author(self) -> Optional[int]: + return self._author diff --git a/kdb-bot/src/bot_data/service/__init__.py b/bot/src/bot_data/service/__init__.py similarity index 84% rename from kdb-bot/src/bot_data/service/__init__.py rename to bot/src/bot_data/service/__init__.py index da13a82b..d393f1f1 100644 --- a/kdb-bot/src/bot_data/service/__init__.py +++ b/bot/src/bot_data/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_data.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_data/service/achievements_repository_service.py b/bot/src/bot_data/service/achievements_repository_service.py similarity index 92% rename from kdb-bot/src/bot_data/service/achievements_repository_service.py rename to bot/src/bot_data/service/achievements_repository_service.py index b848fb5a..d8923db5 100644 --- a/kdb-bot/src/bot_data/service/achievements_repository_service.py +++ b/bot/src/bot_data/service/achievements_repository_service.py @@ -65,7 +65,10 @@ class AchievementRepositoryService(AchievementRepositoryABC): def get_achievements_by_server_id(self, server_id: int) -> List[Achievement]: achievements = List(Achievement) - self._logger.trace(__name__, f"Send SQL command: {Achievement.get_select_by_server_id_string(server_id)}") + self._logger.trace( + __name__, + 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]}") @@ -76,7 +79,10 @@ class AchievementRepositoryService(AchievementRepositoryABC): def get_achievements_by_user_id(self, user_id: int) -> List[Achievement]: achievements = List(Achievement) achievements_joins = List(UserGotAchievement) - self._logger.trace(__name__, f"Send SQL command: {UserGotAchievement.get_select_by_user_id_string(user_id)}") + self._logger.trace( + __name__, + 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]}") @@ -93,7 +99,8 @@ class AchievementRepositoryService(AchievementRepositoryABC): def get_user_got_achievements_by_achievement_id(self, achievement_id: int) -> List[Achievement]: achievements_joins = List(UserGotAchievement) self._logger.trace( - __name__, f"Send SQL command: {UserGotAchievement.get_select_by_achievement_id_string(achievement_id)}" + __name__, + 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: diff --git a/kdb-bot/src/bot_data/service/api_key_repository_service.py b/bot/src/bot_data/service/api_key_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/api_key_repository_service.py rename to bot/src/bot_data/service/api_key_repository_service.py diff --git a/kdb-bot/src/bot_data/service/auth_user_repository_service.py b/bot/src/bot_data/service/auth_user_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/auth_user_repository_service.py rename to bot/src/bot_data/service/auth_user_repository_service.py diff --git a/kdb-bot/src/bot_data/service/auto_role_repository_service.py b/bot/src/bot_data/service/auto_role_repository_service.py similarity index 74% rename from kdb-bot/src/bot_data/service/auto_role_repository_service.py rename to bot/src/bot_data/service/auto_role_repository_service.py index d1599341..bf0d781a 100644 --- a/kdb-bot/src/bot_data/service/auto_role_repository_service.py +++ b/bot/src/bot_data/service/auto_role_repository_service.py @@ -11,7 +11,12 @@ from bot_data.model.auto_role_rule import AutoRoleRule class AutoRoleRepositoryService(AutoRoleRepositoryABC): - def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + def __init__( + self, + logger: DatabaseLogger, + db_context: DatabaseContextABC, + servers: ServerRepositoryABC, + ): self._logger = logger self._context = db_context self._servers = servers @@ -25,7 +30,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): 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] + self._servers.get_server_by_id(result[1]), + result[2], + result[3], + result[4], + result[5], + id=result[0], ) ) @@ -35,7 +45,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): 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( - self._servers.get_server_by_id(result[1]), result[2], result[3], result[4], result[5], id=result[0] + self._servers.get_server_by_id(result[1]), + result[2], + result[3], + result[4], + result[5], + id=result[0], ) def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]: @@ -47,7 +62,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): result = result[0] return AutoRole( - self._servers.get_server_by_id(result[1]), result[2], result[3], result[4], result[5], id=result[0] + 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]: @@ -57,7 +77,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): 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] + self._servers.get_server_by_id(result[1]), + result[2], + result[3], + result[4], + result[5], + id=result[0], ) ) @@ -70,7 +95,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): ) 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] + 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]: @@ -85,7 +115,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): result = result[0] return AutoRole( - self._servers.get_server_by_id(result[1]), result[2], result[3], result[4], result[5], id=result[0] + 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): @@ -107,7 +142,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): 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] + self.get_auto_role_by_id(result[1]), + result[2], + result[3], + result[4], + result[5], + id=result[0], ) ) @@ -117,7 +157,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): 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( - self.get_auto_role_by_id(result[1]), result[2], result[3], result[4], result[5], id=result[0] + self.get_auto_role_by_id(result[1]), + result[2], + result[3], + result[4], + result[5], + id=result[0], ) def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]: @@ -130,7 +175,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): 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] + self.get_auto_role_by_id(result[1]), + result[2], + result[3], + result[4], + result[5], + id=result[0], ) ) diff --git a/kdb-bot/src/bot_data/service/cache_service.py b/bot/src/bot_data/service/cache_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/cache_service.py rename to bot/src/bot_data/service/cache_service.py diff --git a/kdb-bot/src/bot_data/service/client_repository_service.py b/bot/src/bot_data/service/client_repository_service.py similarity index 98% rename from kdb-bot/src/bot_data/service/client_repository_service.py rename to bot/src/bot_data/service/client_repository_service.py index 587569a0..e3d08ad3 100644 --- a/kdb-bot/src/bot_data/service/client_repository_service.py +++ b/bot/src/bot_data/service/client_repository_service.py @@ -64,7 +64,10 @@ class ClientRepositoryService(ClientRepositoryABC): def get_clients_by_server_id(self, server_id: int) -> List[Client]: clients = List(Client) - self._logger.trace(__name__, f"Send SQL command: {Client.get_select_by_server_id_string(server_id)}") + self._logger.trace( + __name__, + 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( diff --git a/kdb-bot/src/bot_data/service/game_server_repository_service.py b/bot/src/bot_data/service/game_server_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/game_server_repository_service.py rename to bot/src/bot_data/service/game_server_repository_service.py diff --git a/kdb-bot/src/bot_data/service/known_user_repository_service.py b/bot/src/bot_data/service/known_user_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/known_user_repository_service.py rename to bot/src/bot_data/service/known_user_repository_service.py diff --git a/kdb-bot/src/bot_data/service/level_repository_service.py b/bot/src/bot_data/service/level_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/level_repository_service.py rename to bot/src/bot_data/service/level_repository_service.py diff --git a/kdb-bot/src/bot_data/service/migration_service.py b/bot/src/bot_data/service/migration_service.py similarity index 97% rename from kdb-bot/src/bot_data/service/migration_service.py rename to bot/src/bot_data/service/migration_service.py index dc6436a7..ab347283 100644 --- a/kdb-bot/src/bot_data/service/migration_service.py +++ b/bot/src/bot_data/service/migration_service.py @@ -21,7 +21,7 @@ class MigrationService: self._cursor = db.cursor self._migrations: List[MigrationABC] = ( - List(type, MigrationABC.__subclasses__()).order_by(lambda x: x.name).order_by(lambda x: x.prio) + List(type, MigrationABC.__subclasses__()).order_by(lambda x: x.name.split("_")[0]).then_by(lambda x: x.prio) ) def migrate(self): diff --git a/kdb-bot/src/bot_data/service/seeder_service.py b/bot/src/bot_data/service/seeder_service.py similarity index 91% rename from kdb-bot/src/bot_data/service/seeder_service.py rename to bot/src/bot_data/service/seeder_service.py index feada479..69982c09 100644 --- a/kdb-bot/src/bot_data/service/seeder_service.py +++ b/bot/src/bot_data/service/seeder_service.py @@ -19,7 +19,7 @@ class SeederService: async def seed(self): self._logger.info(__name__, f"Seed data") - for seeder in self._services.get_services(list[DataSeederABC]): + for seeder in self._services.get_services(DataSeederABC): seeder: DataSeederABC = seeder self._logger.debug(__name__, f"Starting seeder {type(seeder).__name__}") await seeder.seed() diff --git a/kdb-bot/src/bot_data/service/server_config_repository_service.py b/bot/src/bot_data/service/server_config_repository_service.py similarity index 80% rename from kdb-bot/src/bot_data/service/server_config_repository_service.py rename to bot/src/bot_data/service/server_config_repository_service.py index 4e5d3dcd..45d1aeaa 100644 --- a/kdb-bot/src/bot_data/service/server_config_repository_service.py +++ b/bot/src/bot_data/service/server_config_repository_service.py @@ -13,7 +13,12 @@ from bot_data.model.team_member_type_enum import TeamMemberTypeEnum class ServerConfigRepositoryService(ServerConfigRepositoryABC): - def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + def __init__( + self, + logger: DatabaseLogger, + db_context: DatabaseContextABC, + servers: ServerRepositoryABC, + ): ServerConfigRepositoryABC.__init__(self) self._logger = logger @@ -23,14 +28,20 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC): def _get_team_role_ids(self, server_id: int) -> List[ServerTeamRoleIdsConfig]: ids = List(ServerTeamRoleIdsConfig) self._logger.trace( - __name__, f"Send SQL command: {ServerTeamRoleIdsConfig.get_select_by_server_id_string(server_id)}" + __name__, + 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: self._logger.trace(__name__, f"Got ServerTeamRoleIdsConfig with id {result[0]}") ids.append( ServerTeamRoleIdsConfig( - result[1], TeamMemberTypeEnum(result[2]), result[3], result[4], result[5], id=result[0] + result[1], + TeamMemberTypeEnum(result[2]), + result[3], + result[4], + result[5], + id=result[0], ) ) @@ -66,29 +77,40 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC): result[13], result[14], result[15], - json.loads(result[16]), - self._servers.get_server_by_id(result[17]), - self._get_afk_channel_ids(result[17]), - self._get_team_role_ids(result[17]), - result[18], - result[19], + result[16], + result[17], + json.loads(result[18]), + self._servers.get_server_by_id(result[19]), + self._get_afk_channel_ids(result[19]), + self._get_team_role_ids(result[19]), + result[20], + result[21], id=result[0], ) def does_server_config_exists(self, server_id: int) -> bool: - self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_server_id_string(server_id)}") + self._logger.trace( + __name__, + 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)) return len(result) > 0 def get_server_config_by_server(self, server_id: int) -> ServerConfig: - self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_server_id_string(server_id)}") + self._logger.trace( + __name__, + 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(result) def get_server_config_by_id(self, config_id: int) -> ServerConfig: - self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_id_string(config_id)}") + self._logger.trace( + __name__, + 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(result) diff --git a/kdb-bot/src/bot_data/service/server_config_seeder.py b/bot/src/bot_data/service/server_config_seeder.py similarity index 100% rename from kdb-bot/src/bot_data/service/server_config_seeder.py rename to bot/src/bot_data/service/server_config_seeder.py diff --git a/kdb-bot/src/bot_data/service/server_repository_service.py b/bot/src/bot_data/service/server_repository_service.py similarity index 96% rename from kdb-bot/src/bot_data/service/server_repository_service.py rename to bot/src/bot_data/service/server_repository_service.py index 924cc036..5817d7dc 100644 --- a/kdb-bot/src/bot_data/service/server_repository_service.py +++ b/bot/src/bot_data/service/server_repository_service.py @@ -12,7 +12,12 @@ from bot_data.service.cache_service import CacheService class ServerRepositoryService(ServerRepositoryABC): - def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, cache: CacheService): + def __init__( + self, + logger: DatabaseLogger, + db_context: DatabaseContextABC, + cache: CacheService, + ): self._logger = logger self._context = db_context self._cache = cache diff --git a/kdb-bot/src/bot_data/service/short_role_name_repository_service.py b/bot/src/bot_data/service/short_role_name_repository_service.py similarity index 96% rename from kdb-bot/src/bot_data/service/short_role_name_repository_service.py rename to bot/src/bot_data/service/short_role_name_repository_service.py index fa65077e..3c4bed64 100644 --- a/kdb-bot/src/bot_data/service/short_role_name_repository_service.py +++ b/bot/src/bot_data/service/short_role_name_repository_service.py @@ -60,7 +60,10 @@ class ShortRoleNameRepositoryService(ShortRoleNameRepositoryABC): def find_short_role_names_by_role_id(self, role_id: int) -> List[ShortRoleName]: short_role_names = List(ShortRoleName) - self._logger.trace(__name__, f"Send SQL command: {ShortRoleName.get_select_by_role_id_string(role_id)}") + self._logger.trace( + __name__, + 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)) for result in results: self._logger.trace(__name__, f"Get short_role_name with id {result[0]}") diff --git a/bot/src/bot_data/service/steam_special_offer_repository_service.py b/bot/src/bot_data/service/steam_special_offer_repository_service.py new file mode 100644 index 00000000..dfd0e7ee --- /dev/null +++ b/bot/src/bot_data/service/steam_special_offer_repository_service.py @@ -0,0 +1,73 @@ +from typing import Optional + +from cpl_core.database.context import DatabaseContextABC +from cpl_query.extension import List + +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.abc.steam_special_offer_repository_abc import ( + SteamSpecialOfferRepositoryABC, +) +from bot_data.model.steam_special_offer import SteamSpecialOffer + + +class SteamSpecialOfferRepositoryService(SteamSpecialOfferRepositoryABC): + def __init__( + self, + logger: DatabaseLogger, + db_context: DatabaseContextABC, + servers: ServerRepositoryABC, + ): + self._logger = logger + self._context = db_context + + self._servers = servers + + SteamSpecialOfferRepositoryABC.__init__(self) + + @staticmethod + def _get_value_from_result(value: any) -> Optional[any]: + if isinstance(value, str) and "NULL" in value: + return None + + return value + + def _steam_special_offer_from_result(self, sql_result: tuple) -> SteamSpecialOffer: + return SteamSpecialOffer( + self._get_value_from_result(sql_result[1]), # name + float(self._get_value_from_result(sql_result[2])), # original_price + float(self._get_value_from_result(sql_result[3])), # discount_price + int(self._get_value_from_result(sql_result[4])), # discount_pct + id=self._get_value_from_result(sql_result[0]), # id + ) + + 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()}") + 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 + + def get_steam_special_offer_by_name(self, name: str) -> SteamSpecialOffer: + self._logger.trace( + __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(result) + + def add_steam_special_offer(self, steam_special_offer: SteamSpecialOffer): + self._logger.trace(__name__, f"Send SQL command: {steam_special_offer.insert_string}") + self._context.cursor.execute(steam_special_offer.insert_string) + + def update_steam_special_offer(self, steam_special_offer: SteamSpecialOffer): + self._logger.trace(__name__, f"Send SQL command: {steam_special_offer.udpate_string}") + self._context.cursor.execute(steam_special_offer.udpate_string) + + def delete_steam_special_offer(self, steam_special_offer: SteamSpecialOffer): + self._logger.trace(__name__, f"Send SQL command: {steam_special_offer.delete_string}") + self._context.cursor.execute(steam_special_offer.delete_string) diff --git a/kdb-bot/src/bot_data/service/technician_config_repository_service.py b/bot/src/bot_data/service/technician_config_repository_service.py similarity index 94% rename from kdb-bot/src/bot_data/service/technician_config_repository_service.py rename to bot/src/bot_data/service/technician_config_repository_service.py index fe32eded..f5c27306 100644 --- a/kdb-bot/src/bot_data/service/technician_config_repository_service.py +++ b/bot/src/bot_data/service/technician_config_repository_service.py @@ -29,7 +29,10 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC): def _get_technician_ping_urls(self) -> List[str]: urls = List(str) - self._logger.trace(__name__, f"Send SQL command: {TechnicianPingUrlConfig.get_select_all_string()}") + self._logger.trace( + __name__, + f"Send SQL command: {TechnicianPingUrlConfig.get_select_all_string()}", + ) results = self._context.select(TechnicianPingUrlConfig.get_select_all_string()) for result in results: self._logger.trace(__name__, f"Got TechnicianPingUrl with id {result[0]}") @@ -43,11 +46,13 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC): result[2], result[3], result[4], - json.loads(result[5]), + result[5], + bool(result[6]), + json.loads(result[7]), self._get_technician_ids(), self._get_technician_ping_urls(), - result[6], - result[7], + result[8], + result[9], id=result[0], ) diff --git a/kdb-bot/src/bot_data/service/technician_config_seeder.py b/bot/src/bot_data/service/technician_config_seeder.py similarity index 92% rename from kdb-bot/src/bot_data/service/technician_config_seeder.py rename to bot/src/bot_data/service/technician_config_seeder.py index 209b3e02..3107db0a 100644 --- a/kdb-bot/src/bot_data/service/technician_config_seeder.py +++ b/bot/src/bot_data/service/technician_config_seeder.py @@ -34,7 +34,10 @@ class TechnicianConfigSeeder(DataSeederABC): 1000000, {}, List(int, [240160344557879316]), - List(str, ["www.google.com", "www.sh-edraft.de", "www.keksdose-gaming.de"]), + List( + str, + ["www.google.com", "www.sh-edraft.de", "www.keksdose-gaming.de"], + ), ) self._technician_config.add_technician_config(config) diff --git a/kdb-bot/src/bot_data/service/user_game_ident_repository_service.py b/bot/src/bot_data/service/user_game_ident_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/user_game_ident_repository_service.py rename to bot/src/bot_data/service/user_game_ident_repository_service.py diff --git a/kdb-bot/src/bot_data/service/user_joined_game_server_repository_service.py b/bot/src/bot_data/service/user_joined_game_server_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/user_joined_game_server_repository_service.py rename to bot/src/bot_data/service/user_joined_game_server_repository_service.py diff --git a/kdb-bot/src/bot_data/service/user_joined_server_repository_service.py b/bot/src/bot_data/service/user_joined_server_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/user_joined_server_repository_service.py rename to bot/src/bot_data/service/user_joined_server_repository_service.py diff --git a/kdb-bot/src/bot_data/service/user_joined_voice_channel_repository_service.py b/bot/src/bot_data/service/user_joined_voice_channel_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/user_joined_voice_channel_repository_service.py rename to bot/src/bot_data/service/user_joined_voice_channel_repository_service.py diff --git a/kdb-bot/src/bot_data/service/user_message_count_per_hour_repository_service.py b/bot/src/bot_data/service/user_message_count_per_hour_repository_service.py similarity index 100% rename from kdb-bot/src/bot_data/service/user_message_count_per_hour_repository_service.py rename to bot/src/bot_data/service/user_message_count_per_hour_repository_service.py diff --git a/kdb-bot/src/bot_data/service/user_repository_service.py b/bot/src/bot_data/service/user_repository_service.py similarity index 97% rename from kdb-bot/src/bot_data/service/user_repository_service.py rename to bot/src/bot_data/service/user_repository_service.py index 73387908..940156a8 100644 --- a/kdb-bot/src/bot_data/service/user_repository_service.py +++ b/bot/src/bot_data/service/user_repository_service.py @@ -1,3 +1,4 @@ +import datetime from typing import Optional from cpl_core.database.context import DatabaseContextABC @@ -29,9 +30,10 @@ class UserRepositoryService(UserRepositoryABC): result[2], result[3], result[4], - self._servers.get_server_by_id(result[5]), - result[6], + result[5], + self._servers.get_server_by_id(result[6]), result[7], + result[8], id=result[0], ) diff --git a/kdb-bot/src/bot_data/service/user_warnings_repository_service.py b/bot/src/bot_data/service/user_warnings_repository_service.py similarity index 93% rename from kdb-bot/src/bot_data/service/user_warnings_repository_service.py rename to bot/src/bot_data/service/user_warnings_repository_service.py index ff19d61f..fbf7c4ee 100644 --- a/kdb-bot/src/bot_data/service/user_warnings_repository_service.py +++ b/bot/src/bot_data/service/user_warnings_repository_service.py @@ -32,7 +32,7 @@ class UserWarningsRepositoryService(UserWarningsRepositoryABC): def _from_result(self, sql_result: tuple) -> UserWarnings: user = self._users.get_user_by_id(self._get_value_from_result(sql_result[2])) author = None - author_id = self._get_value_from_result(sql_result[2]) + author_id = self._get_value_from_result(sql_result[3]) if author_id is not None: author = self._users.get_user_by_id(author_id) @@ -61,7 +61,10 @@ class UserWarningsRepositoryService(UserWarningsRepositoryABC): def get_user_warnings_by_user_id(self, user_id: int) -> List[UserWarnings]: warnings = List(UserWarnings) - self._logger.trace(__name__, f"Send SQL command: {UserWarnings.get_select_by_user_id_string(user_id)}") + self._logger.trace( + __name__, + 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)) diff --git a/kdb-bot/src/bot/startup_migration_extension.py b/bot/src/bot_data/startup_migration_extension.py similarity index 77% rename from kdb-bot/src/bot/startup_migration_extension.py rename to bot/src/bot_data/startup_migration_extension.py index bbf5f328..14a90938 100644 --- a/kdb-bot/src/bot/startup_migration_extension.py +++ b/bot/src/bot_data/startup_migration_extension.py @@ -9,18 +9,29 @@ from bot_data.migration.api_key_migration import ApiKeyMigration from bot_data.migration.api_migration import ApiMigration from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration from bot_data.migration.auto_role_migration import AutoRoleMigration -from bot_data.migration.config_feature_flags_migration import ConfigFeatureFlagsMigration +from bot_data.migration.birthday_migration import BirthdayMigration +from bot_data.migration.config_feature_flags_migration import ( + ConfigFeatureFlagsMigration, +) from bot_data.migration.config_migration import ConfigMigration from bot_data.migration.db_history_migration import DBHistoryMigration from bot_data.migration.default_role_migration import DefaultRoleMigration from bot_data.migration.fix_updates_migration import FixUpdatesMigration +from bot_data.migration.fix_user_history_migration import FixUserHistoryMigration from bot_data.migration.initial_migration import InitialMigration from bot_data.migration.level_migration import LevelMigration +from bot_data.migration.maintenance_mode_migration import MaintenanceModeMigration +from bot_data.migration.max_steam_offer_count_migration import MaxSteamOfferCountMigration from bot_data.migration.remove_stats_migration import RemoveStatsMigration from bot_data.migration.short_role_name_migration import ShortRoleNameMigration -from bot_data.migration.short_role_name_only_highest_migration import ShortRoleNameOnlyHighestMigration +from bot_data.migration.short_role_name_only_highest_migration import ( + ShortRoleNameOnlyHighestMigration, +) from bot_data.migration.stats_migration import StatsMigration -from bot_data.migration.user_joined_game_server_migration import UserJoinedGameServerMigration +from bot_data.migration.steam_special_offer_migration import SteamSpecialOfferMigration +from bot_data.migration.user_joined_game_server_migration import ( + UserJoinedGameServerMigration, +) from bot_data.migration.user_message_count_per_hour_migration import ( UserMessageCountPerHourMigration, ) @@ -56,3 +67,8 @@ class StartupMigrationExtension(StartupExtensionABC): services.add_transient(MigrationABC, ShortRoleNameMigration) # 28.09.2023 #378 - 1.1.7 services.add_transient(MigrationABC, FixUpdatesMigration) # 28.09.2023 #378 - 1.1.7 services.add_transient(MigrationABC, ShortRoleNameOnlyHighestMigration) # 02.10.2023 #391 - 1.1.9 + services.add_transient(MigrationABC, FixUserHistoryMigration) # 10.10.2023 #401 - 1.2.0 + services.add_transient(MigrationABC, BirthdayMigration) # 10.10.2023 #401 - 1.2.0 + services.add_transient(MigrationABC, SteamSpecialOfferMigration) # 10.10.2023 #188 - 1.2.0 + services.add_transient(MigrationABC, MaxSteamOfferCountMigration) # 04.11.2023 #188 - 1.2.0 + services.add_transient(MigrationABC, MaintenanceModeMigration) # 06.11.2023 #424 - 1.2.0 diff --git a/kdb-bot/src/bot_graphql/__init__.py b/bot/src/bot_graphql/__init__.py similarity index 84% rename from kdb-bot/src/bot_graphql/__init__.py rename to bot/src/bot_graphql/__init__.py index c6369011..963709cb 100644 --- a/kdb-bot/src/bot_graphql/__init__.py +++ b/bot/src/bot_graphql/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_graphql" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_graphql/abc/__init__.py b/bot/src/bot_graphql/abc/__init__.py similarity index 84% rename from kdb-bot/src/bot_graphql/abc/__init__.py rename to bot/src/bot_graphql/abc/__init__.py index 4c6777fd..31668cc0 100644 --- a/kdb-bot/src/bot_graphql/abc/__init__.py +++ b/bot/src/bot_graphql/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_graphql.abc" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_graphql/abc/data_query_abc.py b/bot/src/bot_graphql/abc/data_query_abc.py similarity index 100% rename from kdb-bot/src/bot_graphql/abc/data_query_abc.py rename to bot/src/bot_graphql/abc/data_query_abc.py diff --git a/kdb-bot/src/bot_graphql/abc/data_query_with_history_abc.py b/bot/src/bot_graphql/abc/data_query_with_history_abc.py similarity index 100% rename from kdb-bot/src/bot_graphql/abc/data_query_with_history_abc.py rename to bot/src/bot_graphql/abc/data_query_with_history_abc.py diff --git a/kdb-bot/src/bot_graphql/abc/filter_abc.py b/bot/src/bot_graphql/abc/filter_abc.py similarity index 100% rename from kdb-bot/src/bot_graphql/abc/filter_abc.py rename to bot/src/bot_graphql/abc/filter_abc.py diff --git a/kdb-bot/src/bot_graphql/abc/history_query_abc.py b/bot/src/bot_graphql/abc/history_query_abc.py similarity index 100% rename from kdb-bot/src/bot_graphql/abc/history_query_abc.py rename to bot/src/bot_graphql/abc/history_query_abc.py diff --git a/kdb-bot/src/bot_graphql/abc/query_abc.py b/bot/src/bot_graphql/abc/query_abc.py similarity index 89% rename from kdb-bot/src/bot_graphql/abc/query_abc.py rename to bot/src/bot_graphql/abc/query_abc.py index 1a566a94..506428fc 100644 --- a/kdb-bot/src/bot_graphql/abc/query_abc.py +++ b/bot/src/bot_graphql/abc/query_abc.py @@ -1,6 +1,7 @@ from typing import Callable from ariadne import ObjectType +from cpl_core.configuration import ConfigurationABC from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.type import T from cpl_discord.service import DiscordBotServiceABC @@ -10,6 +11,7 @@ from bot_api.exception.service_error_code_enum import ServiceErrorCode from bot_api.exception.service_exception import ServiceException from bot_api.route.route import Route from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.environment_variables import MAINTENANCE from bot_data.model.achievement import Achievement from bot_data.model.auth_role_enum import AuthRoleEnum from bot_data.model.auth_user import AuthUser @@ -75,9 +77,14 @@ class QueryABC(ObjectType): def get_services(services: ServiceProviderABC) -> ServiceProviderABC: return services + @ServiceProviderABC.inject + def get_config(config: ConfigurationABC) -> ConfigurationABC: + return config + services = get_services() permissions: PermissionService = services.get_service(PermissionService) bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC) + config = get_config() if user.auth_role == AuthRoleEnum.admin: return True @@ -87,6 +94,9 @@ class QueryABC(ObjectType): if permissions.is_member_technician(guild.get_member(u.discord_id)): return True + if config.get_configuration(MAINTENANCE): + return False + access = False if type(element) == Achievement: element: Achievement = element @@ -215,7 +225,9 @@ class QueryABC(ObjectType): return access @ServiceProviderABC.inject - def _can_user_mutate_data(self, server: Server, permission: UserRoleEnum, services: ServiceProviderABC): + def _can_user_mutate_data( + self, server: Server, permission: UserRoleEnum, services: ServiceProviderABC, config: ConfigurationABC + ): permissions: PermissionService = services.get_service(PermissionService) bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC) @@ -227,21 +239,32 @@ class QueryABC(ObjectType): auth_user.users.where(lambda x: x.server.id == server.id).single().discord_id ) - check_perm = lambda x: True + can_edit = lambda x: False match permission: case UserRoleEnum.moderator: - check_perm = lambda x: permissions.is_member_moderator(x) + can_edit = permissions.is_member_moderator + if config.get_configuration(MAINTENANCE): + can_edit = lambda x: False case UserRoleEnum.admin: - check_perm = lambda x: permissions.is_member_admin(x) + can_edit = permissions.is_member_admin + if config.get_configuration(MAINTENANCE): + can_edit = lambda x: False case UserRoleEnum.technician: - check_perm = lambda x: permissions.is_member_technician(x) + can_edit = permissions.is_member_technician - if not check_perm(member): + if not can_edit(member): ex = ServiceException(ServiceErrorCode.Forbidden, f"User not allowed to mutate data") raise ex # @FilterABC.resolve_filter_annotation - def _resolve_collection(self, collection: List, *_, filter: FilterABC = None, page: Page = None, sort: Sort = None): + def _resolve_collection( + self, + collection: List, + *_, + filter: FilterABC = None, + page: Page = None, + sort: Sort = None, + ): if filter is not None: collection = filter.filter(collection) diff --git a/kdb-bot/src/bot_graphql/bot-graphql.json b/bot/src/bot_graphql/bot-graphql.json similarity index 96% rename from kdb-bot/src/bot_graphql/bot-graphql.json rename to bot/src/bot_graphql/bot-graphql.json index 4a9505a7..552f4f7d 100644 --- a/kdb-bot/src/bot_graphql/bot-graphql.json +++ b/bot/src/bot_graphql/bot-graphql.json @@ -3,8 +3,8 @@ "Name": "bot-data", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/bot_graphql/filter/__init__.py b/bot/src/bot_graphql/filter/__init__.py similarity index 84% rename from kdb-bot/src/bot_graphql/filter/__init__.py rename to bot/src/bot_graphql/filter/__init__.py index 1d67bf12..0d5e9d05 100644 --- a/kdb-bot/src/bot_graphql/filter/__init__.py +++ b/bot/src/bot_graphql/filter/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_graphql.filter" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_graphql/filter/achievement_filter.py b/bot/src/bot_graphql/filter/achievement_filter.py similarity index 92% rename from kdb-bot/src/bot_graphql/filter/achievement_filter.py rename to bot/src/bot_graphql/filter/achievement_filter.py index 674af502..b95e00c0 100644 --- a/kdb-bot/src/bot_graphql/filter/achievement_filter.py +++ b/bot/src/bot_graphql/filter/achievement_filter.py @@ -1,3 +1,4 @@ +from cpl_core.dependency_injection import ServiceProviderABC from cpl_query.extension import List from bot_data.model.user import User @@ -5,9 +6,14 @@ from bot_graphql.abc.filter_abc import FilterABC class AchievementFilter(FilterABC): - def __init__(self): + def __init__( + self, + services: ServiceProviderABC, + ): FilterABC.__init__(self) + self._services = services + self._id = None self._name = None self._description = None diff --git a/kdb-bot/src/bot_graphql/filter/auto_role_filter.py b/bot/src/bot_graphql/filter/auto_role_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/auto_role_filter.py rename to bot/src/bot_graphql/filter/auto_role_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/auto_role_rule_filter.py b/bot/src/bot_graphql/filter/auto_role_rule_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/auto_role_rule_filter.py rename to bot/src/bot_graphql/filter/auto_role_rule_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/client_filter.py b/bot/src/bot_graphql/filter/client_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/client_filter.py rename to bot/src/bot_graphql/filter/client_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/level_filter.py b/bot/src/bot_graphql/filter/level_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/level_filter.py rename to bot/src/bot_graphql/filter/level_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/page.py b/bot/src/bot_graphql/filter/page.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/page.py rename to bot/src/bot_graphql/filter/page.py diff --git a/kdb-bot/src/bot_graphql/filter/server_filter.py b/bot/src/bot_graphql/filter/server_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/server_filter.py rename to bot/src/bot_graphql/filter/server_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/short_role_name_filter.py b/bot/src/bot_graphql/filter/short_role_name_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/short_role_name_filter.py rename to bot/src/bot_graphql/filter/short_role_name_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/sort.py b/bot/src/bot_graphql/filter/sort.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/sort.py rename to bot/src/bot_graphql/filter/sort.py diff --git a/kdb-bot/src/bot_graphql/filter/user_filter.py b/bot/src/bot_graphql/filter/user_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/user_filter.py rename to bot/src/bot_graphql/filter/user_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/user_joined_game_server_filter.py b/bot/src/bot_graphql/filter/user_joined_game_server_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/user_joined_game_server_filter.py rename to bot/src/bot_graphql/filter/user_joined_game_server_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/user_joined_server_filter.py b/bot/src/bot_graphql/filter/user_joined_server_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/user_joined_server_filter.py rename to bot/src/bot_graphql/filter/user_joined_server_filter.py diff --git a/kdb-bot/src/bot_graphql/filter/user_joined_voice_channel_filter.py b/bot/src/bot_graphql/filter/user_joined_voice_channel_filter.py similarity index 100% rename from kdb-bot/src/bot_graphql/filter/user_joined_voice_channel_filter.py rename to bot/src/bot_graphql/filter/user_joined_voice_channel_filter.py diff --git a/bot/src/bot_graphql/filter/user_warning_filter.py b/bot/src/bot_graphql/filter/user_warning_filter.py new file mode 100644 index 00000000..2c716c9e --- /dev/null +++ b/bot/src/bot_graphql/filter/user_warning_filter.py @@ -0,0 +1,56 @@ +from cpl_core.dependency_injection import ServiceProviderABC +from cpl_query.extension import List + +from bot_data.model.user_warnings import UserWarnings +from bot_graphql.abc.filter_abc import FilterABC + + +class UserWarningFilter(FilterABC): + def __init__( + self, + services: ServiceProviderABC, + ): + FilterABC.__init__(self) + + self._services = services + + self._id = None + self._user = None + self._description = None + self._author = None + + def from_dict(self, values: dict): + if "id" in values: + self._id = int(values["id"]) + + if "user" in values: + from bot_graphql.filter.user_filter import UserFilter + + self._user: UserFilter = self._services.get_service(UserFilter) + self._user.from_dict(values["user"]) + + if "description" in values: + self._description = values["description"] + + if "author" in values: + from bot_graphql.filter.user_filter import UserFilter + + self._author: UserFilter = self._services.get_service(UserFilter) + self._author.from_dict(values["author"]) + + def filter(self, query: List[UserWarnings]) -> List[UserWarnings]: + if self._id is not None: + query = query.where(lambda x: x.id == self._id) + + if self._user is not None: + users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id) + query = query.where(lambda x: x.id in users) + + if self._description is not None: + query = query.where(lambda x: x.description == self._description or self._description in x.description) + + if self._author is not None: + users = self._author.filter(query.select(lambda x: x.author)).select(lambda x: x.id) + query = query.where(lambda x: x.id in users) + + return query diff --git a/kdb-bot/src/bot_graphql/graphql/achievement.gql b/bot/src/bot_graphql/graphql/achievement.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/achievement.gql rename to bot/src/bot_graphql/graphql/achievement.gql diff --git a/kdb-bot/src/bot_graphql/graphql/autoRole.gql b/bot/src/bot_graphql/graphql/autoRole.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/autoRole.gql rename to bot/src/bot_graphql/graphql/autoRole.gql diff --git a/kdb-bot/src/bot_graphql/graphql/autoRoleRule.gql b/bot/src/bot_graphql/graphql/autoRoleRule.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/autoRoleRule.gql rename to bot/src/bot_graphql/graphql/autoRoleRule.gql diff --git a/kdb-bot/src/bot_graphql/graphql/base.gql b/bot/src/bot_graphql/graphql/base.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/base.gql rename to bot/src/bot_graphql/graphql/base.gql diff --git a/kdb-bot/src/bot_graphql/graphql/client.gql b/bot/src/bot_graphql/graphql/client.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/client.gql rename to bot/src/bot_graphql/graphql/client.gql diff --git a/kdb-bot/src/bot_graphql/graphql/discord.gql b/bot/src/bot_graphql/graphql/discord.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/discord.gql rename to bot/src/bot_graphql/graphql/discord.gql diff --git a/kdb-bot/src/bot_graphql/graphql/featureFlags.gql b/bot/src/bot_graphql/graphql/featureFlags.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/featureFlags.gql rename to bot/src/bot_graphql/graphql/featureFlags.gql diff --git a/kdb-bot/src/bot_graphql/graphql/knownUser.gql b/bot/src/bot_graphql/graphql/knownUser.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/knownUser.gql rename to bot/src/bot_graphql/graphql/knownUser.gql diff --git a/kdb-bot/src/bot_graphql/graphql/level.gql b/bot/src/bot_graphql/graphql/level.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/level.gql rename to bot/src/bot_graphql/graphql/level.gql diff --git a/kdb-bot/src/bot_graphql/graphql/mutation.gql b/bot/src/bot_graphql/graphql/mutation.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/mutation.gql rename to bot/src/bot_graphql/graphql/mutation.gql diff --git a/kdb-bot/src/bot_graphql/graphql/query.gql b/bot/src/bot_graphql/graphql/query.gql similarity index 93% rename from kdb-bot/src/bot_graphql/graphql/query.gql rename to bot/src/bot_graphql/graphql/query.gql index 8946e9a9..ffa3c21f 100644 --- a/kdb-bot/src/bot_graphql/graphql/query.gql +++ b/bot/src/bot_graphql/graphql/query.gql @@ -41,6 +41,9 @@ type Query { shortRoleNames(filter: ShortRoleNameFilter, page: Page, sort: Sort): [ShortRoleName] shortRoleNamePositions: [String] + userWarningCount: Int + userWarnings(filter: UserWarningFilter, page: Page, sort: Sort): [UserWarning] + technicianConfig: TechnicianConfig possibleFeatureFlags: [String] discord: Discord diff --git a/kdb-bot/src/bot_graphql/graphql/server.gql b/bot/src/bot_graphql/graphql/server.gql similarity index 94% rename from kdb-bot/src/bot_graphql/graphql/server.gql rename to bot/src/bot_graphql/graphql/server.gql index 2dda4cef..be603f3a 100644 --- a/kdb-bot/src/bot_graphql/graphql/server.gql +++ b/bot/src/bot_graphql/graphql/server.gql @@ -26,6 +26,7 @@ type Server implements TableWithHistoryQuery { gameServers: [GameServer] userCount: Int + activeUserCount: Int users(filter: UserFilter, page: Page, sort: Sort): [User] achievementCount: Int @@ -37,6 +38,8 @@ type Server implements TableWithHistoryQuery { config: ServerConfig hasFeatureFlag(flag: String): FeatureFlag + statistic(date: String): ServerStatistic + createdAt: String modifiedAt: String diff --git a/kdb-bot/src/bot_graphql/graphql/serverConfig.gql b/bot/src/bot_graphql/graphql/serverConfig.gql similarity index 92% rename from kdb-bot/src/bot_graphql/graphql/serverConfig.gql rename to bot/src/bot_graphql/graphql/serverConfig.gql index 7683194c..bc2f1e24 100644 --- a/kdb-bot/src/bot_graphql/graphql/serverConfig.gql +++ b/bot/src/bot_graphql/graphql/serverConfig.gql @@ -9,12 +9,14 @@ type ServerConfig implements TableWithHistoryQuery { xpPerOntimeHour: Int xpPerEventParticipation: Int xpPerAchievement: Int + xpForBirthday: Int afkCommandChannelId: String helpVoiceChannelId: String teamChannelId: String loginMessageChannelId: String defaultRoleId: String shortRoleNameOnlySetHighestRole: Boolean + gameOfferNotificationChatId: String featureFlagCount: Int featureFlags: [FeatureFlag] @@ -41,12 +43,14 @@ type ServerConfigHistory implements HistoryTableQuery { xpPerOntimeHour: Int xpPerEventParticipation: Int xpPerAchievement: Int + xpForBirthday: Int afkCommandChannelId: String helpVoiceChannelId: String teamChannelId: String loginMessageChannelId: String defaultRoleId: String shortRoleNameOnlySetHighestRole: Boolean + gameOfferNotificationChatId: String featureFlagCount: Int featureFlags: [FeatureFlag] @@ -91,12 +95,14 @@ input ServerConfigInput { xpPerOntimeHour: Int xpPerEventParticipation: Int xpPerAchievement: Int + xpForBirthday: Int afkCommandChannelId: String helpVoiceChannelId: String teamChannelId: String loginMessageChannelId: String defaultRoleId: String shortRoleNameOnlySetHighestRole: Boolean + gameOfferNotificationChatId: String featureFlags: [FeatureFlagInput] afkChannelIds: [String] diff --git a/bot/src/bot_graphql/graphql/serverStatistic.gql b/bot/src/bot_graphql/graphql/serverStatistic.gql new file mode 100644 index 00000000..9f3b5c9f --- /dev/null +++ b/bot/src/bot_graphql/graphql/serverStatistic.gql @@ -0,0 +1,17 @@ +type ServerStatistic { + achievementsAchieved: Int + messageCount: Int + + userCount: Int + activeUserCount: Int + + userJoinedVoiceChannelCount: Int + userJoinedVoiceChannelOntime: Int + + userJoinedGameServerCount: Int + userJoinedGameServerOntime: Int + + userWarningCount: Int + + activityScore: Int +} \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/graphql/shortRoleName.gql b/bot/src/bot_graphql/graphql/shortRoleName.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/shortRoleName.gql rename to bot/src/bot_graphql/graphql/shortRoleName.gql diff --git a/kdb-bot/src/bot_graphql/graphql/technicianConfig.gql b/bot/src/bot_graphql/graphql/technicianConfig.gql similarity index 90% rename from kdb-bot/src/bot_graphql/graphql/technicianConfig.gql rename to bot/src/bot_graphql/graphql/technicianConfig.gql index dd91ceab..63cc1fb8 100644 --- a/kdb-bot/src/bot_graphql/graphql/technicianConfig.gql +++ b/bot/src/bot_graphql/graphql/technicianConfig.gql @@ -4,6 +4,8 @@ type TechnicianConfig implements TableWithHistoryQuery { waitForRestart: Int waitForShutdown: Int cacheMaxMessages: Int + maxSteamOfferCount: Int + maintenance: Boolean featureFlagCount: Int featureFlags: [FeatureFlag] pingURLs: [String] @@ -23,6 +25,8 @@ type TechnicianConfigHistory implements HistoryTableQuery { waitForRestart: Int waitForShutdown: Int cacheMaxMessages: Int + maxSteamOfferCount: Int + maintenance: Boolean featureFlagCount: Int featureFlags: [FeatureFlag] @@ -59,6 +63,8 @@ input TechnicianConfigInput { waitForRestart: Int waitForShutdown: Int cacheMaxMessages: Int + maxSteamOfferCount: Int + maintenance: Boolean featureFlags: [FeatureFlagInput] pingURLs: [String] technicianIds: [String] diff --git a/kdb-bot/src/bot_graphql/graphql/user.gql b/bot/src/bot_graphql/graphql/user.gql similarity index 87% rename from kdb-bot/src/bot_graphql/graphql/user.gql rename to bot/src/bot_graphql/graphql/user.gql index 38db3573..9ffff9a2 100644 --- a/kdb-bot/src/bot_graphql/graphql/user.gql +++ b/bot/src/bot_graphql/graphql/user.gql @@ -5,6 +5,7 @@ type User implements TableWithHistoryQuery { xp: Int messageCount: Int reactionCount: Int + birthday: String ontime: Float level: Level @@ -20,6 +21,9 @@ type User implements TableWithHistoryQuery { achievementCount: Int achievements(filter: AchievementFilter, page: Page, sort: Sort): [Achievement] + userWarningCount: Int + userWarnings(filter: UserWarningFilter, page: Page, sort: Sort): [UserWarning] + server: Server leftServer: Boolean @@ -59,5 +63,7 @@ type UserMutation { input UserInput { id: ID xp: Int + birthday: String levelId: ID + userWarnings: [UserWarningInput] } \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/graphql/userJoinedGameServer.gql b/bot/src/bot_graphql/graphql/userJoinedGameServer.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/userJoinedGameServer.gql rename to bot/src/bot_graphql/graphql/userJoinedGameServer.gql diff --git a/kdb-bot/src/bot_graphql/graphql/userJoinedServer.gql b/bot/src/bot_graphql/graphql/userJoinedServer.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/userJoinedServer.gql rename to bot/src/bot_graphql/graphql/userJoinedServer.gql diff --git a/kdb-bot/src/bot_graphql/graphql/userJoinedVoiceChannel.gql b/bot/src/bot_graphql/graphql/userJoinedVoiceChannel.gql similarity index 100% rename from kdb-bot/src/bot_graphql/graphql/userJoinedVoiceChannel.gql rename to bot/src/bot_graphql/graphql/userJoinedVoiceChannel.gql diff --git a/bot/src/bot_graphql/graphql/userWarning.gql b/bot/src/bot_graphql/graphql/userWarning.gql new file mode 100644 index 00000000..d36a9eeb --- /dev/null +++ b/bot/src/bot_graphql/graphql/userWarning.gql @@ -0,0 +1,34 @@ +type UserWarning implements TableWithHistoryQuery { + id: ID + user: User + description: String + author: User + + createdAt: String + modifiedAt: String + + history: [UserWarningHistory] +} + +type UserWarningHistory implements HistoryTableQuery { + id: ID + user: ID + description: String + author: ID + + deleted: Boolean + dateFrom: String + dateTo: String +} + +input UserWarningFilter { + id: ID + user: UserFilter +} + +input UserWarningInput { + id: ID + user: ID + description: String + author: ID +} \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/graphql_module.py b/bot/src/bot_graphql/graphql_module.py similarity index 90% rename from kdb-bot/src/bot_graphql/graphql_module.py rename to bot/src/bot_graphql/graphql_module.py index 96c72797..95d73f7b 100644 --- a/kdb-bot/src/bot_graphql/graphql_module.py +++ b/bot/src/bot_graphql/graphql_module.py @@ -17,7 +17,10 @@ from bot_graphql.filter.short_role_name_filter import ShortRoleNameFilter from bot_graphql.filter.user_filter import UserFilter from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter -from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceChannelFilter +from bot_graphql.filter.user_joined_voice_channel_filter import ( + UserJoinedVoiceChannelFilter, +) +from bot_graphql.filter.user_warning_filter import UserWarningFilter from bot_graphql.graphql_service import GraphQLService from bot_graphql.mutation import Mutation from bot_graphql.mutations.achievement_mutation import AchievementMutation @@ -27,7 +30,9 @@ from bot_graphql.mutations.level_mutation import LevelMutation from bot_graphql.mutations.server_config_mutation import ServerConfigMutation from bot_graphql.mutations.short_role_name_mutation import ShortRoleNameMutation from bot_graphql.mutations.technician_config_mutation import TechnicianConfigMutation -from bot_graphql.mutations.user_joined_game_server_mutation import UserJoinedGameServerMutation +from bot_graphql.mutations.user_joined_game_server_mutation import ( + UserJoinedGameServerMutation, +) from bot_graphql.mutations.user_mutation import UserMutation from bot_graphql.queries.achievement_attribute_query import AchievementAttributeQuery from bot_graphql.queries.achievement_history_query import AchievementHistoryQuery @@ -52,20 +57,37 @@ from bot_graphql.queries.level_query import LevelQuery from bot_graphql.queries.server_config_query import ServerConfigQuery from bot_graphql.queries.server_history_query import ServerHistoryQuery from bot_graphql.queries.server_query import ServerQuery +from bot_graphql.queries.server_statistic_query import ServerStatisticQuery from bot_graphql.queries.short_role_name_history_query import ShortRoleNameHistoryQuery from bot_graphql.queries.short_role_name_query import ShortRoleNameQuery -from bot_graphql.queries.technician_config_history_query import TechnicianConfigHistoryQuery +from bot_graphql.queries.technician_config_history_query import ( + TechnicianConfigHistoryQuery, +) from bot_graphql.queries.technician_config_query import TechnicianConfigQuery -from bot_graphql.queries.technician_id_config_history_query import TechnicianIdConfigHistoryQuery -from bot_graphql.queries.technician_ping_url_config_history_query import TechnicianPingUrlConfigHistoryQuery +from bot_graphql.queries.technician_id_config_history_query import ( + TechnicianIdConfigHistoryQuery, +) +from bot_graphql.queries.technician_ping_url_config_history_query import ( + TechnicianPingUrlConfigHistoryQuery, +) from bot_graphql.queries.user_history_query import UserHistoryQuery -from bot_graphql.queries.user_joined_game_server_history_query import UserJoinedGameServerHistoryQuery +from bot_graphql.queries.user_joined_game_server_history_query import ( + UserJoinedGameServerHistoryQuery, +) from bot_graphql.queries.user_joined_game_server_query import UserJoinedGameServerQuery -from bot_graphql.queries.user_joined_server_history_query import UserJoinedServerHistoryQuery +from bot_graphql.queries.user_joined_server_history_query import ( + UserJoinedServerHistoryQuery, +) from bot_graphql.queries.user_joined_server_query import UserJoinedServerQuery -from bot_graphql.queries.user_joined_voice_channel_history_query import UserJoinedVoiceChannelHistoryQuery -from bot_graphql.queries.user_joined_voice_channel_query import UserJoinedVoiceChannelQuery +from bot_graphql.queries.user_joined_voice_channel_history_query import ( + UserJoinedVoiceChannelHistoryQuery, +) +from bot_graphql.queries.user_joined_voice_channel_query import ( + UserJoinedVoiceChannelQuery, +) from bot_graphql.queries.user_query import UserQuery +from bot_graphql.queries.user_warning_history_query import UserWarningHistoryQuery +from bot_graphql.queries.user_warning_query import UserWarningQuery from bot_graphql.query import Query from bot_graphql.schema import Schema @@ -115,6 +137,9 @@ class GraphQLModule(ModuleABC): services.add_transient(QueryABC, UserJoinedGameServerQuery) services.add_transient(QueryABC, ShortRoleNameHistoryQuery) services.add_transient(QueryABC, ShortRoleNameQuery) + services.add_transient(QueryABC, UserWarningHistoryQuery) + services.add_transient(QueryABC, UserWarningQuery) + services.add_transient(QueryABC, ServerStatisticQuery) services.add_transient(QueryABC, DiscordQuery) services.add_transient(QueryABC, GuildQuery) @@ -135,6 +160,7 @@ class GraphQLModule(ModuleABC): services.add_transient(FilterABC, UserJoinedVoiceChannelFilter) services.add_transient(FilterABC, UserJoinedGameServerFilter) services.add_transient(FilterABC, ShortRoleNameFilter) + services.add_transient(FilterABC, UserWarningFilter) # mutations services.add_transient(QueryABC, AutoRoleMutation) diff --git a/kdb-bot/src/bot_graphql/graphql_service.py b/bot/src/bot_graphql/graphql_service.py similarity index 100% rename from kdb-bot/src/bot_graphql/graphql_service.py rename to bot/src/bot_graphql/graphql_service.py diff --git a/kdb-bot/src/bot_graphql/model/__init__.py b/bot/src/bot_graphql/model/__init__.py similarity index 84% rename from kdb-bot/src/bot_graphql/model/__init__.py rename to bot/src/bot_graphql/model/__init__.py index bb404809..5ba9978f 100644 --- a/kdb-bot/src/bot_graphql/model/__init__.py +++ b/bot/src/bot_graphql/model/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_graphql.model" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_graphql/model/discord.py b/bot/src/bot_graphql/model/discord.py similarity index 100% rename from kdb-bot/src/bot_graphql/model/discord.py rename to bot/src/bot_graphql/model/discord.py diff --git a/bot/src/bot_graphql/model/server_statistics.py b/bot/src/bot_graphql/model/server_statistics.py new file mode 100644 index 00000000..45ae580e --- /dev/null +++ b/bot/src/bot_graphql/model/server_statistics.py @@ -0,0 +1,7 @@ +from bot_data.model.server import Server + + +class ServerStatistics: + def __init__(self, server: Server, kwargs: dict): + self.server = server + self.kwargs = kwargs diff --git a/kdb-bot/src/bot_graphql/mutation.py b/bot/src/bot_graphql/mutation.py similarity index 97% rename from kdb-bot/src/bot_graphql/mutation.py rename to bot/src/bot_graphql/mutation.py index 3dc7d599..39e38cc5 100644 --- a/kdb-bot/src/bot_graphql/mutation.py +++ b/bot/src/bot_graphql/mutation.py @@ -7,7 +7,9 @@ from bot_graphql.mutations.level_mutation import LevelMutation from bot_graphql.mutations.server_config_mutation import ServerConfigMutation from bot_graphql.mutations.short_role_name_mutation import ShortRoleNameMutation from bot_graphql.mutations.technician_config_mutation import TechnicianConfigMutation -from bot_graphql.mutations.user_joined_game_server_mutation import UserJoinedGameServerMutation +from bot_graphql.mutations.user_joined_game_server_mutation import ( + UserJoinedGameServerMutation, +) from bot_graphql.mutations.user_mutation import UserMutation diff --git a/kdb-bot/src/bot_graphql/mutations/__init__.py b/bot/src/bot_graphql/mutations/__init__.py similarity index 84% rename from kdb-bot/src/bot_graphql/mutations/__init__.py rename to bot/src/bot_graphql/mutations/__init__.py index 38c4b97b..180b6b7b 100644 --- a/kdb-bot/src/bot_graphql/mutations/__init__.py +++ b/bot/src/bot_graphql/mutations/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_graphql.mutations" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_graphql/mutations/achievement_mutation.py b/bot/src/bot_graphql/mutations/achievement_mutation.py similarity index 100% rename from kdb-bot/src/bot_graphql/mutations/achievement_mutation.py rename to bot/src/bot_graphql/mutations/achievement_mutation.py diff --git a/kdb-bot/src/bot_graphql/mutations/auto_role_mutation.py b/bot/src/bot_graphql/mutations/auto_role_mutation.py similarity index 93% rename from kdb-bot/src/bot_graphql/mutations/auto_role_mutation.py rename to bot/src/bot_graphql/mutations/auto_role_mutation.py index d936fc6e..72ac1cf9 100644 --- a/kdb-bot/src/bot_graphql/mutations/auto_role_mutation.py +++ b/bot/src/bot_graphql/mutations/auto_role_mutation.py @@ -25,7 +25,11 @@ class AutoRoleMutation(QueryABC): self.set_field("deleteAutoRole", self.resolve_delete_auto_role) def resolve_create_auto_role(self, *_, input: dict): - auto_role = AutoRole(self._servers.get_server_by_id(input["serverId"]), input["channelId"], input["messageId"]) + auto_role = AutoRole( + self._servers.get_server_by_id(input["serverId"]), + input["channelId"], + input["messageId"], + ) self._can_user_mutate_data(auto_role.server, UserRoleEnum.moderator) self._auto_roles.add_auto_role(auto_role) diff --git a/kdb-bot/src/bot_graphql/mutations/auto_role_rule_mutation.py b/bot/src/bot_graphql/mutations/auto_role_rule_mutation.py similarity index 98% rename from kdb-bot/src/bot_graphql/mutations/auto_role_rule_mutation.py rename to bot/src/bot_graphql/mutations/auto_role_rule_mutation.py index 56681df9..ceafdd2d 100644 --- a/kdb-bot/src/bot_graphql/mutations/auto_role_rule_mutation.py +++ b/bot/src/bot_graphql/mutations/auto_role_rule_mutation.py @@ -32,7 +32,9 @@ class AutoRoleRuleMutation(QueryABC): def resolve_create_auto_role_rule(self, *_, input: dict): auto_role_rule = AutoRoleRule( - self._auto_roles.get_auto_role_by_id(input["autoRoleId"]), input["emojiName"], input["roleId"] + self._auto_roles.get_auto_role_by_id(input["autoRoleId"]), + input["emojiName"], + input["roleId"], ) self._can_user_mutate_data(auto_role_rule.auto_role.server, UserRoleEnum.moderator) diff --git a/kdb-bot/src/bot_graphql/mutations/level_mutation.py b/bot/src/bot_graphql/mutations/level_mutation.py similarity index 93% rename from kdb-bot/src/bot_graphql/mutations/level_mutation.py rename to bot/src/bot_graphql/mutations/level_mutation.py index 215538b7..e0959c55 100644 --- a/kdb-bot/src/bot_graphql/mutations/level_mutation.py +++ b/bot/src/bot_graphql/mutations/level_mutation.py @@ -41,6 +41,9 @@ class LevelMutation(QueryABC): int(input["permissions"]), server, ) + levels = self._levels.get_levels_by_server_id(server.id) + if levels.where(lambda x: x.name == level.name).count() > 0: + raise ValueError(f"Level with name {level.name} already exists") self._levels.add_level(level) self._db.save_changes() diff --git a/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py b/bot/src/bot_graphql/mutations/server_config_mutation.py similarity index 92% rename from kdb-bot/src/bot_graphql/mutations/server_config_mutation.py rename to bot/src/bot_graphql/mutations/server_config_mutation.py index 044ec3be..6b2ff5eb 100644 --- a/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py +++ b/bot/src/bot_graphql/mutations/server_config_mutation.py @@ -72,6 +72,9 @@ class ServerConfigMutation(QueryABC): server_config.xp_per_achievement = ( input["xpPerAchievement"] if "xpPerAchievement" in input else server_config.xp_per_achievement ) + server_config.xp_for_birthday = ( + input["xpForBirthday"] if "xpForBirthday" in input else server_config.xp_for_birthday + ) server_config.afk_command_channel_id = ( input["afkCommandChannelId"] if "afkCommandChannelId" in input else server_config.afk_command_channel_id ) @@ -94,8 +97,18 @@ class ServerConfigMutation(QueryABC): if "shortRoleNameOnlySetHighestRole" in input else server_config.short_role_name_only_set_highest_role ) + server_config.game_offer_notification_chat_id = ( + input["gameOfferNotificationChatId"] + if "gameOfferNotificationChatId" in input + else server_config.game_offer_notification_chat_id + ) server_config.feature_flags = ( - dict(zip([x["key"] for x in input["featureFlags"]], [x["value"] for x in input["featureFlags"]])) + dict( + zip( + [x["key"] for x in input["featureFlags"]], + [x["value"] for x in input["featureFlags"]], + ) + ) if "featureFlags" in input else server_config.feature_flags ) @@ -139,6 +152,7 @@ class ServerConfigMutation(QueryABC): self._update_team_role_ids(server_config) self._db.save_changes() + self._bot.loop.create_task(self._config_service.reload_server_config(server_config.server)) return server_config def _update_afk_channel_ids(self, new_config: ServerConfig): @@ -178,5 +192,3 @@ class ServerConfigMutation(QueryABC): continue self._server_configs.add_server_team_role_id_config(role_id) - - self._bot.loop.create_task(self._config_service.reload_server_config(new_config.server)) diff --git a/kdb-bot/src/bot_graphql/mutations/short_role_name_mutation.py b/bot/src/bot_graphql/mutations/short_role_name_mutation.py similarity index 100% rename from kdb-bot/src/bot_graphql/mutations/short_role_name_mutation.py rename to bot/src/bot_graphql/mutations/short_role_name_mutation.py diff --git a/kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py b/bot/src/bot_graphql/mutations/technician_config_mutation.py similarity index 82% rename from kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py rename to bot/src/bot_graphql/mutations/technician_config_mutation.py index 434856ee..67091955 100644 --- a/kdb-bot/src/bot_graphql/mutations/technician_config_mutation.py +++ b/bot/src/bot_graphql/mutations/technician_config_mutation.py @@ -1,9 +1,12 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_discord.service import DiscordBotServiceABC from cpl_query.extension import List from bot_api.logging.api_logger import ApiLogger from bot_api.route.route import Route +from bot_core.abc.client_utils_abc import ClientUtilsABC +from bot_core.environment_variables import MAINTENANCE from bot_core.service.config_service import ConfigService from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC @@ -18,6 +21,7 @@ from bot_graphql.abc.query_abc import QueryABC class TechnicianConfigMutation(QueryABC): def __init__( self, + config: ConfigurationABC, logger: ApiLogger, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, @@ -25,9 +29,11 @@ class TechnicianConfigMutation(QueryABC): db: DatabaseContextABC, config_service: ConfigService, tech_seeder: TechnicianConfigSeeder, + client_utils: ClientUtilsABC, ): QueryABC.__init__(self, "TechnicianConfigMutation") + self._config = config self._logger = logger self._bot = bot self._servers = servers @@ -35,6 +41,7 @@ class TechnicianConfigMutation(QueryABC): self._db = db self._config_service = config_service self._tech_seeder = tech_seeder + self._client_utils = client_utils self.set_field("updateTechnicianConfig", self.resolve_update_technician_config) @@ -59,9 +66,20 @@ class TechnicianConfigMutation(QueryABC): technician_config.cache_max_messages = ( input["cacheMaxMessages"] if "cacheMaxMessages" in input else technician_config.cache_max_messages ) + technician_config.max_steam_offer_count = ( + input["maxSteamOfferCount"] if "maxSteamOfferCount" in input else technician_config.max_steam_offer_count + ) + technician_config.maintenance = ( + input["maintenance"] if "maintenance" in input else technician_config.maintenance + ) old_feature_flags = technician_config.feature_flags technician_config.feature_flags = ( - dict(zip([x["key"] for x in input["featureFlags"]], [x["value"] for x in input["featureFlags"]])) + dict( + zip( + [x["key"] for x in input["featureFlags"]], + [x["value"] for x in input["featureFlags"]], + ) + ) if "featureFlags" in input else technician_config.feature_flags ) @@ -86,7 +104,10 @@ class TechnicianConfigMutation(QueryABC): self._update_technician_ids(technician_config) self._db.save_changes() - self._config_service.reload_technician_config() + if technician_config.maintenance != self._config.get_configuration(MAINTENANCE): + self._bot.loop.create_task(self._client_utils.set_maintenance_mode(technician_config.maintenance)) + + self._bot.loop.create_task(self._config_service.reload_technician_config()) return technician_config def _update_ping_urls(self, new_config: TechnicianConfig): diff --git a/kdb-bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py b/bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py similarity index 99% rename from kdb-bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py rename to bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py index 9225299d..4f53a741 100644 --- a/kdb-bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py +++ b/bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py @@ -15,7 +15,9 @@ from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC -from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC +from bot_data.abc.user_joined_game_server_repository_abc import ( + UserJoinedGameServerRepositoryABC, +) from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.api_key import ApiKey from bot_data.model.server_config import ServerConfig diff --git a/bot/src/bot_graphql/mutations/user_mutation.py b/bot/src/bot_graphql/mutations/user_mutation.py new file mode 100644 index 00000000..9ec5f4cc --- /dev/null +++ b/bot/src/bot_graphql/mutations/user_mutation.py @@ -0,0 +1,90 @@ +from datetime import datetime + +from cpl_core.database.context import DatabaseContextABC +from cpl_discord.service import DiscordBotServiceABC + +from bot_api.route.route import Route +from bot_data.abc.level_repository_abc import LevelRepositoryABC +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC +from bot_data.model.user import User +from bot_data.model.user_role_enum import UserRoleEnum +from bot_graphql.abc.query_abc import QueryABC +from modules.base.service.user_warnings_service import UserWarningsService +from modules.level.service.level_service import LevelService +from modules.permission.service.permission_service import PermissionService + + +class UserMutation(QueryABC): + def __init__( + self, + servers: ServerRepositoryABC, + users: UserRepositoryABC, + bot: DiscordBotServiceABC, + db: DatabaseContextABC, + permissions: PermissionService, + levels: LevelRepositoryABC, + level_service: LevelService, + user_warnings: UserWarningsRepositoryABC, + user_warning_service: UserWarningsService, + ): + QueryABC.__init__(self, "UserMutation") + + self._servers = servers + self._users = users + self._bot = bot + self._db = db + self._permissions = permissions + self._levels = levels + self._level_service = level_service + self._user_warnings = user_warnings + self._user_warning_service = user_warning_service + + self.set_field("updateUser", self.resolve_update_user) + + def resolve_update_user(self, *_, input: dict): + user = self._users.get_user_by_id(input["id"]) + + auth_user = Route.get_user() + member = self._bot.get_guild(user.server.discord_id).get_member( + auth_user.users.where(lambda x: x.server.id == user.server.id).single().discord_id + ) + if member.id != user.discord_id: + self._can_user_mutate_data(user.server, UserRoleEnum.moderator) + + new_xp = None + if "levelId" in input: + level = self._levels.get_level_by_id(input["levelId"]) + if user.level.id != level.id: + new_xp = level.min_xp + + if "userWarnings" in input: + self._update_user_warning(user, input["userWarnings"]) + + user.xp = new_xp if new_xp is not None else input["xp"] if "xp" in input else user.xp + + user.birthday = datetime.strptime(input["birthday"], "%d.%m.%Y") if "birthday" in input else user.birthday + + self._users.update_user(user) + self._db.save_changes() + self._bot.loop.create_task(self._level_service.set_level(user)) + + user = self._users.get_user_by_id(input["id"]) + return user + + def _update_user_warning(self, user: User, new_warnings: dict): + old_warnings = self._user_warnings.get_user_warnings_by_user_id(user.id) + for warning in old_warnings: + if warning.id in [int(x["id"]) if "id" in x else None for x in new_warnings]: + continue + + self._user_warning_service.remove_warnings(warning.id) + + for warning in new_warnings: + if "id" in warning and int(warning["id"]) in old_warnings.select(lambda x: x.id): + continue + + member = self._bot.get_guild(user.server.discord_id).get_member(user.discord_id) + author = self._users.get_user_by_id(int(warning["author"])) + self._user_warning_service.add_warnings(member, warning["description"], author.discord_id) diff --git a/kdb-bot/src/bot_graphql/queries/__init__.py b/bot/src/bot_graphql/queries/__init__.py similarity index 84% rename from kdb-bot/src/bot_graphql/queries/__init__.py rename to bot/src/bot_graphql/queries/__init__.py index 6709693b..9cdf0a5a 100644 --- a/kdb-bot/src/bot_graphql/queries/__init__.py +++ b/bot/src/bot_graphql/queries/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_graphql.queries" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_graphql/queries/achievement_attribute_query.py b/bot/src/bot_graphql/queries/achievement_attribute_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/achievement_attribute_query.py rename to bot/src/bot_graphql/queries/achievement_attribute_query.py diff --git a/kdb-bot/src/bot_graphql/queries/achievement_history_query.py b/bot/src/bot_graphql/queries/achievement_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/achievement_history_query.py rename to bot/src/bot_graphql/queries/achievement_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/achievement_query.py b/bot/src/bot_graphql/queries/achievement_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/achievement_query.py rename to bot/src/bot_graphql/queries/achievement_query.py diff --git a/kdb-bot/src/bot_graphql/queries/auto_role_history_query.py b/bot/src/bot_graphql/queries/auto_role_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/auto_role_history_query.py rename to bot/src/bot_graphql/queries/auto_role_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/auto_role_query.py b/bot/src/bot_graphql/queries/auto_role_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/auto_role_query.py rename to bot/src/bot_graphql/queries/auto_role_query.py diff --git a/kdb-bot/src/bot_graphql/queries/auto_role_rule_history_query.py b/bot/src/bot_graphql/queries/auto_role_rule_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/auto_role_rule_history_query.py rename to bot/src/bot_graphql/queries/auto_role_rule_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/auto_role_rule_query.py b/bot/src/bot_graphql/queries/auto_role_rule_query.py similarity index 90% rename from kdb-bot/src/bot_graphql/queries/auto_role_rule_query.py rename to bot/src/bot_graphql/queries/auto_role_rule_query.py index e847a605..0b6373dd 100644 --- a/kdb-bot/src/bot_graphql/queries/auto_role_rule_query.py +++ b/bot/src/bot_graphql/queries/auto_role_rule_query.py @@ -8,7 +8,12 @@ from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC class AutoRoleRuleQuery(DataQueryWithHistoryABC): - def __init__(self, bot: DiscordBotServiceABC, auto_roles: AutoRoleRepositoryABC, db: DatabaseContextABC): + def __init__( + self, + bot: DiscordBotServiceABC, + auto_roles: AutoRoleRepositoryABC, + db: DatabaseContextABC, + ): DataQueryWithHistoryABC.__init__(self, "AutoRoleRule", "AutoRoleRulesHistory", AutoRoleRuleHistory, db) self._bot = bot diff --git a/kdb-bot/src/bot_graphql/queries/client_history_query.py b/bot/src/bot_graphql/queries/client_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/client_history_query.py rename to bot/src/bot_graphql/queries/client_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/client_query.py b/bot/src/bot_graphql/queries/client_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/client_query.py rename to bot/src/bot_graphql/queries/client_query.py diff --git a/kdb-bot/src/bot_graphql/queries/discord/__init__.py b/bot/src/bot_graphql/queries/discord/__init__.py similarity index 84% rename from kdb-bot/src/bot_graphql/queries/discord/__init__.py rename to bot/src/bot_graphql/queries/discord/__init__.py index 813ca26f..662e0b21 100644 --- a/kdb-bot/src/bot_graphql/queries/discord/__init__.py +++ b/bot/src/bot_graphql/queries/discord/__init__.py @@ -15,7 +15,7 @@ __title__ = "bot_graphql.queries.discord" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/bot_graphql/queries/discord/channel_query.py b/bot/src/bot_graphql/queries/discord/channel_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/discord/channel_query.py rename to bot/src/bot_graphql/queries/discord/channel_query.py diff --git a/kdb-bot/src/bot_graphql/queries/discord/discord_query.py b/bot/src/bot_graphql/queries/discord/discord_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/discord/discord_query.py rename to bot/src/bot_graphql/queries/discord/discord_query.py diff --git a/kdb-bot/src/bot_graphql/queries/discord/discord_user_query.py b/bot/src/bot_graphql/queries/discord/discord_user_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/discord/discord_user_query.py rename to bot/src/bot_graphql/queries/discord/discord_user_query.py diff --git a/kdb-bot/src/bot_graphql/queries/discord/emoji_query.py b/bot/src/bot_graphql/queries/discord/emoji_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/discord/emoji_query.py rename to bot/src/bot_graphql/queries/discord/emoji_query.py diff --git a/kdb-bot/src/bot_graphql/queries/discord/guild_query.py b/bot/src/bot_graphql/queries/discord/guild_query.py similarity index 82% rename from kdb-bot/src/bot_graphql/queries/discord/guild_query.py rename to bot/src/bot_graphql/queries/discord/guild_query.py index 98f581f3..7b64eeab 100644 --- a/kdb-bot/src/bot_graphql/queries/discord/guild_query.py +++ b/bot/src/bot_graphql/queries/discord/guild_query.py @@ -20,11 +20,12 @@ class GuildQuery(QueryABC): self.set_field("channels", self._resolve_channels) self.set_field("roles", lambda g, *_: g.roles.order_by(lambda x: x.position)) self.set_field( - "emojis", lambda g, *_: List(discord.Emoji, g.emojis).order_by_descending(lambda x: x.created_at) + "emojis", + lambda g, *_: List(discord.Emoji, g.emojis).order_by_descending(lambda x: x.created_at), ) def _resolve_channels(self, g: Guild, *_, filter=None): - channels = List(any).extend(g.channels) + channels = List(any).extend(g.channels).order_by(lambda x: x.position) if filter is None: return channels @@ -38,4 +39,4 @@ class GuildQuery(QueryABC): if "type" in filter: channels = channels.where(lambda c: type(c).__name__ == filter["type"]) - return channels.order_by(lambda x: x.position) + return channels diff --git a/kdb-bot/src/bot_graphql/queries/discord/role_query.py b/bot/src/bot_graphql/queries/discord/role_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/discord/role_query.py rename to bot/src/bot_graphql/queries/discord/role_query.py diff --git a/kdb-bot/src/bot_graphql/queries/game_server_query.py b/bot/src/bot_graphql/queries/game_server_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/game_server_query.py rename to bot/src/bot_graphql/queries/game_server_query.py diff --git a/kdb-bot/src/bot_graphql/queries/known_user_history_query.py b/bot/src/bot_graphql/queries/known_user_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/known_user_history_query.py rename to bot/src/bot_graphql/queries/known_user_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/known_user_query.py b/bot/src/bot_graphql/queries/known_user_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/known_user_query.py rename to bot/src/bot_graphql/queries/known_user_query.py diff --git a/kdb-bot/src/bot_graphql/queries/level_history_query.py b/bot/src/bot_graphql/queries/level_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/level_history_query.py rename to bot/src/bot_graphql/queries/level_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/level_query.py b/bot/src/bot_graphql/queries/level_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/level_query.py rename to bot/src/bot_graphql/queries/level_query.py diff --git a/kdb-bot/src/bot_graphql/queries/server_config_query.py b/bot/src/bot_graphql/queries/server_config_query.py similarity index 79% rename from kdb-bot/src/bot_graphql/queries/server_config_query.py rename to bot/src/bot_graphql/queries/server_config_query.py index 5e580eca..3f45fdbf 100644 --- a/kdb-bot/src/bot_graphql/queries/server_config_query.py +++ b/bot/src/bot_graphql/queries/server_config_query.py @@ -18,19 +18,31 @@ class ServerConfigQuery(DataQueryWithHistoryABC): self.set_field("xpPerReaction", lambda config, *_: config.xp_per_reaction) self.set_field("maxMessageXpPerHour", lambda config, *_: config.max_message_xp_per_hour) self.set_field("xpPerOntimeHour", lambda config, *_: config.xp_per_ontime_hour) - self.set_field("xpPerEventParticipation", lambda config, *_: config.xp_per_event_participation) + self.set_field( + "xpPerEventParticipation", + lambda config, *_: config.xp_per_event_participation, + ) self.set_field("xpPerAchievement", lambda config, *_: config.xp_per_achievement) + self.set_field("xpForBirthday", lambda config, *_: config.xp_for_birthday) self.set_field("afkCommandChannelId", lambda config, *_: config.afk_command_channel_id) self.set_field("helpVoiceChannelId", lambda config, *_: config.help_voice_channel_id) self.set_field("teamChannelId", lambda config, *_: config.team_channel_id) self.set_field("loginMessageChannelId", lambda config, *_: config.login_message_channel_id) self.set_field("defaultRoleId", lambda config, *_: config.default_role_id) self.set_field( - "shortRoleNameOnlySetHighestRole", lambda config, *_: config.short_role_name_only_set_highest_role + "shortRoleNameOnlySetHighestRole", + lambda config, *_: config.short_role_name_only_set_highest_role, + ) + self.set_field( + "gameOfferNotificationChatId", + lambda config, *_: config.game_offer_notification_chat_id, ) self.add_collection( "featureFlag", - lambda config, *_: List(any, [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags]), + lambda config, *_: List( + any, + [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags], + ), ) self.set_field("afkChannelIds", lambda config, *_: config.afk_channel_ids) self.set_field( diff --git a/kdb-bot/src/bot_graphql/queries/server_history_query.py b/bot/src/bot_graphql/queries/server_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/server_history_query.py rename to bot/src/bot_graphql/queries/server_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/server_query.py b/bot/src/bot_graphql/queries/server_query.py similarity index 74% rename from kdb-bot/src/bot_graphql/queries/server_query.py rename to bot/src/bot_graphql/queries/server_query.py index 6ba77149..14033101 100644 --- a/kdb-bot/src/bot_graphql/queries/server_query.py +++ b/bot/src/bot_graphql/queries/server_query.py @@ -12,7 +12,9 @@ from bot_data.abc.level_repository_abc import LevelRepositoryABC from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC from bot_data.abc.short_role_name_repository_abc import ShortRoleNameRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC -from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC +from bot_data.abc.user_joined_voice_channel_repository_abc import ( + UserJoinedVoiceChannelRepositoryABC, +) from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.server import Server from bot_data.model.server_config import ServerConfig @@ -24,6 +26,7 @@ from bot_graphql.filter.client_filter import ClientFilter from bot_graphql.filter.level_filter import LevelFilter from bot_graphql.filter.short_role_name_filter import ShortRoleNameFilter from bot_graphql.filter.user_filter import UserFilter +from bot_graphql.model.server_statistics import ServerStatistics class ServerQuery(DataQueryWithHistoryABC): @@ -65,23 +68,47 @@ class ServerQuery(DataQueryWithHistoryABC): AutoRoleFilter, ) self.add_collection( - "client", lambda server, *_: self._clients.get_clients_by_server_id(server.id), ClientFilter + "client", + lambda server, *_: self._clients.get_clients_by_server_id(server.id), + ClientFilter, ) - self.add_collection("level", lambda server, *_: self._levels.get_levels_by_server_id(server.id), LevelFilter) - self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.id), UserFilter) - self.add_collection("gameServer", lambda server, *_: game_servers.get_game_servers_by_server_id(server.id)) self.add_collection( - "achievement", lambda server, *_: achievements.get_achievements_by_server_id(server.id), AchievementFilter + "level", + lambda server, *_: self._levels.get_levels_by_server_id(server.id), + LevelFilter, + ) + self.set_field( + "activeUserCount", + lambda server, *_: self._users.get_users_by_server_id(server.id).where(lambda x: not x.left_server).count(), + ) + self.add_collection( + "user", + lambda server, *_: self._users.get_users_by_server_id(server.id), + UserFilter, + ) + self.add_collection( + "gameServer", + lambda server, *_: game_servers.get_game_servers_by_server_id(server.id), + ) + self.add_collection( + "achievement", + lambda server, *_: achievements.get_achievements_by_server_id(server.id), + AchievementFilter, ) self.add_collection( "shortRoleName", lambda server, *_: short_role_names.get_short_role_names_by_server_id(server.id), ShortRoleNameFilter, ) - self.set_field("config", lambda server, *_: server_configs.get_server_config_by_server(server.id)) self.set_field( - "hasFeatureFlag", lambda server, *_, **kwargs: self._resolve_has_feature_flag(server, *_, **kwargs) + "config", + lambda server, *_: server_configs.get_server_config_by_server(server.id), ) + self.set_field( + "hasFeatureFlag", + lambda server, *_, **kwargs: self._resolve_has_feature_flag(server, *_, **kwargs), + ) + self.set_field("statistic", lambda server, *_, **kwargs: ServerStatistics(server, kwargs)) @staticmethod def resolve_id(server: Server, *_): diff --git a/bot/src/bot_graphql/queries/server_statistic_query.py b/bot/src/bot_graphql/queries/server_statistic_query.py new file mode 100644 index 00000000..7fa4d9c1 --- /dev/null +++ b/bot/src/bot_graphql/queries/server_statistic_query.py @@ -0,0 +1,157 @@ +import datetime + +from cpl_core.configuration import ConfigurationABC + +from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC +from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC +from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC +from bot_data.abc.user_message_count_per_hour_repository_abc import UserMessageCountPerHourRepositoryABC +from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC +from bot_data.model.server_config import ServerConfig +from bot_graphql.abc.query_abc import QueryABC + + +class ServerStatisticQuery(QueryABC): + def __init__( + self, + config: ConfigurationABC, + users: UserRepositoryABC, + user_joined_voice_channels: UserJoinedVoiceChannelRepositoryABC, + user_joined_game_servers: UserJoinedGameServerRepositoryABC, + user_messages: UserMessageCountPerHourRepositoryABC, + user_warnings: UserWarningsRepositoryABC, + achievements: AchievementRepositoryABC, + ): + QueryABC.__init__(self, "ServerStatistic") + + self._config = config + self._users = users + self._user_joined_voice_channels = user_joined_voice_channels + self._user_joined_game_servers = user_joined_game_servers + self._user_messages = user_messages + self._user_warnings = user_warnings + self._achievements = achievements + + self.set_field( + "achievementsAchieved", + self._resolve_achievements, + ) + + self.set_field( + "messageCount", + self._resolve_message_count, + ) + + self.set_field("userCount", lambda server, *_: self._users.get_users_by_server_id(server.server.id).count()) + self.set_field("activeUserCount", self._resolve_active_count) + + self.set_field("userJoinedVoiceChannelCount", self._resolve_voice_channel_count) + self.set_field("userJoinedVoiceChannelOntime", self._resolve_voice_channel_ontime) + + self.set_field("userJoinedGameServerCount", self._resolve_game_server_count) + self.set_field("userJoinedGameServerOntime", self._resolve_game_server_ontime) + + self.set_field("userWarningCount", self._resolve_user_warning_count) + + self.set_field("activityScore", self._resolve_activity_score) + + def _resolve_activity_score(self, server, *_): + days = (datetime.date.today() - self._get_date(**server.kwargs)).days + return int( + ( + ( + self._resolve_achievements(server, *_) + + self._resolve_message_count(server, *_) + + self._resolve_voice_channel_count(server, *_) + + self._resolve_voice_channel_ontime(server, *_) + + self._resolve_game_server_count(server, *_) + + self._resolve_game_server_ontime(server, *_) + - self._resolve_user_warning_count(server, *_) + ) + / self._resolve_active_count(server, *_) + ) + / days + * 1000 + ) + + def _resolve_message_count(self, server, *_): + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.server.discord_id}") + return ( + self._user_messages.get_user_message_count_per_hours() + .where( + lambda x: x.user.server.id == server.server.id + and x.created_at.date() >= self._get_date(**server.kwargs) + ) + .sum(lambda x: x.xp_count / settings.xp_per_message) + ) + + def _resolve_active_count(self, server, *_): + return self._users.get_users_by_server_id(server.server.id).where(lambda x: not x.left_server).count() + + def _resolve_voice_channel_count(self, server, *_): + return ( + self._user_joined_voice_channels.get_user_joined_voice_channels() + .where( + lambda x: x.user.server.id == server.server.id + and x.created_at.date() >= self._get_date(**server.kwargs) + ) + .count() + ) + + def _resolve_voice_channel_ontime(self, server, *_): + return ( + self._user_joined_voice_channels.get_user_joined_voice_channels() + .where( + lambda x: x.user.server.id == server.server.id + and x.created_at.date() >= self._get_date(**server.kwargs) + ) + .sum(lambda x: x.time) + ) + + def _resolve_game_server_count(self, server, *_): + return ( + self._user_joined_game_servers.get_user_joined_game_servers() + .where( + lambda x: x.user.server.id == server.server.id + and x.created_at.date() >= self._get_date(**server.kwargs) + ) + .count() + ) + + def _resolve_game_server_ontime(self, server, *_): + return ( + self._user_joined_game_servers.get_user_joined_game_servers() + .where( + lambda x: x.user.server.id == server.server.id + and x.created_at.date() >= self._get_date(**server.kwargs) + ) + .sum(lambda x: x.time) + ) + + def _resolve_user_warning_count(self, server, *_): + return ( + self._user_warnings.get_user_warnings() + .where( + lambda x: x.user.server.id == server.server.id + and x.created_at.date() >= self._get_date(**server.kwargs) + ) + .count() + ) + + def _resolve_achievements(self, server, *_): + return ( + self._achievements.get_achievements_by_server_id(server.server.id) + .select_many(lambda x: self._achievements.get_user_got_achievements_by_achievement_id(x.id)) + .where( + lambda x: x.user.server.id == server.server.id + and x.created_at.date() >= self._get_date(**server.kwargs) + ) + .count() + ) + + def _get_date(self, **kwargs) -> datetime.date: + if "date" not in kwargs: + return datetime.date.today() - datetime.timedelta(days=7) + + return datetime.datetime.strptime(kwargs["date"], "%d.%m.%Y").date() diff --git a/kdb-bot/src/bot_graphql/queries/short_role_name_history_query.py b/bot/src/bot_graphql/queries/short_role_name_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/short_role_name_history_query.py rename to bot/src/bot_graphql/queries/short_role_name_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/short_role_name_query.py b/bot/src/bot_graphql/queries/short_role_name_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/short_role_name_query.py rename to bot/src/bot_graphql/queries/short_role_name_query.py diff --git a/kdb-bot/src/bot_graphql/queries/technician_config_history_query.py b/bot/src/bot_graphql/queries/technician_config_history_query.py similarity index 54% rename from kdb-bot/src/bot_graphql/queries/technician_config_history_query.py rename to bot/src/bot_graphql/queries/technician_config_history_query.py index a63f88f8..825acd7b 100644 --- a/kdb-bot/src/bot_graphql/queries/technician_config_history_query.py +++ b/bot/src/bot_graphql/queries/technician_config_history_query.py @@ -7,11 +7,19 @@ class TechnicianConfigHistoryQuery(HistoryQueryABC): def __init__(self): HistoryQueryABC.__init__(self, "TechnicianConfig") - self.set_field("helpCommandReferenceUrl", lambda config, *_: config.help_command_reference_url) + self.set_field( + "helpCommandReferenceUrl", + lambda config, *_: config.help_command_reference_url, + ) self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart) self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown) self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages) + self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count) + self.set_field("maintenance", lambda config, *_: config.maintenance) self.add_collection( "featureFlag", - lambda config, *_: List(any, [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags]), + lambda config, *_: List( + any, + [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags], + ), ) diff --git a/kdb-bot/src/bot_graphql/queries/technician_config_query.py b/bot/src/bot_graphql/queries/technician_config_query.py similarity index 73% rename from kdb-bot/src/bot_graphql/queries/technician_config_query.py rename to bot/src/bot_graphql/queries/technician_config_query.py index 2d8bb8f9..4809a60d 100644 --- a/kdb-bot/src/bot_graphql/queries/technician_config_query.py +++ b/bot/src/bot_graphql/queries/technician_config_query.py @@ -4,21 +4,37 @@ from cpl_query.extension import List from bot_data.abc.table_with_id_abc import TableWithIdABC from bot_data.model.technician_config_history import TechnicianConfigHistory from bot_data.model.technician_id_config_history import TechnicianIdConfigHistory -from bot_data.model.technician_ping_url_config_history import TechnicianPingUrlConfigHistory +from bot_data.model.technician_ping_url_config_history import ( + TechnicianPingUrlConfigHistory, +) from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC class TechnicianConfigQuery(DataQueryWithHistoryABC): def __init__(self, db: DatabaseContextABC): - DataQueryWithHistoryABC.__init__(self, "TechnicianConfig", "CFG_TechnicianHistory", TechnicianConfigHistory, db) + DataQueryWithHistoryABC.__init__( + self, + "TechnicianConfig", + "CFG_TechnicianHistory", + TechnicianConfigHistory, + db, + ) - self.set_field("helpCommandReferenceUrl", lambda config, *_: config.help_command_reference_url) + self.set_field( + "helpCommandReferenceUrl", + lambda config, *_: config.help_command_reference_url, + ) self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart) self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown) self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages) + self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count) + self.set_field("maintenance", lambda config, *_: config.maintenance) self.add_collection( "featureFlag", - lambda config, *_: List(any, [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags]), + lambda config, *_: List( + any, + [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags], + ), ) self.set_field("pingURLs", lambda config, *_: config.ping_urls) self.set_field("technicianIds", lambda config, *_: config.technician_ids) diff --git a/kdb-bot/src/bot_graphql/queries/technician_id_config_history_query.py b/bot/src/bot_graphql/queries/technician_id_config_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/technician_id_config_history_query.py rename to bot/src/bot_graphql/queries/technician_id_config_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/technician_ping_url_config_history_query.py b/bot/src/bot_graphql/queries/technician_ping_url_config_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/technician_ping_url_config_history_query.py rename to bot/src/bot_graphql/queries/technician_ping_url_config_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/user_history_query.py b/bot/src/bot_graphql/queries/user_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/user_history_query.py rename to bot/src/bot_graphql/queries/user_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/user_joined_game_server_history_query.py b/bot/src/bot_graphql/queries/user_joined_game_server_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/user_joined_game_server_history_query.py rename to bot/src/bot_graphql/queries/user_joined_game_server_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/user_joined_game_server_query.py b/bot/src/bot_graphql/queries/user_joined_game_server_query.py similarity index 90% rename from kdb-bot/src/bot_graphql/queries/user_joined_game_server_query.py rename to bot/src/bot_graphql/queries/user_joined_game_server_query.py index 6a5befaa..0ea7ceb3 100644 --- a/kdb-bot/src/bot_graphql/queries/user_joined_game_server_query.py +++ b/bot/src/bot_graphql/queries/user_joined_game_server_query.py @@ -9,7 +9,11 @@ from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC class UserJoinedGameServerQuery(DataQueryWithHistoryABC): def __init__(self, bot: DiscordBotServiceABC, db: DatabaseContextABC): DataQueryWithHistoryABC.__init__( - self, "UserJoinedGameServer", "UserJoinedGameServersHistory", UserJoinedGameServerHistory, db + self, + "UserJoinedGameServer", + "UserJoinedGameServersHistory", + UserJoinedGameServerHistory, + db, ) self._bot = bot diff --git a/kdb-bot/src/bot_graphql/queries/user_joined_server_history_query.py b/bot/src/bot_graphql/queries/user_joined_server_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/user_joined_server_history_query.py rename to bot/src/bot_graphql/queries/user_joined_server_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/user_joined_server_query.py b/bot/src/bot_graphql/queries/user_joined_server_query.py similarity index 87% rename from kdb-bot/src/bot_graphql/queries/user_joined_server_query.py rename to bot/src/bot_graphql/queries/user_joined_server_query.py index a8e236ff..db9967f4 100644 --- a/kdb-bot/src/bot_graphql/queries/user_joined_server_query.py +++ b/bot/src/bot_graphql/queries/user_joined_server_query.py @@ -8,7 +8,11 @@ from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC class UserJoinedServerQuery(DataQueryWithHistoryABC): def __init__(self, db: DatabaseContextABC): DataQueryWithHistoryABC.__init__( - self, "UserJoinedServer", "UserJoinedServersHistory", UserJoinedServerHistory, db + self, + "UserJoinedServer", + "UserJoinedServersHistory", + UserJoinedServerHistory, + db, ) self.set_field("id", self.resolve_id) diff --git a/kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_history_query.py b/bot/src/bot_graphql/queries/user_joined_voice_channel_history_query.py similarity index 100% rename from kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_history_query.py rename to bot/src/bot_graphql/queries/user_joined_voice_channel_history_query.py diff --git a/kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_query.py b/bot/src/bot_graphql/queries/user_joined_voice_channel_query.py similarity index 85% rename from kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_query.py rename to bot/src/bot_graphql/queries/user_joined_voice_channel_query.py index a5465581..15a8af9c 100644 --- a/kdb-bot/src/bot_graphql/queries/user_joined_voice_channel_query.py +++ b/bot/src/bot_graphql/queries/user_joined_voice_channel_query.py @@ -2,14 +2,20 @@ from cpl_core.database.context import DatabaseContextABC from cpl_discord.service import DiscordBotServiceABC from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel -from bot_data.model.user_joined_voice_channel_history import UserJoinedVoiceChannelHistory +from bot_data.model.user_joined_voice_channel_history import ( + UserJoinedVoiceChannelHistory, +) from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC class UserJoinedVoiceChannelQuery(DataQueryWithHistoryABC): def __init__(self, bot: DiscordBotServiceABC, db: DatabaseContextABC): DataQueryWithHistoryABC.__init__( - self, "UserJoinedVoiceChannel", "UserJoinedVoiceChannelsHistory", UserJoinedVoiceChannelHistory, db + self, + "UserJoinedVoiceChannel", + "UserJoinedVoiceChannelsHistory", + UserJoinedVoiceChannelHistory, + db, ) self._bot = bot diff --git a/kdb-bot/src/bot_graphql/queries/user_query.py b/bot/src/bot_graphql/queries/user_query.py similarity index 83% rename from kdb-bot/src/bot_graphql/queries/user_query.py rename to bot/src/bot_graphql/queries/user_query.py index 9bb4a48b..a6cffa64 100644 --- a/kdb-bot/src/bot_graphql/queries/user_query.py +++ b/bot/src/bot_graphql/queries/user_query.py @@ -3,16 +3,24 @@ from cpl_discord.service import DiscordBotServiceABC from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC -from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC +from bot_data.abc.user_joined_game_server_repository_abc import ( + UserJoinedGameServerRepositoryABC, +) from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC -from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC +from bot_data.abc.user_joined_voice_channel_repository_abc import ( + UserJoinedVoiceChannelRepositoryABC, +) +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_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC from bot_graphql.filter.achievement_filter import AchievementFilter from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter -from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceChannelFilter +from bot_graphql.filter.user_joined_voice_channel_filter import ( + UserJoinedVoiceChannelFilter, +) +from bot_graphql.filter.user_warning_filter import UserWarningFilter from modules.level.service.level_service import LevelService from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -29,6 +37,7 @@ class UserQuery(DataQueryWithHistoryABC): user_joined_game_server: UserJoinedGameServerRepositoryABC, permissions: PermissionServiceABC, achievements: AchievementRepositoryABC, + user_warnings: UserWarningsRepositoryABC, ): DataQueryWithHistoryABC.__init__(self, "User", "UsersHistory", UserHistory, db) @@ -47,6 +56,7 @@ class UserQuery(DataQueryWithHistoryABC): self.set_field("xp", self.resolve_xp) self.set_field("messageCount", lambda x, *_: x.message_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("ontime", self.resolve_ontime) self.set_field("level", self.resolve_level) self.add_collection( @@ -65,7 +75,14 @@ class UserQuery(DataQueryWithHistoryABC): UserJoinedGameServerFilter, ) self.add_collection( - "achievement", lambda user, *_: achievements.get_achievements_by_user_id(user.id), AchievementFilter + "achievement", + lambda user, *_: achievements.get_achievements_by_user_id(user.id), + AchievementFilter, + ) + self.add_collection( + "userWarning", + lambda user, *_: user_warnings.get_user_warnings_by_user_id(user.id), + UserWarningFilter, ) self.set_field("server", self.resolve_server) diff --git a/bot/src/bot_graphql/queries/user_warning_history_query.py b/bot/src/bot_graphql/queries/user_warning_history_query.py new file mode 100644 index 00000000..c120e360 --- /dev/null +++ b/bot/src/bot_graphql/queries/user_warning_history_query.py @@ -0,0 +1,11 @@ +from bot_graphql.abc.history_query_abc import HistoryQueryABC + + +class UserWarningHistoryQuery(HistoryQueryABC): + def __init__(self): + HistoryQueryABC.__init__(self, "UserWarning") + + self.set_field("id", lambda x, *_: x.id) + self.set_field("user", lambda x, *_: x.user) + self.set_field("description", lambda x, *_: x.description) + self.set_field("author", lambda x, *_: x.author) diff --git a/bot/src/bot_graphql/queries/user_warning_query.py b/bot/src/bot_graphql/queries/user_warning_query.py new file mode 100644 index 00000000..f6243d5e --- /dev/null +++ b/bot/src/bot_graphql/queries/user_warning_query.py @@ -0,0 +1,17 @@ +from cpl_core.database.context import DatabaseContextABC + +from bot_data.model.user_warnings_history import UserWarningsHistory +from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC + + +class UserWarningQuery(DataQueryWithHistoryABC): + def __init__( + self, + db: DatabaseContextABC, + ): + DataQueryWithHistoryABC.__init__(self, "UserWarning", "UserWarningsHistory", UserWarningsHistory, db) + + self.set_field("id", lambda x, *_: x.id) + self.set_field("user", lambda x, *_: x.user) + self.set_field("description", lambda x, *_: x.description) + self.set_field("author", lambda x, *_: x.author) diff --git a/kdb-bot/src/bot_graphql/query.py b/bot/src/bot_graphql/query.py similarity index 80% rename from kdb-bot/src/bot_graphql/query.py rename to bot/src/bot_graphql/query.py index abde5cb0..41dafdf0 100644 --- a/kdb-bot/src/bot_graphql/query.py +++ b/bot/src/bot_graphql/query.py @@ -11,10 +11,15 @@ from bot_data.abc.level_repository_abc import LevelRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.short_role_name_repository_abc import ShortRoleNameRepositoryABC from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC -from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC +from bot_data.abc.user_joined_game_server_repository_abc import ( + UserJoinedGameServerRepositoryABC, +) from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC -from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC +from bot_data.abc.user_joined_voice_channel_repository_abc import ( + UserJoinedVoiceChannelRepositoryABC, +) from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC from bot_data.model.short_role_name_position_enum import ShortRoleNamePositionEnum from bot_graphql.abc.query_abc import QueryABC from bot_graphql.filter.achievement_filter import AchievementFilter @@ -27,7 +32,10 @@ from bot_graphql.filter.short_role_name_filter import ShortRoleNameFilter from bot_graphql.filter.user_filter import UserFilter from bot_graphql.filter.user_joined_game_server_filter import UserJoinedGameServerFilter from bot_graphql.filter.user_joined_server_filter import UserJoinedServerFilter -from bot_graphql.filter.user_joined_voice_channel_filter import UserJoinedVoiceChannelFilter +from bot_graphql.filter.user_joined_voice_channel_filter import ( + UserJoinedVoiceChannelFilter, +) +from bot_graphql.filter.user_warning_filter import UserWarningFilter from bot_graphql.model.discord import Discord from modules.achievements.achievement_service import AchievementService @@ -48,20 +56,27 @@ class Query(QueryABC): users: UserRepositoryABC, achievements: AchievementRepositoryABC, short_role_names: ShortRoleNameRepositoryABC, + user_warnings: UserWarningsRepositoryABC, achievement_service: AchievementService, technician_config: TechnicianConfigRepositoryABC, ): QueryABC.__init__(self, "Query") self.add_collection("autoRole", lambda *_: auto_roles.get_auto_roles(), AutoRoleFilter) - self.add_collection("autoRoleRule", lambda *_: auto_roles.get_auto_role_rules(), AutoRoleRuleFilter) + self.add_collection( + "autoRoleRule", + lambda *_: auto_roles.get_auto_role_rules(), + AutoRoleRuleFilter, + ) self.add_collection("client", lambda *_: clients.get_clients(), ClientFilter) self.add_collection("knownUser", lambda *_: known_users.get_users()) self.add_collection("level", lambda *_: levels.get_levels(), LevelFilter) self.add_collection("server", lambda *_: servers.get_servers(), ServerFilter) self.add_collection("gameServer", lambda *_: game_servers.get_game_servers()) self.add_collection( - "userJoinedServer", lambda *_: user_joined_servers.get_user_joined_servers(), UserJoinedServerFilter + "userJoinedServer", + lambda *_: user_joined_servers.get_user_joined_servers(), + UserJoinedServerFilter, ) self.add_collection( "userJoinedVoiceChannel", @@ -75,12 +90,25 @@ class Query(QueryABC): ) self.add_collection("user", lambda *_: users.get_users(), UserFilter) self.add_collection("achievement", lambda *_: achievements.get_achievements(), AchievementFilter) - self.add_collection("shortRoleName", lambda *_: short_role_names.get_short_role_names(), ShortRoleNameFilter) + self.add_collection( + "shortRoleName", + lambda *_: short_role_names.get_short_role_names(), + ShortRoleNameFilter, + ) + self.add_collection( + "userWarning", + lambda *_: user_warnings.get_user_warnings(), + UserWarningFilter, + ) self.set_field("technicianConfig", lambda *_: technician_config.get_technician_config()) self.set_field("achievementAttributes", lambda *_: achievement_service.get_attributes()) self.set_field("achievementOperators", lambda *_: achievement_service.get_operators()) - self.set_field("shortRoleNamePositions", lambda *_: [x.value for x in ShortRoleNamePositionEnum]) + self.set_field( + "shortRoleNamePositions", + lambda *_: [x.value for x in ShortRoleNamePositionEnum], + ) + self.set_field("possibleFeatureFlags", lambda *_: [e.value for e in FeatureFlagsEnum]) self.set_field("discord", lambda *_: Discord(bot.guilds, List(any).extend(bot.users))) diff --git a/kdb-bot/src/bot_graphql/schema.py b/bot/src/bot_graphql/schema.py similarity index 100% rename from kdb-bot/src/bot_graphql/schema.py rename to bot/src/bot_graphql/schema.py diff --git a/kdb-bot/src/modules/__init__.py b/bot/src/modules/__init__.py similarity index 100% rename from kdb-bot/src/modules/__init__.py rename to bot/src/modules/__init__.py diff --git a/kdb-bot/src/modules/achievements/__init__.py b/bot/src/modules/achievements/__init__.py similarity index 84% rename from kdb-bot/src/modules/achievements/__init__.py rename to bot/src/modules/achievements/__init__.py index 4fe7a734..865470f0 100644 --- a/kdb-bot/src/modules/achievements/__init__.py +++ b/bot/src/modules/achievements/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.achievements" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/achievements/achievement_attribute_resolver.py b/bot/src/modules/achievements/achievement_attribute_resolver.py similarity index 96% rename from kdb-bot/src/modules/achievements/achievement_attribute_resolver.py rename to bot/src/modules/achievements/achievement_attribute_resolver.py index f08f1579..66f478f8 100644 --- a/kdb-bot/src/modules/achievements/achievement_attribute_resolver.py +++ b/bot/src/modules/achievements/achievement_attribute_resolver.py @@ -7,9 +7,13 @@ from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.level_repository_abc import LevelRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC -from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC +from bot_data.abc.user_joined_game_server_repository_abc import ( + UserJoinedGameServerRepositoryABC, +) from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC -from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC +from bot_data.abc.user_joined_voice_channel_repository_abc import ( + UserJoinedVoiceChannelRepositoryABC, +) from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.user import User diff --git a/kdb-bot/src/modules/achievements/achievement_service.py b/bot/src/modules/achievements/achievement_service.py similarity index 94% rename from kdb-bot/src/modules/achievements/achievement_service.py rename to bot/src/modules/achievements/achievement_service.py index d7b2a455..39b6cd47 100644 --- a/kdb-bot/src/modules/achievements/achievement_service.py +++ b/bot/src/modules/achievements/achievement_service.py @@ -12,7 +12,9 @@ from bot_data.model.achievement import Achievement from bot_data.model.server_config import ServerConfig from bot_data.model.user import User from bot_data.model.user_got_achievement import UserGotAchievement -from modules.achievements.achievement_attribute_resolver import AchievementAttributeResolver +from modules.achievements.achievement_attribute_resolver import ( + AchievementAttributeResolver, +) from modules.achievements.model.achievement_attribute import AchievementAttribute @@ -49,10 +51,14 @@ class AchievementService: AchievementAttribute("level", lambda user: user.level, "Level"), # special cases AchievementAttribute( - "played_on_game_server", lambda user: resolver.get_played_on_game_server(user), "GameServer" + "played_on_game_server", + lambda user: resolver.get_played_on_game_server(user), + "GameServer", ), AchievementAttribute( - "last_single_ontime_hours", lambda user: resolver.get_last_ontime_hours(user), "number" + "last_single_ontime_hours", + lambda user: resolver.get_last_ontime_hours(user), + "number", ), ] ) diff --git a/kdb-bot/src/modules/achievements/achievements.json b/bot/src/modules/achievements/achievements.json similarity index 92% rename from kdb-bot/src/modules/achievements/achievements.json rename to bot/src/modules/achievements/achievements.json index 033548c6..64851517 100644 --- a/kdb-bot/src/modules/achievements/achievements.json +++ b/bot/src/modules/achievements/achievements.json @@ -3,8 +3,8 @@ "Name": "achievements", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,10 +16,10 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=1.1.7" + "cpl-core>=1.2.0" ], "DevDependencies": [ - "cpl-cli>=1.1.7" + "cpl-cli>=1.2.0" ], "PythonVersion": ">=3.10.4", "PythonPath": {}, diff --git a/kdb-bot/src/modules/achievements/achievements_module.py b/bot/src/modules/achievements/achievements_module.py similarity index 63% rename from kdb-bot/src/modules/achievements/achievements_module.py rename to bot/src/modules/achievements/achievements_module.py index 3860feac..4e1a53f4 100644 --- a/kdb-bot/src/modules/achievements/achievements_module.py +++ b/bot/src/modules/achievements/achievements_module.py @@ -6,13 +6,23 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC from bot_core.abc.module_abc import ModuleABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum -from modules.achievements.achievement_attribute_resolver import AchievementAttributeResolver +from modules.achievements.achievement_attribute_resolver import ( + AchievementAttributeResolver, +) from modules.achievements.achievement_service import AchievementService from modules.achievements.commands.achievements_group import AchievementGroup -from modules.achievements.events.achievement_on_message_event import AchievementOnMessageEvent -from modules.achievements.events.achievement_on_reaction_add_event import AchievementOnReactionAddEvent -from modules.achievements.events.achievement_on_reaction_remove_event import AchievementOnReactionRemoveEvent -from modules.achievements.events.achievement_on_voice_state_update_event import AchievementOnVoiceStateUpdateEvent +from modules.achievements.events.achievement_on_message_event import ( + AchievementOnMessageEvent, +) +from modules.achievements.events.achievement_on_reaction_add_event import ( + AchievementOnReactionAddEvent, +) +from modules.achievements.events.achievement_on_reaction_remove_event import ( + AchievementOnReactionRemoveEvent, +) +from modules.achievements.events.achievement_on_voice_state_update_event import ( + AchievementOnVoiceStateUpdateEvent, +) class AchievementsModule(ModuleABC): @@ -26,9 +36,15 @@ class AchievementsModule(ModuleABC): services.add_transient(AchievementAttributeResolver) services.add_transient(AchievementService) - self._dc.add_command(AchievementGroup) + services.add_transient(AchievementGroup) - self._dc.add_event(DiscordEventTypesEnum.on_message.value, AchievementOnMessageEvent) - self._dc.add_event(DiscordEventTypesEnum.on_reaction_add.value, AchievementOnReactionAddEvent) - self._dc.add_event(DiscordEventTypesEnum.on_reaction_remove.value, AchievementOnReactionRemoveEvent) - self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, AchievementOnVoiceStateUpdateEvent) + services.add_transient(DiscordEventTypesEnum.on_message.value, AchievementOnMessageEvent) + services.add_transient(DiscordEventTypesEnum.on_reaction_add.value, AchievementOnReactionAddEvent) + services.add_transient( + DiscordEventTypesEnum.on_reaction_remove.value, + AchievementOnReactionRemoveEvent, + ) + services.add_transient( + DiscordEventTypesEnum.on_voice_state_update.value, + AchievementOnVoiceStateUpdateEvent, + ) diff --git a/kdb-bot/src/modules/achievements/commands/__init__.py b/bot/src/modules/achievements/commands/__init__.py similarity index 84% rename from kdb-bot/src/modules/achievements/commands/__init__.py rename to bot/src/modules/achievements/commands/__init__.py index 9ad697ae..1294f61b 100644 --- a/kdb-bot/src/modules/achievements/commands/__init__.py +++ b/bot/src/modules/achievements/commands/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.achievements.commands" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/achievements/commands/achievements_group.py b/bot/src/modules/achievements/commands/achievements_group.py similarity index 100% rename from kdb-bot/src/modules/achievements/commands/achievements_group.py rename to bot/src/modules/achievements/commands/achievements_group.py diff --git a/kdb-bot/src/modules/achievements/events/__init__.py b/bot/src/modules/achievements/events/__init__.py similarity index 84% rename from kdb-bot/src/modules/achievements/events/__init__.py rename to bot/src/modules/achievements/events/__init__.py index d59751a8..a7e73387 100644 --- a/kdb-bot/src/modules/achievements/events/__init__.py +++ b/bot/src/modules/achievements/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.achievements.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_message_event.py b/bot/src/modules/achievements/events/achievement_on_message_event.py similarity index 98% rename from kdb-bot/src/modules/achievements/events/achievement_on_message_event.py rename to bot/src/modules/achievements/events/achievement_on_message_event.py index b3564ccf..fa108de3 100644 --- a/kdb-bot/src/modules/achievements/events/achievement_on_message_event.py +++ b/bot/src/modules/achievements/events/achievement_on_message_event.py @@ -35,7 +35,7 @@ class AchievementOnMessageEvent(OnMessageABC): self._servers = servers self._users = users - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_message(self, message: discord.Message): if message.guild is None: return diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_reaction_add_event.py b/bot/src/modules/achievements/events/achievement_on_reaction_add_event.py similarity index 89% rename from kdb-bot/src/modules/achievements/events/achievement_on_reaction_add_event.py rename to bot/src/modules/achievements/events/achievement_on_reaction_add_event.py index b033b534..1709f132 100644 --- a/kdb-bot/src/modules/achievements/events/achievement_on_reaction_add_event.py +++ b/bot/src/modules/achievements/events/achievement_on_reaction_add_event.py @@ -9,6 +9,7 @@ from cpl_discord.service import DiscordBotServiceABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.helper.event_checks import EventChecks from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.server_config import ServerConfig @@ -36,7 +37,12 @@ class AchievementOnReactionAddEvent(OnReactionAddABC): self._servers = servers self._users = users - async def on_reaction_add(self, reaction: discord.reaction.Reaction, user: Union[discord.Member, discord.User]): + @EventChecks.check_is_ready + async def on_reaction_add( + self, + reaction: discord.reaction.Reaction, + user: Union[discord.Member, discord.User], + ): if not isinstance(user, discord.Member): return diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py b/bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py similarity index 89% rename from kdb-bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py rename to bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py index bbb33f28..4b639f3e 100644 --- a/kdb-bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py +++ b/bot/src/modules/achievements/events/achievement_on_reaction_remove_event.py @@ -9,6 +9,7 @@ from cpl_discord.service import DiscordBotServiceABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.helper.event_checks import EventChecks from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.server_config import ServerConfig @@ -36,7 +37,12 @@ class AchievementOnReactionRemoveEvent(OnReactionRemoveABC): self._servers = servers self._users = users - async def on_reaction_remove(self, reaction: discord.reaction.Reaction, user: Union[discord.Member, discord.User]): + @EventChecks.check_is_ready + async def on_reaction_remove( + self, + reaction: discord.reaction.Reaction, + user: Union[discord.Member, discord.User], + ): if not isinstance(user, discord.Member): return diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py b/bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py similarity index 89% rename from kdb-bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py rename to bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py index 6f60e06e..57700206 100644 --- a/kdb-bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py +++ b/bot/src/modules/achievements/events/achievement_on_voice_state_update_event.py @@ -7,6 +7,7 @@ from cpl_discord.service import DiscordBotServiceABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.helper.event_checks import EventChecks from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.server_config import ServerConfig @@ -34,8 +35,12 @@ class AchievementOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): self._servers = servers self._users = users + @EventChecks.check_is_ready async def on_voice_state_update( - self, member: discord.member.Member, before: discord.member.VoiceState, after: discord.member.VoiceState + self, + member: discord.member.Member, + before: discord.member.VoiceState, + after: discord.member.VoiceState, ): if member.guild is None: return diff --git a/kdb-bot/src/modules/achievements/model/__init__.py b/bot/src/modules/achievements/model/__init__.py similarity index 84% rename from kdb-bot/src/modules/achievements/model/__init__.py rename to bot/src/modules/achievements/model/__init__.py index 1166e952..3887011a 100644 --- a/kdb-bot/src/modules/achievements/model/__init__.py +++ b/bot/src/modules/achievements/model/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.achievements.model" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/achievements/model/achievement_attribute.py b/bot/src/modules/achievements/model/achievement_attribute.py similarity index 100% rename from kdb-bot/src/modules/achievements/model/achievement_attribute.py rename to bot/src/modules/achievements/model/achievement_attribute.py diff --git a/kdb-bot/src/modules/auto_role/__init__.py b/bot/src/modules/auto_role/__init__.py similarity index 84% rename from kdb-bot/src/modules/auto_role/__init__.py rename to bot/src/modules/auto_role/__init__.py index 4d641f35..17736b45 100644 --- a/kdb-bot/src/modules/auto_role/__init__.py +++ b/bot/src/modules/auto_role/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.auto_role" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/auto_role/auto-role.json b/bot/src/modules/auto_role/auto-role.json similarity index 95% rename from kdb-bot/src/modules/auto_role/auto-role.json rename to bot/src/modules/auto_role/auto-role.json index 2a78346e..81afa64e 100644 --- a/kdb-bot/src/modules/auto_role/auto-role.json +++ b/bot/src/modules/auto_role/auto-role.json @@ -3,8 +3,8 @@ "Name": "auto-role", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/auto_role/auto_role_module.py b/bot/src/modules/auto_role/auto_role_module.py similarity index 93% rename from kdb-bot/src/modules/auto_role/auto_role_module.py rename to bot/src/modules/auto_role/auto_role_module.py index e23085f3..07eba97e 100644 --- a/kdb-bot/src/modules/auto_role/auto_role_module.py +++ b/bot/src/modules/auto_role/auto_role_module.py @@ -26,13 +26,13 @@ class AutoRoleModule(ModuleABC): def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services.add_transient(AutoRoleReactionHandler) # commands - self._dc.add_command(AutoRoleGroup) + services.add_transient(AutoRoleGroup) # events - self._dc.add_event( + services.add_transient( DiscordEventTypesEnum.on_raw_reaction_add.value, AutoRoleOnRawReactionAddEvent, ) - self._dc.add_event( + services.add_transient( DiscordEventTypesEnum.on_raw_reaction_remove.value, AutoRoleOnRawReactionRemoveEvent, ) diff --git a/kdb-bot/src/modules/auto_role/command/__init__.py b/bot/src/modules/auto_role/command/__init__.py similarity index 84% rename from kdb-bot/src/modules/auto_role/command/__init__.py rename to bot/src/modules/auto_role/command/__init__.py index 3a096291..8044c8a1 100644 --- a/kdb-bot/src/modules/auto_role/command/__init__.py +++ b/bot/src/modules/auto_role/command/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.auto_role.command" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/auto_role/command/auto_role_group.py b/bot/src/modules/auto_role/command/auto_role_group.py similarity index 98% rename from kdb-bot/src/modules/auto_role/command/auto_role_group.py rename to bot/src/modules/auto_role/command/auto_role_group.py index bf1f7758..f8d48d4e 100644 --- a/kdb-bot/src/modules/auto_role/command/auto_role_group.py +++ b/bot/src/modules/auto_role/command/auto_role_group.py @@ -61,7 +61,7 @@ class AutoRoleGroup(DiscordCommandABC): auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.id).select(lambda x: x.id) return [ app_commands.Choice(name=auto_role, value=auto_role) - for auto_role in self._client_utils.get_auto_complete_list(auto_roles, current) + for auto_role in self._client_utils.get_auto_complete_list(auto_roles, current, lambda x: x.name) ] @commands.hybrid_group(name="auto-role") @@ -245,7 +245,10 @@ class AutoRoleGroup(DiscordCommandABC): for rule in self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_from_db.id): await self._client_utils.react_to_message_by_auto_role_rule( - auto_role_from_db.discord_channel_id, auto_role_from_db.discord_message_id, rule, ctx.guild + auto_role_from_db.discord_channel_id, + auto_role_from_db.discord_message_id, + rule, + ctx.guild, ) await self._message_service.send_ctx_msg( @@ -389,7 +392,10 @@ class AutoRoleGroup(DiscordCommandABC): # as task to run in background self._bot.loop.create_task( await self._client_utils.react_to_message_by_auto_role_rule( - auto_role_from_db.discord_channel_id, auto_role_from_db.discord_message_id, rule, ctx.guild + auto_role_from_db.discord_channel_id, + auto_role_from_db.discord_message_id, + rule, + ctx.guild, ) ) diff --git a/kdb-bot/src/modules/auto_role/events/__init__.py b/bot/src/modules/auto_role/events/__init__.py similarity index 84% rename from kdb-bot/src/modules/auto_role/events/__init__.py rename to bot/src/modules/auto_role/events/__init__.py index 30f60d27..9309ac26 100644 --- a/kdb-bot/src/modules/auto_role/events/__init__.py +++ b/bot/src/modules/auto_role/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.auto_role.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py b/bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py similarity index 98% rename from kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py rename to bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py index f5d14804..61c029cf 100644 --- a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py +++ b/bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py @@ -32,7 +32,7 @@ class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC): self._auto_roles = auto_roles self._reaction_handler = reaction_handler - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_raw_reaction_add(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") diff --git a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py b/bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py similarity index 98% rename from kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py rename to bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py index a174c8f5..b26bf5fb 100644 --- a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py +++ b/bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py @@ -32,7 +32,7 @@ class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC): self._auto_roles = auto_roles self._reaction_handler = reaction_handler - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") diff --git a/kdb-bot/src/modules/auto_role/helper/__init__.py b/bot/src/modules/auto_role/helper/__init__.py similarity index 84% rename from kdb-bot/src/modules/auto_role/helper/__init__.py rename to bot/src/modules/auto_role/helper/__init__.py index 3e020087..a35ecba7 100644 --- a/kdb-bot/src/modules/auto_role/helper/__init__.py +++ b/bot/src/modules/auto_role/helper/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.auto_role.helper" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/auto_role/helper/auto_role_reaction_handler.py b/bot/src/modules/auto_role/helper/auto_role_reaction_handler.py similarity index 100% rename from kdb-bot/src/modules/auto_role/helper/auto_role_reaction_handler.py rename to bot/src/modules/auto_role/helper/auto_role_reaction_handler.py diff --git a/kdb-bot/src/modules/base/__init__.py b/bot/src/modules/base/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/__init__.py rename to bot/src/modules/base/__init__.py index 3314d082..e21909e8 100644 --- a/kdb-bot/src/modules/base/__init__.py +++ b/bot/src/modules/base/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/base/base.json b/bot/src/modules/base/base.json similarity index 95% rename from kdb-bot/src/modules/base/base.json rename to bot/src/modules/base/base.json index e7f69ff0..18cc6283 100644 --- a/kdb-bot/src/modules/base/base.json +++ b/bot/src/modules/base/base.json @@ -3,8 +3,8 @@ "Name": "base", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/base/base_module.py b/bot/src/modules/base/base_module.py similarity index 70% rename from kdb-bot/src/modules/base/base_module.py rename to bot/src/modules/base/base_module.py index 626ea4ef..fc04e55e 100644 --- a/kdb-bot/src/modules/base/base_module.py +++ b/bot/src/modules/base/base_module.py @@ -5,7 +5,9 @@ from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum from cpl_discord.service.discord_collection_abc import DiscordCollectionABC from bot_core.abc.module_abc import ModuleABC +from bot_core.abc.task_abc import TaskABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from modules.base.birthday_watcher import BirthdayWatcher from modules.base.command.afk_command import AFKCommand from modules.base.command.game_server_group import GameServerGroup from modules.base.command.help_command import HelpCommand @@ -28,7 +30,9 @@ from modules.base.events.base_on_message_delete_event import BaseOnMessageDelete from modules.base.events.base_on_message_event import BaseOnMessageEvent from modules.base.events.base_on_raw_reaction_add import BaseOnRawReactionAddEvent from modules.base.events.base_on_raw_reaction_remove import BaseOnRawReactionRemoveEvent -from modules.base.events.base_on_scheduled_event_update_event import BaseOnScheduledEventUpdateEvent +from modules.base.events.base_on_scheduled_event_update_event import ( + BaseOnScheduledEventUpdateEvent, +) from modules.base.events.base_on_voice_state_update_event import ( BaseOnVoiceStateUpdateEvent, ) @@ -56,55 +60,56 @@ class BaseModule(ModuleABC): services.add_transient(BaseReactionHandler) services.add_singleton(EventService) services.add_transient(UserWarningsService) + services.add_singleton(TaskABC, BirthdayWatcher) # forms services.add_transient(BugReportForm) services.add_transient(ComplaintForm) # commands - self._dc.add_command(AFKCommand) - self._dc.add_command(SubmitGroup) - self._dc.add_command(HelpCommand) - self._dc.add_command(InfoCommand) - self._dc.add_command(MassMoveCommand) - self._dc.add_command(PingCommand) - self._dc.add_command(PresenceCommand) - self._dc.add_command(MakeCoffeeCommand) + services.add_transient(AFKCommand) + services.add_transient(SubmitGroup) + services.add_transient(HelpCommand) + services.add_transient(InfoCommand) + services.add_transient(MassMoveCommand) + services.add_transient(PingCommand) + services.add_transient(PresenceCommand) + services.add_transient(MakeCoffeeCommand) - self._dc.add_command(PurgeCommand) - self._dc.add_command(UserGroup) - self._dc.add_command(RegisterGroup) - self._dc.add_command(UnregisterGroup) - self._dc.add_command(GameServerGroup) + services.add_transient(PurgeCommand) + services.add_transient(UserGroup) + services.add_transient(RegisterGroup) + services.add_transient(UnregisterGroup) + services.add_transient(GameServerGroup) # events - self._dc.add_event(DiscordEventTypesEnum.on_command.value, BaseOnCommandEvent) - self._dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) - self._dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) - self._dc.add_event(DiscordEventTypesEnum.on_member_remove.value, BaseOnMemberRemoveEvent) - self._dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) - self._dc.add_event(DiscordEventTypesEnum.on_message_delete.value, BaseOnMessageDeleteEvent) - self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, BaseOnRawReactionAddEvent) - self._dc.add_event( + services.add_transient(DiscordEventTypesEnum.on_command.value, BaseOnCommandEvent) + services.add_transient(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) + services.add_transient(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) + services.add_transient(DiscordEventTypesEnum.on_member_remove.value, BaseOnMemberRemoveEvent) + services.add_transient(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) + services.add_transient(DiscordEventTypesEnum.on_message_delete.value, BaseOnMessageDeleteEvent) + services.add_transient(DiscordEventTypesEnum.on_raw_reaction_add.value, BaseOnRawReactionAddEvent) + services.add_transient( DiscordEventTypesEnum.on_raw_reaction_remove.value, BaseOnRawReactionRemoveEvent, ) - self._dc.add_event( + services.add_transient( DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent, ) - self._dc.add_event( + services.add_transient( DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEventHelpChannel, ) - self._dc.add_event( + services.add_transient( DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEventScheduledEventBonus, ) - self._dc.add_event( + services.add_transient( DiscordEventTypesEnum.on_scheduled_event_update.value, BaseOnScheduledEventUpdateEvent, ) - self._dc.add_event( + services.add_transient( DiscordEventTypesEnum.on_guild_join.value, BaseOnGuildJoinEvent, ) diff --git a/bot/src/modules/base/birthday_watcher.py b/bot/src/modules/base/birthday_watcher.py new file mode 100644 index 00000000..50015415 --- /dev/null +++ b/bot/src/modules/base/birthday_watcher.py @@ -0,0 +1,68 @@ +import datetime + +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_discord.service import DiscordBotServiceABC +from cpl_translation import TranslatePipe +from discord.ext import tasks + +from bot_core.abc.task_abc import TaskABC +from bot_core.logging.task_logger import TaskLogger +from bot_core.service.message_service import MessageService +from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.model.server_config import ServerConfig + + +class BirthdayWatcher(TaskABC): + def __init__( + self, + config: ConfigurationABC, + logger: TaskLogger, + bot: DiscordBotServiceABC, + db: DatabaseContextABC, + users: UserRepositoryABC, + message_service: MessageService, + t: TranslatePipe, + ): + TaskABC.__init__(self) + + self._config = config + self._logger = logger + self._bot = bot + self._db = db + self._users = users + self._message_service = message_service + self._t = t + + if not self._is_maintenance(): + self.watch.start() + + @tasks.loop(time=datetime.time(hour=8, minute=0)) + async def watch(self): + self._logger.info(__name__, "Watching birthdays") + try: + today = datetime.date.today() + users = self._users.get_users().where(lambda x: x.birthday is not None) + for user in users: + if user.birthday.day != today.day or user.birthday.month != today.month: + continue + + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.server.discord_id}") + + user.xp += settings.xp_for_birthday + self._users.update_user(user) + self._db.save_changes() + + guild = self._bot.get_guild(user.server.discord_id) + member = guild.get_member(user.discord_id) + await self._message_service.send_channel_message( + self._bot.get_channel(settings.notification_chat_id), + self._t.transform("modules.base.user.birthday.has_birthday").format(member.mention), + is_persistent=True, + ) + except Exception as e: + self._logger.error(__name__, f"Watching birthdays failed", e) + + @watch.before_loop + async def wait(self): + await self._wait_until_ready() diff --git a/kdb-bot/src/modules/base/command/__init__.py b/bot/src/modules/base/command/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/command/__init__.py rename to bot/src/modules/base/command/__init__.py index 68f7c289..f5ed1fc1 100644 --- a/kdb-bot/src/modules/base/command/__init__.py +++ b/bot/src/modules/base/command/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base.command" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/base/command/afk_command.py b/bot/src/modules/base/command/afk_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/afk_command.py rename to bot/src/modules/base/command/afk_command.py diff --git a/kdb-bot/src/modules/base/command/game_server_group.py b/bot/src/modules/base/command/game_server_group.py similarity index 96% rename from kdb-bot/src/modules/base/command/game_server_group.py rename to bot/src/modules/base/command/game_server_group.py index b822f3de..55d235e3 100644 --- a/kdb-bot/src/modules/base/command/game_server_group.py +++ b/bot/src/modules/base/command/game_server_group.py @@ -107,7 +107,11 @@ class GameServerGroup(DiscordCommandABC): value=game_server_name, inline=True, ) - embed.add_field(name=self._t.transform("modules.base.game_server.list.api_key"), value=api_key, inline=True) + embed.add_field( + name=self._t.transform("modules.base.game_server.list.api_key"), + value=api_key, + inline=True, + ) await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait) self._logger.trace(__name__, f"Finished command game_server list") @@ -209,7 +213,11 @@ class GameServerGroup(DiscordCommandABC): description=self._t.transform("modules.base.game_server.list_members.description"), color=int("ef9d0d", 16), ) - embed.add_field(name=self._t.transform("modules.base.game_server.list_members.users"), value=users, inline=True) + embed.add_field( + name=self._t.transform("modules.base.game_server.list_members.users"), + value=users, + inline=True, + ) await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait) self._logger.trace(__name__, f"Finished command game-server remove") diff --git a/kdb-bot/src/modules/base/command/help_command.py b/bot/src/modules/base/command/help_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/help_command.py rename to bot/src/modules/base/command/help_command.py diff --git a/kdb-bot/src/modules/base/command/info_command.py b/bot/src/modules/base/command/info_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/info_command.py rename to bot/src/modules/base/command/info_command.py diff --git a/kdb-bot/src/modules/base/command/make_coffee_command.py b/bot/src/modules/base/command/make_coffee_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/make_coffee_command.py rename to bot/src/modules/base/command/make_coffee_command.py diff --git a/kdb-bot/src/modules/base/command/mass_move_command.py b/bot/src/modules/base/command/mass_move_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/mass_move_command.py rename to bot/src/modules/base/command/mass_move_command.py diff --git a/kdb-bot/src/modules/base/command/ping_command.py b/bot/src/modules/base/command/ping_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/ping_command.py rename to bot/src/modules/base/command/ping_command.py diff --git a/kdb-bot/src/modules/base/command/presence_command.py b/bot/src/modules/base/command/presence_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/presence_command.py rename to bot/src/modules/base/command/presence_command.py diff --git a/kdb-bot/src/modules/base/command/purge_command.py b/bot/src/modules/base/command/purge_command.py similarity index 100% rename from kdb-bot/src/modules/base/command/purge_command.py rename to bot/src/modules/base/command/purge_command.py diff --git a/kdb-bot/src/modules/base/command/register_group.py b/bot/src/modules/base/command/register_group.py similarity index 97% rename from kdb-bot/src/modules/base/command/register_group.py rename to bot/src/modules/base/command/register_group.py index dc3fed15..a598b31e 100644 --- a/kdb-bot/src/modules/base/command/register_group.py +++ b/bot/src/modules/base/command/register_group.py @@ -68,7 +68,8 @@ class RegisterGroup(DiscordCommandABC): response = requests.get(url=f"https://api.mojang.com/users/profiles/minecraft/{name}") if len(response.content) == 0: await self._message_service.send_interaction_msg( - ctx.interaction, self._t.transform("modules.base.register.not_found") + ctx.interaction, + self._t.transform("modules.base.register.not_found"), ) return diff --git a/kdb-bot/src/modules/base/command/submit_group.py b/bot/src/modules/base/command/submit_group.py similarity index 100% rename from kdb-bot/src/modules/base/command/submit_group.py rename to bot/src/modules/base/command/submit_group.py diff --git a/kdb-bot/src/modules/base/command/unregister_group.py b/bot/src/modules/base/command/unregister_group.py similarity index 100% rename from kdb-bot/src/modules/base/command/unregister_group.py rename to bot/src/modules/base/command/unregister_group.py diff --git a/kdb-bot/src/modules/base/command/user_group.py b/bot/src/modules/base/command/user_group.py similarity index 81% rename from kdb-bot/src/modules/base/command/user_group.py rename to bot/src/modules/base/command/user_group.py index 37570a70..4f1df692 100644 --- a/kdb-bot/src/modules/base/command/user_group.py +++ b/bot/src/modules/base/command/user_group.py @@ -1,10 +1,12 @@ -from typing import Optional, List +import datetime +from typing import Optional, List as TList import discord from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC +from cpl_query.extension import List from cpl_translation import TranslatePipe from discord import app_commands from discord.ext import commands @@ -22,6 +24,7 @@ from bot_data.abc.user_joined_voice_channel_repository_abc import ( ) from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC +from bot_data.model.server_config import ServerConfig from modules.base.service.user_warnings_service import UserWarningsService from modules.level.service.level_service import LevelService from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -73,7 +76,7 @@ class UserGroup(DiscordCommandABC): "ontime": self._t.transform("modules.base.user.atr.ontime"), } - self._atr_list = [(key, self._atr_dict[key]) for key in self._atr_dict] + self._atr_TList = [(key, self._atr_dict[key]) for key in self._atr_dict] async def _handle_atr_calc( self, @@ -116,6 +119,64 @@ class UserGroup(DiscordCommandABC): async def user(self, ctx: Context): pass + @user.command() + @commands.guild_only() + @CommandChecks.check_is_ready() + async def birthday(self, ctx: Context, day: int, month: int, year: int): + self._logger.debug( + __name__, + f"Received command user birthday {ctx}:{ctx.author},{day}:{month}:{year}", + ) + date = datetime.date(year, month, day) + server = self._servers.get_server_by_discord_id(ctx.guild.id) + user = self._users.get_user_by_discord_id_and_server_id(ctx.author.id, server.id) + user.birthday = date + self._users.update_user(user) + self._db.save_changes() + await self._message_service.send_interaction_msg( + ctx.interaction, self._t.transform("modules.base.user.birthday.success") + ) + # notify team to prevent multiple entries every day + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") + channel = ctx.guild.get_channel(settings.team_channel_id) + await self._message_service.send_channel_message( + channel, + self._t.transform("modules.base.user.birthday.success_team").format(ctx.author.mention, date), + is_persistent=True, + ) + self._logger.trace(__name__, f"Finished user-info command") + + @birthday.autocomplete("day") + async def birthday_autocomplete( + self, interaction: discord.Interaction, current: str + ) -> TList[app_commands.Choice[int]]: + days = List(int, range(0, 32)).select(lambda x: str(x)) + return [ + app_commands.Choice(name=date, value=date) + for date in self._client_utils.get_auto_complete_list(days, current) + ] + + @birthday.autocomplete("month") + async def birthday_autocomplete( + self, interaction: discord.Interaction, current: str + ) -> TList[app_commands.Choice[int]]: + days = List(int, range(0, 13)).select(lambda x: str(x)) + return [ + app_commands.Choice(name=date, value=date) + for date in self._client_utils.get_auto_complete_list(days, current) + ] + + @birthday.autocomplete("year") + async def birthday_autocomplete( + self, interaction: discord.Interaction, current: str + ) -> TList[app_commands.Choice[int]]: + today = datetime.date.today() + days = List(int, range(today.year - 75, today.year)).select(lambda x: str(x)) + return [ + app_commands.Choice(name=date, value=date) + for date in self._client_utils.get_auto_complete_list(days, current) + ] + @user.command() @commands.guild_only() @CommandChecks.check_is_ready() @@ -237,8 +298,8 @@ class UserGroup(DiscordCommandABC): ) @get.autocomplete("atr") - async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: - return [app_commands.Choice(name=value, value=key) for key, value in self._atr_list] + async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: + return [app_commands.Choice(name=value, value=key) for key, value in self._atr_TList] @user.command() @commands.guild_only() @@ -281,9 +342,9 @@ class UserGroup(DiscordCommandABC): ) @set.autocomplete("atr") - async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: - atr_list = [("xp", self._atr_dict["xp"])] - return [app_commands.Choice(name=value, value=key) for key, value in atr_list] + async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: + atr_TList = [("xp", self._atr_dict["xp"])] + return [app_commands.Choice(name=value, value=key) for key, value in atr_TList] @user.command() @commands.guild_only() @@ -294,9 +355,9 @@ class UserGroup(DiscordCommandABC): await self._handle_atr_calc(ctx, atr, value, member) @add.autocomplete("atr") - async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: - atr_list = [("xp", self._atr_dict["xp"])] - return [app_commands.Choice(name=value, value=key) for key, value in atr_list] + async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: + atr_TList = [("xp", self._atr_dict["xp"])] + return [app_commands.Choice(name=value, value=key) for key, value in atr_TList] @user.command() @commands.guild_only() @@ -307,9 +368,9 @@ class UserGroup(DiscordCommandABC): await self._handle_atr_calc(ctx, atr, value, member, is_remove=True) @remove.autocomplete("atr") - async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: - atr_list = [("xp", self._atr_dict["xp"])] - return [app_commands.Choice(name=value, value=key) for key, value in atr_list] + async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: + atr_TList = [("xp", self._atr_dict["xp"])] + return [app_commands.Choice(name=value, value=key) for key, value in atr_TList] @user.command() @commands.guild_only() @@ -349,8 +410,8 @@ class UserGroup(DiscordCommandABC): @reset.autocomplete("atr") async def reset_autocomplete( self, interaction: discord.Interaction, current: str - ) -> List[app_commands.Choice[str]]: - return [app_commands.Choice(name=value, value=key) for key, value in self._atr_list] + ) -> TList[app_commands.Choice[str]]: + return [app_commands.Choice(name=value, value=key) for key, value in self._atr_TList] @user.group() @commands.guild_only() @@ -368,7 +429,9 @@ class UserGroup(DiscordCommandABC): user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id) embed = discord.Embed( - title=member.name, description=self._t.transform("modules.base.user.atr.warnings"), color=int("ef9d0d", 16) + title=member.name, + description=self._t.transform("modules.base.user.atr.warnings"), + color=int("ef9d0d", 16), ) warnings = self._user_warnings.get_user_warnings_by_user_id(user.id) @@ -400,7 +463,7 @@ class UserGroup(DiscordCommandABC): async def add(self, ctx: Context, member: discord.Member, description: str): self._logger.debug(__name__, f"Received command user warning add {ctx}:{member},{description}") try: - await self._user_warnings_service.add_warnings(member, description, ctx.author.id) + await self._user_warnings_service.add_warnings_async(member, description, ctx.author.id) await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.base.warnings.add.success")) except Exception as e: self._logger.error(__name__, f"Adding user warning failed", e) @@ -414,7 +477,7 @@ class UserGroup(DiscordCommandABC): async def remove(self, ctx: Context, warning_id: int): self._logger.debug(__name__, f"Received command user warning remove {ctx}:{warning_id}") try: - await self._user_warnings_service.remove_warnings(warning_id) + await self._user_warnings_service.remove_warnings_async(warning_id) await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.base.warnings.remove.success")) except Exception as e: self._logger.error(__name__, f"Removing user warning failed", e) diff --git a/kdb-bot/src/modules/base/events/__init__.py b/bot/src/modules/base/events/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/events/__init__.py rename to bot/src/modules/base/events/__init__.py index 8a040853..b1bc682c 100644 --- a/kdb-bot/src/modules/base/events/__init__.py +++ b/bot/src/modules/base/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/base/events/base_on_command_error_event.py b/bot/src/modules/base/events/base_on_command_error_event.py similarity index 99% rename from kdb-bot/src/modules/base/events/base_on_command_error_event.py rename to bot/src/modules/base/events/base_on_command_error_event.py index d5aab492..d371a2aa 100644 --- a/kdb-bot/src/modules/base/events/base_on_command_error_event.py +++ b/bot/src/modules/base/events/base_on_command_error_event.py @@ -11,6 +11,7 @@ from discord.ext.commands import Context, CommandError from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.exception.check_error import CheckError +from bot_core.helper.event_checks import EventChecks from bot_data.model.technician_config import TechnicianConfig @@ -32,6 +33,7 @@ class BaseOnCommandErrorEvent(OnCommandErrorABC): self._time_format_settings = time_format_settings self._t = translate + @EventChecks.check_is_ready async def on_command_error(self, ctx: Context, error: CommandError): if isinstance(error, CheckError): return diff --git a/kdb-bot/src/modules/base/events/base_on_command_event.py b/bot/src/modules/base/events/base_on_command_event.py similarity index 97% rename from kdb-bot/src/modules/base/events/base_on_command_event.py rename to bot/src/modules/base/events/base_on_command_event.py index 407a875f..92f9c89e 100644 --- a/kdb-bot/src/modules/base/events/base_on_command_event.py +++ b/bot/src/modules/base/events/base_on_command_event.py @@ -10,6 +10,7 @@ from cpl_translation import TranslatePipe from discord.ext.commands import Context from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.helper.event_checks import EventChecks from bot_core.logging.command_logger import CommandLogger from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC @@ -78,6 +79,7 @@ class BaseOnCommandEvent(OnCommandABC): self._logger.debug(__name__, f"User {user} sent message. xp: from {old_xp} to {user.xp}") + @EventChecks.check_is_ready async def on_command(self, ctx: Context): self._logger.debug(__name__, f"Module {type(self)} started") self._logger.info(__name__, f"Received command: {ctx.command} from {ctx.channel}") diff --git a/kdb-bot/src/modules/base/events/base_on_guild_join_event.py b/bot/src/modules/base/events/base_on_guild_join_event.py similarity index 93% rename from kdb-bot/src/modules/base/events/base_on_guild_join_event.py rename to bot/src/modules/base/events/base_on_guild_join_event.py index 4a1582de..644fd194 100644 --- a/kdb-bot/src/modules/base/events/base_on_guild_join_event.py +++ b/bot/src/modules/base/events/base_on_guild_join_event.py @@ -4,6 +4,7 @@ from cpl_discord.events import OnGuildJoinABC from cpl_discord.service import DiscordBotServiceABC from discord import Guild +from bot_core.helper.event_checks import EventChecks from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.server import Server @@ -29,6 +30,7 @@ class BaseOnGuildJoinEvent(OnGuildJoinABC): self._db = db self._seeder = seeder + @EventChecks.check_is_ready async def on_guild_join(self, guild: Guild): if self._servers.find_server_by_discord_id(guild.id) is None: self._servers.add_server(Server(guild.id)) diff --git a/kdb-bot/src/modules/base/events/base_on_member_join_event.py b/bot/src/modules/base/events/base_on_member_join_event.py similarity index 98% rename from kdb-bot/src/modules/base/events/base_on_member_join_event.py rename to bot/src/modules/base/events/base_on_member_join_event.py index a09772d6..a3e9d456 100644 --- a/kdb-bot/src/modules/base/events/base_on_member_join_event.py +++ b/bot/src/modules/base/events/base_on_member_join_event.py @@ -101,9 +101,11 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC): ) self._logger.trace(__name__, f"Notified team that a member left") - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_member_join(self, member: discord.Member): self._logger.debug(__name__, f"Module {type(self)} started") + if member.bot: + return await self._client_utils.check_default_role(member) self._check_for_known_user(member) await self._add_if_not_exists_user_async(member) diff --git a/kdb-bot/src/modules/base/events/base_on_member_remove_event.py b/bot/src/modules/base/events/base_on_member_remove_event.py similarity index 98% rename from kdb-bot/src/modules/base/events/base_on_member_remove_event.py rename to bot/src/modules/base/events/base_on_member_remove_event.py index adfe7e87..c32d9be6 100644 --- a/kdb-bot/src/modules/base/events/base_on_member_remove_event.py +++ b/bot/src/modules/base/events/base_on_member_remove_event.py @@ -69,7 +69,7 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC): ) self._logger.trace(__name__, f"Notified team that a member left") - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_member_remove(self, member: discord.Member): self._logger.debug(__name__, f"Module {type(self)} started") await self._remove_user(member) diff --git a/kdb-bot/src/modules/base/events/base_on_message_delete_event.py b/bot/src/modules/base/events/base_on_message_delete_event.py similarity index 97% rename from kdb-bot/src/modules/base/events/base_on_message_delete_event.py rename to bot/src/modules/base/events/base_on_message_delete_event.py index 3d3aad1c..0dd1fa0d 100644 --- a/kdb-bot/src/modules/base/events/base_on_message_delete_event.py +++ b/bot/src/modules/base/events/base_on_message_delete_event.py @@ -6,6 +6,7 @@ from cpl_core.database.context import DatabaseContextABC from cpl_discord.events import OnMessageDeleteABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.helper.event_checks import EventChecks from bot_core.helper.log_message_helper import LogMessageHelper from bot_core.logging.message_logger import MessageLogger from bot_data.abc.client_repository_abc import ClientRepositoryABC @@ -72,6 +73,7 @@ class BaseOnMessageDeleteEvent(OnMessageDeleteABC): f"Removed message from user {user}. xp: from {old_xp} to {user.xp}", ) + @EventChecks.check_is_ready async def on_message_delete(self, message: discord.Message): self._logger.debug(__name__, f"Module {type(self)} started") if message is None or message.guild is None: diff --git a/kdb-bot/src/modules/base/events/base_on_message_event.py b/bot/src/modules/base/events/base_on_message_event.py similarity index 99% rename from kdb-bot/src/modules/base/events/base_on_message_event.py rename to bot/src/modules/base/events/base_on_message_event.py index e6531385..18ba2bb3 100644 --- a/kdb-bot/src/modules/base/events/base_on_message_event.py +++ b/bot/src/modules/base/events/base_on_message_event.py @@ -79,7 +79,7 @@ class BaseOnMessageEvent(OnMessageABC): self._logger.debug(__name__, f"User {user} sent message. xp: from {old_xp} to {user.xp}") - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_message(self, message: discord.Message): self._logger.debug(__name__, f"Module {type(self)} started") if message is None or message.guild is None: diff --git a/kdb-bot/src/modules/base/events/base_on_raw_reaction_add.py b/bot/src/modules/base/events/base_on_raw_reaction_add.py similarity index 97% rename from kdb-bot/src/modules/base/events/base_on_raw_reaction_add.py rename to bot/src/modules/base/events/base_on_raw_reaction_add.py index 4591959e..72e06099 100644 --- a/kdb-bot/src/modules/base/events/base_on_raw_reaction_add.py +++ b/bot/src/modules/base/events/base_on_raw_reaction_add.py @@ -26,7 +26,7 @@ class BaseOnRawReactionAddEvent(OnRawReactionAddABC): self._auto_roles = auto_roles self._reaction_handler = reaction_handler - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_raw_reaction_add(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") diff --git a/kdb-bot/src/modules/base/events/base_on_raw_reaction_remove.py b/bot/src/modules/base/events/base_on_raw_reaction_remove.py similarity index 97% rename from kdb-bot/src/modules/base/events/base_on_raw_reaction_remove.py rename to bot/src/modules/base/events/base_on_raw_reaction_remove.py index 9b32cbb1..273fada1 100644 --- a/kdb-bot/src/modules/base/events/base_on_raw_reaction_remove.py +++ b/bot/src/modules/base/events/base_on_raw_reaction_remove.py @@ -26,7 +26,7 @@ class BaseOnRawReactionRemoveEvent(OnRawReactionRemoveABC): self._auto_roles = auto_roles self._reaction_handler = reaction_handler - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") diff --git a/kdb-bot/src/modules/base/events/base_on_scheduled_event_update_event.py b/bot/src/modules/base/events/base_on_scheduled_event_update_event.py similarity index 95% rename from kdb-bot/src/modules/base/events/base_on_scheduled_event_update_event.py rename to bot/src/modules/base/events/base_on_scheduled_event_update_event.py index 640a9a80..25cd22fb 100644 --- a/kdb-bot/src/modules/base/events/base_on_scheduled_event_update_event.py +++ b/bot/src/modules/base/events/base_on_scheduled_event_update_event.py @@ -4,6 +4,7 @@ from cpl_discord.events.on_scheduled_event_update_abc import OnScheduledEventUpd from cpl_discord.service import DiscordBotServiceABC from discord import EventStatus +from bot_core.helper.event_checks import EventChecks from modules.base.model.active_event import ActiveEvent from modules.base.service.event_service import EventService @@ -21,6 +22,7 @@ class BaseOnScheduledEventUpdateEvent(OnScheduledEventUpdateABC): self._bot = bot self._events = events + @EventChecks.check_is_ready async def on_scheduled_event_update(self, before: discord.ScheduledEvent, after: discord.ScheduledEvent): self._logger.debug(__name__, f"Module {type(self)} started") diff --git a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py b/bot/src/modules/base/events/base_on_voice_state_update_event.py similarity index 98% rename from kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py rename to bot/src/modules/base/events/base_on_voice_state_update_event.py index 6fb0c113..7d8a2896 100644 --- a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py +++ b/bot/src/modules/base/events/base_on_voice_state_update_event.py @@ -83,7 +83,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): except Exception as e: self._logger.error(__name__, f"Ontime validation failed", e) - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_voice_state_update( self, member: discord.Member, @@ -97,6 +97,8 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): ) settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}") server = self._servers.get_server_by_discord_id(member.guild.id) + if member.bot: + return try: if before.channel == after.channel: diff --git a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py b/bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py similarity index 98% rename from kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py rename to bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py index 3e1b3da0..545620ac 100644 --- a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py +++ b/bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py @@ -42,7 +42,7 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC): ) self._logger.trace(__name__, f"Notified team that a member need help") - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_voice_state_update( self, member: discord.Member, diff --git a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py b/bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py similarity index 98% rename from kdb-bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py rename to bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py index fe5195c9..b18af00b 100644 --- a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py +++ b/bot/src/modules/base/events/base_on_voice_state_update_event_scheduled_event_bonus.py @@ -30,7 +30,7 @@ class BaseOnVoiceStateUpdateEventScheduledEventBonus(OnVoiceStateUpdateABC): self._logger.info(__name__, f"Module {type(self)} loaded") - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_voice_state_update( self, member: discord.Member, diff --git a/kdb-bot/src/modules/base/forms/__init__.py b/bot/src/modules/base/forms/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/forms/__init__.py rename to bot/src/modules/base/forms/__init__.py index ca431fb0..1c884422 100644 --- a/kdb-bot/src/modules/base/forms/__init__.py +++ b/bot/src/modules/base/forms/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base.forms" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/base/forms/bug_report_form.py b/bot/src/modules/base/forms/bug_report_form.py similarity index 100% rename from kdb-bot/src/modules/base/forms/bug_report_form.py rename to bot/src/modules/base/forms/bug_report_form.py diff --git a/kdb-bot/src/modules/base/forms/complaint_form.py b/bot/src/modules/base/forms/complaint_form.py similarity index 100% rename from kdb-bot/src/modules/base/forms/complaint_form.py rename to bot/src/modules/base/forms/complaint_form.py diff --git a/kdb-bot/src/modules/base/helper/__init__.py b/bot/src/modules/base/helper/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/helper/__init__.py rename to bot/src/modules/base/helper/__init__.py index 5cc98776..ebb8d084 100644 --- a/kdb-bot/src/modules/base/helper/__init__.py +++ b/bot/src/modules/base/helper/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base.helper" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/base/helper/base_reaction_handler.py b/bot/src/modules/base/helper/base_reaction_handler.py similarity index 100% rename from kdb-bot/src/modules/base/helper/base_reaction_handler.py rename to bot/src/modules/base/helper/base_reaction_handler.py diff --git a/kdb-bot/src/modules/base/helper/voice_channel_transformer.py b/bot/src/modules/base/helper/voice_channel_transformer.py similarity index 95% rename from kdb-bot/src/modules/base/helper/voice_channel_transformer.py rename to bot/src/modules/base/helper/voice_channel_transformer.py index a9ee5df0..a6056e58 100644 --- a/kdb-bot/src/modules/base/helper/voice_channel_transformer.py +++ b/bot/src/modules/base/helper/voice_channel_transformer.py @@ -24,7 +24,8 @@ class VoiceChannelTransformer(Transformer): voice_channels = List(discord.Role, interaction.guild.voice_channels).where(lambda x: len(x.members) > 0) return [ app_commands.Choice( - name=f"{vc.name}" if vc.category is None else f"{vc.name}: {vc.category.name}", value=vc.name + name=f"{vc.name}" if vc.category is None else f"{vc.name}: {vc.category.name}", + value=vc.name, ) for vc in get_client_utils().get_auto_complete_list(voice_channels, current, lambda x: x.name) ] diff --git a/kdb-bot/src/modules/base/model/__init__.py b/bot/src/modules/base/model/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/model/__init__.py rename to bot/src/modules/base/model/__init__.py index 53cc22a8..55bb1b35 100644 --- a/kdb-bot/src/modules/base/model/__init__.py +++ b/bot/src/modules/base/model/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base.model" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/base/model/active_event.py b/bot/src/modules/base/model/active_event.py similarity index 100% rename from kdb-bot/src/modules/base/model/active_event.py rename to bot/src/modules/base/model/active_event.py diff --git a/kdb-bot/src/modules/base/service/__init__.py b/bot/src/modules/base/service/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/service/__init__.py rename to bot/src/modules/base/service/__init__.py index d231bef4..6a949706 100644 --- a/kdb-bot/src/modules/base/service/__init__.py +++ b/bot/src/modules/base/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/base/service/event_service.py b/bot/src/modules/base/service/event_service.py similarity index 100% rename from kdb-bot/src/modules/base/service/event_service.py rename to bot/src/modules/base/service/event_service.py diff --git a/kdb-bot/src/modules/base/service/user_warnings_service.py b/bot/src/modules/base/service/user_warnings_service.py similarity index 76% rename from kdb-bot/src/modules/base/service/user_warnings_service.py rename to bot/src/modules/base/service/user_warnings_service.py index f3b0ab3f..eea9129a 100644 --- a/kdb-bot/src/modules/base/service/user_warnings_service.py +++ b/bot/src/modules/base/service/user_warnings_service.py @@ -105,10 +105,24 @@ class UserWarningsService: user.xp = 0 self._users.update_user(user) self._db.save_changes() - await self.notify_team(member, self._t.transform("modules.base.warnings.kick").format(member.mention)) + await self.notify_team( + member, + self._t.transform("modules.base.warnings.kick").format(member.mention), + ) await member.kick() - async def add_warnings(self, member: discord.Member, description: str, author_id: int = None): + async def _notify_after_add(self, member: discord.Member, warning: UserWarnings): + server = self._servers.get_server_by_discord_id(member.guild.id) + user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id) + + await self.notify_user( + member, + self._t.transform("modules.base.warnings.warned").format(warning.description), + ) + await self.notify_team(member, warning.description) + await self.check_for_warnings(member, user) + + def _add_warnings(self, member: discord.Member, description: str, author_id: int = None): server = self._servers.get_server_by_discord_id(member.guild.id) user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id) @@ -119,17 +133,35 @@ class UserWarningsService: warning = UserWarnings(description, user, author) self._warnings.add_user_warnings(warning) self._db.save_changes() - await self.notify_user(member, self._t.transform("modules.base.warnings.warned").format(warning.description)) - await self.notify_team(member, warning.description) - await self.check_for_warnings(member, user) + return warning - async def remove_warnings(self, id: int): + def add_warnings(self, member: discord.Member, description: str, author_id: int = None): + warning = self._add_warnings(member, description, author_id) + self._bot.loop.create_task(self._notify_after_add(member, warning)) + + async def add_warnings_async(self, member: discord.Member, description: str, author_id: int = None): + warning = self._add_warnings(member, description, author_id) + await self._notify_after_add(member, warning) + + async def _notify_after_remove(self, warning: UserWarnings): + guild = self._bot.get_guild(warning.user.server.discord_id) + member = guild.get_member(warning.user.discord_id) + await self.notify_user( + member, + self._t.transform("modules.base.warnings.removed").format(warning.description), + ) + await self.notify_team(member, warning.description, removed=True) + + def _remove_warnings(self, id: int): warning = self._warnings.get_user_warnings_by_id(id) self._warnings.delete_user_warnings(warning) self._db.save_changes() + return warning - guild = self._bot.get_guild(warning.user.server.discord_id) - member = guild.get_member(warning.user.discord_id) + def remove_warnings(self, id: int): + warning = self._remove_warnings(id) + self._bot.loop.create_task(self._notify_after_remove(warning)) - await self.notify_user(member, self._t.transform("modules.base.warnings.removed").format(warning.description)) - await self.notify_team(member, warning.description, removed=True) + async def remove_warnings_async(self, id: int): + warning = self._remove_warnings(id) + await self._notify_after_remove(warning) diff --git a/kdb-bot/src/modules/base/thread/__init__.py b/bot/src/modules/base/thread/__init__.py similarity index 84% rename from kdb-bot/src/modules/base/thread/__init__.py rename to bot/src/modules/base/thread/__init__.py index cc75ad70..df1ac34b 100644 --- a/kdb-bot/src/modules/base/thread/__init__.py +++ b/bot/src/modules/base/thread/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.base.thread" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/boot_log/__init__.py b/bot/src/modules/boot_log/__init__.py similarity index 84% rename from kdb-bot/src/modules/boot_log/__init__.py rename to bot/src/modules/boot_log/__init__.py index c1f30e96..f1a9cdf7 100644 --- a/kdb-bot/src/modules/boot_log/__init__.py +++ b/bot/src/modules/boot_log/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.boot_log" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/boot_log/boot-log.json b/bot/src/modules/boot_log/boot-log.json similarity index 95% rename from kdb-bot/src/modules/boot_log/boot-log.json rename to bot/src/modules/boot_log/boot-log.json index 444f31fd..4a62d1ac 100644 --- a/kdb-bot/src/modules/boot_log/boot-log.json +++ b/bot/src/modules/boot_log/boot-log.json @@ -3,8 +3,8 @@ "Name": "boot-log", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/boot_log/boot_log_extension.py b/bot/src/modules/boot_log/boot_log_extension.py similarity index 100% rename from kdb-bot/src/modules/boot_log/boot_log_extension.py rename to bot/src/modules/boot_log/boot_log_extension.py diff --git a/kdb-bot/src/modules/boot_log/boot_log_module.py b/bot/src/modules/boot_log/boot_log_module.py similarity index 91% rename from kdb-bot/src/modules/boot_log/boot_log_module.py rename to bot/src/modules/boot_log/boot_log_module.py index 94a1cc14..dde842f0 100644 --- a/kdb-bot/src/modules/boot_log/boot_log_module.py +++ b/bot/src/modules/boot_log/boot_log_module.py @@ -19,4 +19,4 @@ class BootLogModule(ModuleABC): def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): # commands # events - self._dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) + services.add_transient(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) diff --git a/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py b/bot/src/modules/boot_log/boot_log_on_ready_event.py similarity index 98% rename from kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py rename to bot/src/modules/boot_log/boot_log_on_ready_event.py index 4c8aeec7..0c5161fd 100644 --- a/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py +++ b/bot/src/modules/boot_log/boot_log_on_ready_event.py @@ -82,6 +82,6 @@ class BootLogOnReadyEvent(OnReadyABC): ) ) - self._config.add_configuration("IS_READY", "true") + self._config.add_configuration("IS_READY", True) self._logger.info(__name__, "Bot is ready") self._logger.trace(__name__, f"Module {type(self)} stopped") diff --git a/kdb-bot/src/modules/config/__init__.py b/bot/src/modules/config/__init__.py similarity index 84% rename from kdb-bot/src/modules/config/__init__.py rename to bot/src/modules/config/__init__.py index fcdb875f..af1aee22 100644 --- a/kdb-bot/src/modules/config/__init__.py +++ b/bot/src/modules/config/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.config" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/config/config.json b/bot/src/modules/config/config.json similarity index 90% rename from kdb-bot/src/modules/config/config.json rename to bot/src/modules/config/config.json index 5dcc1695..cd8a4e09 100644 --- a/kdb-bot/src/modules/config/config.json +++ b/bot/src/modules/config/config.json @@ -3,8 +3,8 @@ "Name": "config", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=1.1.7" + "cpl-core>=1.2.0" ], "DevDependencies": [ - "cpl-cli>=1.1.7" + "cpl-cli>=1.2.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/kdb-bot/src/modules/config/config_extension.py b/bot/src/modules/config/config_extension.py similarity index 95% rename from kdb-bot/src/modules/config/config_extension.py rename to bot/src/modules/config/config_extension.py index ce164180..810d2214 100644 --- a/kdb-bot/src/modules/config/config_extension.py +++ b/bot/src/modules/config/config_extension.py @@ -19,4 +19,4 @@ class ConfigExtension(ApplicationExtensionABC): logger: LoggerABC = services.get_service(LoggerABC) logger.debug(__name__, "Config extension started") config: ConfigService = services.get_service(ConfigService) - config.reload_technician_config() + await config.reload_technician_config() diff --git a/kdb-bot/src/modules/config/config_module.py b/bot/src/modules/config/config_module.py similarity index 90% rename from kdb-bot/src/modules/config/config_module.py rename to bot/src/modules/config/config_module.py index c55b62d1..14c16263 100644 --- a/kdb-bot/src/modules/config/config_module.py +++ b/bot/src/modules/config/config_module.py @@ -17,4 +17,4 @@ class ConfigModule(ModuleABC): pass def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): - self._dc.add_event(DiscordEventTypesEnum.on_ready.value, ConfigOnReadyEvent) + services.add_transient(DiscordEventTypesEnum.on_ready.value, ConfigOnReadyEvent) diff --git a/kdb-bot/src/modules/config/events/__init__.py b/bot/src/modules/config/events/__init__.py similarity index 84% rename from kdb-bot/src/modules/config/events/__init__.py rename to bot/src/modules/config/events/__init__.py index 7596e849..81b9f17e 100644 --- a/kdb-bot/src/modules/config/events/__init__.py +++ b/bot/src/modules/config/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.config.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/config/events/config_on_ready_event.py b/bot/src/modules/config/events/config_on_ready_event.py similarity index 100% rename from kdb-bot/src/modules/config/events/config_on_ready_event.py rename to bot/src/modules/config/events/config_on_ready_event.py diff --git a/kdb-bot/src/modules/config/service/__init__.py b/bot/src/modules/config/service/__init__.py similarity index 84% rename from kdb-bot/src/modules/config/service/__init__.py rename to bot/src/modules/config/service/__init__.py index 61e61e9c..049525d1 100644 --- a/kdb-bot/src/modules/config/service/__init__.py +++ b/bot/src/modules/config/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.config.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/database/__init__.py b/bot/src/modules/database/__init__.py similarity index 84% rename from kdb-bot/src/modules/database/__init__.py rename to bot/src/modules/database/__init__.py index 769f117f..fce928b7 100644 --- a/kdb-bot/src/modules/database/__init__.py +++ b/bot/src/modules/database/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.database" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/database/database.json b/bot/src/modules/database/database.json similarity index 96% rename from kdb-bot/src/modules/database/database.json rename to bot/src/modules/database/database.json index c82f9f24..3c617eb0 100644 --- a/kdb-bot/src/modules/database/database.json +++ b/bot/src/modules/database/database.json @@ -3,8 +3,8 @@ "Name": "database", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/src/modules/database/database_extension.py b/bot/src/modules/database/database_extension.py similarity index 92% rename from kdb-bot/src/modules/database/database_extension.py rename to bot/src/modules/database/database_extension.py index 1c26e70b..cdfe28fa 100644 --- a/kdb-bot/src/modules/database/database_extension.py +++ b/bot/src/modules/database/database_extension.py @@ -8,6 +8,7 @@ from cpl_core.logging import LoggerABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.environment_variables import MIGRATION_ONLY from bot_core.logging.database_logger import DatabaseLogger from bot_data.service.migration_service import MigrationService @@ -25,6 +26,6 @@ class DatabaseExtension(ApplicationExtensionABC): config.add_configuration("Database_StartTime", str(datetime.now())) migrations: MigrationService = services.get_service(MigrationService) migrations.migrate() - if config.get_configuration("MIGRATION_ONLY"): + if config.get_configuration(MIGRATION_ONLY): logger.warn(__name__, "Migrations finished. Stopping application...") sys.exit() diff --git a/kdb-bot/src/modules/database/database_module.py b/bot/src/modules/database/database_module.py similarity index 90% rename from kdb-bot/src/modules/database/database_module.py rename to bot/src/modules/database/database_module.py index cf478645..bd7c6c6f 100644 --- a/kdb-bot/src/modules/database/database_module.py +++ b/bot/src/modules/database/database_module.py @@ -19,4 +19,4 @@ class DatabaseModule(ModuleABC): def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): # commands # events - self._dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent) + services.add_transient(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent) diff --git a/kdb-bot/src/modules/database/database_on_ready_event.py b/bot/src/modules/database/database_on_ready_event.py similarity index 100% rename from kdb-bot/src/modules/database/database_on_ready_event.py rename to bot/src/modules/database/database_on_ready_event.py diff --git a/kdb-bot/src/modules/level/__init__.py b/bot/src/modules/level/__init__.py similarity index 84% rename from kdb-bot/src/modules/level/__init__.py rename to bot/src/modules/level/__init__.py index 241d5bed..9a54c17e 100644 --- a/kdb-bot/src/modules/level/__init__.py +++ b/bot/src/modules/level/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.level" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/level/command/__init__.py b/bot/src/modules/level/command/__init__.py similarity index 84% rename from kdb-bot/src/modules/level/command/__init__.py rename to bot/src/modules/level/command/__init__.py index b06b3010..f1e31901 100644 --- a/kdb-bot/src/modules/level/command/__init__.py +++ b/bot/src/modules/level/command/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.level.command" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/level/command/level_group.py b/bot/src/modules/level/command/level_group.py similarity index 100% rename from kdb-bot/src/modules/level/command/level_group.py rename to bot/src/modules/level/command/level_group.py diff --git a/bot/src/modules/level/config/default-level.development.json b/bot/src/modules/level/config/default-level.development.json new file mode 100644 index 00000000..b07cc047 --- /dev/null +++ b/bot/src/modules/level/config/default-level.development.json @@ -0,0 +1,31 @@ +{ + "DefaultLevel": { + "LevelHeader": "~~~ dev-Level ~~~", + "Levels": [ + { + "Name": "dev-Newbie", + "Color": "0x1abc9c", + "MinXp": 0, + "Permissions": 968552209984 + }, + { + "Name": "dev-Keks", + "Color": "0x2ecc71", + "MinXp": 100, + "Permissions": 1002928856640 + }, + { + "Name": "dev-Doppelkeks", + "Color": "0x3498db", + "MinXp": 200, + "Permissions": 1071849660224 + }, + { + "Name": "dev-Auror", + "Color": "0xf1c40f", + "MinXp": 300, + "Permissions": 1089042120513 + } + ] + } +} \ No newline at end of file diff --git a/bot/src/modules/level/config/default-level.edrafts-lapi.json b/bot/src/modules/level/config/default-level.edrafts-lapi.json new file mode 100644 index 00000000..dfe52d5b --- /dev/null +++ b/bot/src/modules/level/config/default-level.edrafts-lapi.json @@ -0,0 +1,31 @@ +{ + "DefaultLevel": { + "LevelHeader": "~~~ ed-Level ~~~", + "Levels": [ + { + "Name": "ed-Newbie", + "Color": "0x1abc9c", + "MinXp": 0, + "Permissions": 968552209984 + }, + { + "Name": "ed-Keks", + "Color": "0x2ecc71", + "MinXp": 100, + "Permissions": 1002928856640 + }, + { + "Name": "ed-Doppelkeks", + "Color": "0x3498db", + "MinXp": 200, + "Permissions": 1071849660224 + }, + { + "Name": "ed-Auror", + "Color": "0xf1c40f", + "MinXp": 300, + "Permissions": 1089042120513 + } + ] + } +} \ No newline at end of file diff --git a/bot/src/modules/level/config/default-level.edrafts-pc.json b/bot/src/modules/level/config/default-level.edrafts-pc.json new file mode 100644 index 00000000..dfe52d5b --- /dev/null +++ b/bot/src/modules/level/config/default-level.edrafts-pc.json @@ -0,0 +1,31 @@ +{ + "DefaultLevel": { + "LevelHeader": "~~~ ed-Level ~~~", + "Levels": [ + { + "Name": "ed-Newbie", + "Color": "0x1abc9c", + "MinXp": 0, + "Permissions": 968552209984 + }, + { + "Name": "ed-Keks", + "Color": "0x2ecc71", + "MinXp": 100, + "Permissions": 1002928856640 + }, + { + "Name": "ed-Doppelkeks", + "Color": "0x3498db", + "MinXp": 200, + "Permissions": 1071849660224 + }, + { + "Name": "ed-Auror", + "Color": "0xf1c40f", + "MinXp": 300, + "Permissions": 1089042120513 + } + ] + } +} \ No newline at end of file diff --git a/kdb-bot/src/modules/level/default-level.json b/bot/src/modules/level/config/default-level.json similarity index 100% rename from kdb-bot/src/modules/level/default-level.json rename to bot/src/modules/level/config/default-level.json diff --git a/bot/src/modules/level/config/default-level.staging.json b/bot/src/modules/level/config/default-level.staging.json new file mode 100644 index 00000000..abc65e87 --- /dev/null +++ b/bot/src/modules/level/config/default-level.staging.json @@ -0,0 +1,31 @@ +{ + "DefaultLevel": { + "LevelHeader": "~~~ test-Level ~~~", + "Levels": [ + { + "Name": "test-Newbie", + "Color": "0x1abc9c", + "MinXp": 0, + "Permissions": 968552209984 + }, + { + "Name": "test-Keks", + "Color": "0x2ecc71", + "MinXp": 100, + "Permissions": 1002928856640 + }, + { + "Name": "test-Doppelkeks", + "Color": "0x3498db", + "MinXp": 200, + "Permissions": 1071849660224 + }, + { + "Name": "test-Auror", + "Color": "0xf1c40f", + "MinXp": 300, + "Permissions": 1089042120513 + } + ] + } +} \ No newline at end of file diff --git a/kdb-bot/src/modules/level/configuration/__init__.py b/bot/src/modules/level/configuration/__init__.py similarity index 84% rename from kdb-bot/src/modules/level/configuration/__init__.py rename to bot/src/modules/level/configuration/__init__.py index d830fb2a..a7104b3f 100644 --- a/kdb-bot/src/modules/level/configuration/__init__.py +++ b/bot/src/modules/level/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.level.configuration" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/level/configuration/default_level_settings.py b/bot/src/modules/level/configuration/default_level_settings.py similarity index 100% rename from kdb-bot/src/modules/level/configuration/default_level_settings.py rename to bot/src/modules/level/configuration/default_level_settings.py diff --git a/kdb-bot/src/modules/level/events/__init__.py b/bot/src/modules/level/events/__init__.py similarity index 84% rename from kdb-bot/src/modules/level/events/__init__.py rename to bot/src/modules/level/events/__init__.py index 97ebcf9c..e6c57145 100644 --- a/kdb-bot/src/modules/level/events/__init__.py +++ b/bot/src/modules/level/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.level.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/level/events/level_on_member_join_event.py b/bot/src/modules/level/events/level_on_member_join_event.py similarity index 97% rename from kdb-bot/src/modules/level/events/level_on_member_join_event.py rename to bot/src/modules/level/events/level_on_member_join_event.py index 7113f761..38326ed3 100644 --- a/kdb-bot/src/modules/level/events/level_on_member_join_event.py +++ b/bot/src/modules/level/events/level_on_member_join_event.py @@ -17,7 +17,7 @@ class LevelOnMemberJoinEvent(OnMemberJoinABC): self._logger = logger self._level = level - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_member_join(self, member: discord.Member): self._logger.debug(__name__, f"Module {type(self)} started") server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}") diff --git a/kdb-bot/src/modules/level/events/level_on_message_event.py b/bot/src/modules/level/events/level_on_message_event.py similarity index 97% rename from kdb-bot/src/modules/level/events/level_on_message_event.py rename to bot/src/modules/level/events/level_on_message_event.py index 4c98706f..be7d4626 100644 --- a/kdb-bot/src/modules/level/events/level_on_message_event.py +++ b/bot/src/modules/level/events/level_on_message_event.py @@ -17,7 +17,7 @@ class LevelOnMessageEvent(OnMessageABC): self._logger = logger self._level = level - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_message(self, message: discord.Message): self._logger.debug(__name__, f"Module {type(self)} started") if message.guild is None: diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py b/bot/src/modules/level/events/level_on_raw_reaction_add_event.py similarity index 98% rename from kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py rename to bot/src/modules/level/events/level_on_raw_reaction_add_event.py index bffc56ef..341a0a21 100644 --- a/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py +++ b/bot/src/modules/level/events/level_on_raw_reaction_add_event.py @@ -26,7 +26,7 @@ class LevelOnRawReactionAddEvent(OnRawReactionAddABC): self._bot = bot self._level = level - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_raw_reaction_add(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py b/bot/src/modules/level/events/level_on_raw_reaction_remove_event.py similarity index 98% rename from kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py rename to bot/src/modules/level/events/level_on_raw_reaction_remove_event.py index fa94e334..1c04f19b 100644 --- a/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py +++ b/bot/src/modules/level/events/level_on_raw_reaction_remove_event.py @@ -26,7 +26,7 @@ class LevelOnRawReactionRemoveEvent(OnRawReactionRemoveABC): self._bot = bot self._level = level - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") diff --git a/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py b/bot/src/modules/level/events/level_on_voice_state_update_event.py similarity index 97% rename from kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py rename to bot/src/modules/level/events/level_on_voice_state_update_event.py index 9a0b5978..f9bb2bf2 100644 --- a/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py +++ b/bot/src/modules/level/events/level_on_voice_state_update_event.py @@ -19,7 +19,7 @@ class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): self._logger.info(__name__, f"Module {type(self)} loaded") - @EventChecks.check_is_ready() + @EventChecks.check_is_ready async def on_voice_state_update( self, member: discord.Member, diff --git a/kdb-bot/src/modules/level/level.json b/bot/src/modules/level/level.json similarity index 95% rename from kdb-bot/src/modules/level/level.json rename to bot/src/modules/level/level.json index 01ca6ac4..f4d7e68f 100644 --- a/kdb-bot/src/modules/level/level.json +++ b/bot/src/modules/level/level.json @@ -3,8 +3,8 @@ "Name": "level", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/level/level_module.py b/bot/src/modules/level/level_module.py similarity index 67% rename from kdb-bot/src/modules/level/level_module.py rename to bot/src/modules/level/level_module.py index 018377f9..4eb6d4ae 100644 --- a/kdb-bot/src/modules/level/level_module.py +++ b/bot/src/modules/level/level_module.py @@ -12,8 +12,12 @@ from bot_data.abc.data_seeder_abc import DataSeederABC from modules.level.command.level_group import LevelGroup from modules.level.events.level_on_member_join_event import LevelOnMemberJoinEvent from modules.level.events.level_on_message_event import LevelOnMessageEvent -from modules.level.events.level_on_raw_reaction_add_event import LevelOnRawReactionAddEvent -from modules.level.events.level_on_raw_reaction_remove_event import LevelOnRawReactionRemoveEvent +from modules.level.events.level_on_raw_reaction_add_event import ( + LevelOnRawReactionAddEvent, +) +from modules.level.events.level_on_raw_reaction_remove_event import ( + LevelOnRawReactionRemoveEvent, +) from modules.level.events.level_on_voice_state_update_event import ( LevelOnVoiceStateUpdateEvent, ) @@ -28,7 +32,9 @@ class LevelModule(ModuleABC): def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): cwd = env.working_directory env.set_working_directory(os.path.dirname(os.path.realpath(__file__))) - config.add_json_file(f"default-level.json", optional=False) + config.add_json_file(f"config/default-level.json", optional=False) + config.add_json_file(f"config/default-level.{env.environment_name}.json", optional=True) + config.add_json_file(f"config/default-level.{env.host_name}.json", optional=True) env.set_working_directory(cwd) def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): @@ -36,14 +42,17 @@ class LevelModule(ModuleABC): services.add_transient(LevelService) # commands - self._dc.add_command(LevelGroup) + services.add_transient(LevelGroup) # events - self._dc.add_event(DiscordEventTypesEnum.on_message.value, LevelOnMessageEvent) - self._dc.add_event( + services.add_transient(DiscordEventTypesEnum.on_message.value, LevelOnMessageEvent) + services.add_transient( DiscordEventTypesEnum.on_voice_state_update.value, LevelOnVoiceStateUpdateEvent, ) - self._dc.add_event(DiscordEventTypesEnum.on_member_join.value, LevelOnMemberJoinEvent) - self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, LevelOnRawReactionAddEvent) - self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, LevelOnRawReactionRemoveEvent) + services.add_transient(DiscordEventTypesEnum.on_member_join.value, LevelOnMemberJoinEvent) + services.add_transient(DiscordEventTypesEnum.on_raw_reaction_add.value, LevelOnRawReactionAddEvent) + services.add_transient( + DiscordEventTypesEnum.on_raw_reaction_remove.value, + LevelOnRawReactionRemoveEvent, + ) diff --git a/kdb-bot/src/modules/level/level_seeder.py b/bot/src/modules/level/level_seeder.py similarity index 100% rename from kdb-bot/src/modules/level/level_seeder.py rename to bot/src/modules/level/level_seeder.py diff --git a/kdb-bot/src/modules/level/service/__init__.py b/bot/src/modules/level/service/__init__.py similarity index 84% rename from kdb-bot/src/modules/level/service/__init__.py rename to bot/src/modules/level/service/__init__.py index 6c623e08..cda7dc5f 100644 --- a/kdb-bot/src/modules/level/service/__init__.py +++ b/bot/src/modules/level/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.level.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/level/service/level_service.py b/bot/src/modules/level/service/level_service.py similarity index 100% rename from kdb-bot/src/modules/level/service/level_service.py rename to bot/src/modules/level/service/level_service.py diff --git a/kdb-bot/src/modules/permission/__init__.py b/bot/src/modules/permission/__init__.py similarity index 84% rename from kdb-bot/src/modules/permission/__init__.py rename to bot/src/modules/permission/__init__.py index f722d617..a0fc4fc7 100644 --- a/kdb-bot/src/modules/permission/__init__.py +++ b/bot/src/modules/permission/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.permission" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/permission/abc/__init__.py b/bot/src/modules/permission/abc/__init__.py similarity index 84% rename from kdb-bot/src/modules/permission/abc/__init__.py rename to bot/src/modules/permission/abc/__init__.py index f527d830..6379f88e 100644 --- a/kdb-bot/src/modules/permission/abc/__init__.py +++ b/bot/src/modules/permission/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.permission.abc" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/permission/abc/permission_service_abc.py b/bot/src/modules/permission/abc/permission_service_abc.py similarity index 100% rename from kdb-bot/src/modules/permission/abc/permission_service_abc.py rename to bot/src/modules/permission/abc/permission_service_abc.py diff --git a/kdb-bot/src/modules/permission/permission.json b/bot/src/modules/permission/permission.json similarity index 95% rename from kdb-bot/src/modules/permission/permission.json rename to bot/src/modules/permission/permission.json index 2ea792a8..3a708347 100644 --- a/kdb-bot/src/modules/permission/permission.json +++ b/bot/src/modules/permission/permission.json @@ -3,8 +3,8 @@ "Name": "permission", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/permission/permission_module.py b/bot/src/modules/permission/permission_module.py similarity index 100% rename from kdb-bot/src/modules/permission/permission_module.py rename to bot/src/modules/permission/permission_module.py diff --git a/kdb-bot/src/modules/permission/service/__init__.py b/bot/src/modules/permission/service/__init__.py similarity index 84% rename from kdb-bot/src/modules/permission/service/__init__.py rename to bot/src/modules/permission/service/__init__.py index 7518517d..db82db07 100644 --- a/kdb-bot/src/modules/permission/service/__init__.py +++ b/bot/src/modules/permission/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.permission.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/permission/service/permission_service.py b/bot/src/modules/permission/service/permission_service.py similarity index 100% rename from kdb-bot/src/modules/permission/service/permission_service.py rename to bot/src/modules/permission/service/permission_service.py diff --git a/kdb-bot/src/modules/short_role_name/__init__.py b/bot/src/modules/short_role_name/__init__.py similarity index 84% rename from kdb-bot/src/modules/short_role_name/__init__.py rename to bot/src/modules/short_role_name/__init__.py index 349e00ae..46278ac8 100644 --- a/kdb-bot/src/modules/short_role_name/__init__.py +++ b/bot/src/modules/short_role_name/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.short_role_name" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/short_role_name/events/__init__.py b/bot/src/modules/short_role_name/events/__init__.py similarity index 85% rename from kdb-bot/src/modules/short_role_name/events/__init__.py rename to bot/src/modules/short_role_name/events/__init__.py index 500818f9..eb81e544 100644 --- a/kdb-bot/src/modules/short_role_name/events/__init__.py +++ b/bot/src/modules/short_role_name/events/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.short_role_name.events" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/short_role_name/events/short_role_name_on_member_update_event.py b/bot/src/modules/short_role_name/events/short_role_name_on_member_update_event.py similarity index 87% rename from kdb-bot/src/modules/short_role_name/events/short_role_name_on_member_update_event.py rename to bot/src/modules/short_role_name/events/short_role_name_on_member_update_event.py index 6b942ed1..92b9a08e 100644 --- a/kdb-bot/src/modules/short_role_name/events/short_role_name_on_member_update_event.py +++ b/bot/src/modules/short_role_name/events/short_role_name_on_member_update_event.py @@ -1,6 +1,7 @@ import discord from cpl_discord.events import OnMemberUpdateABC +from bot_core.helper.event_checks import EventChecks from modules.short_role_name.service.short_role_name_service import ShortRoleNameService @@ -9,6 +10,7 @@ class ShortRoleNameOnMemberUpdateEvent(OnMemberUpdateABC): OnMemberUpdateABC.__init__(self) self._service = service + @EventChecks.check_is_ready async def on_member_update(self, before: discord.member.Member, after: discord.member.Member): if before.roles != after.roles or before.name != after.name: await self._service.check_short_role_names(after) diff --git a/kdb-bot/src/modules/short_role_name/service/__init__.py b/bot/src/modules/short_role_name/service/__init__.py similarity index 85% rename from kdb-bot/src/modules/short_role_name/service/__init__.py rename to bot/src/modules/short_role_name/service/__init__.py index 4f98c6a7..c5716cd3 100644 --- a/kdb-bot/src/modules/short_role_name/service/__init__.py +++ b/bot/src/modules/short_role_name/service/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.short_role_name.service" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/short_role_name/service/short_role_name_service.py b/bot/src/modules/short_role_name/service/short_role_name_service.py similarity index 100% rename from kdb-bot/src/modules/short_role_name/service/short_role_name_service.py rename to bot/src/modules/short_role_name/service/short_role_name_service.py diff --git a/kdb-bot/src/modules/short_role_name/short-role-name.json b/bot/src/modules/short_role_name/short-role-name.json similarity index 88% rename from kdb-bot/src/modules/short_role_name/short-role-name.json rename to bot/src/modules/short_role_name/short-role-name.json index 3cc5cce9..805e3d18 100644 --- a/kdb-bot/src/modules/short_role_name/short-role-name.json +++ b/bot/src/modules/short_role_name/short-role-name.json @@ -2,8 +2,8 @@ "ProjectSettings": { "Name": "short-role-name", "Version": { - "Major": "0", - "Minor": "0", + "Major": "1", + "Minor": "2", "Micro": "0" }, "Author": "", @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2023.4.0.post5" + "cpl-core>=1.2.0" ], "DevDependencies": [ - "cpl-cli>=2023.4.0.post3" + "cpl-cli>=1.2.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/kdb-bot/src/modules/short_role_name/short_role_name_check_command.py b/bot/src/modules/short_role_name/short_role_name_check_command.py similarity index 100% rename from kdb-bot/src/modules/short_role_name/short_role_name_check_command.py rename to bot/src/modules/short_role_name/short_role_name_check_command.py diff --git a/kdb-bot/src/modules/short_role_name/short_role_name_module.py b/bot/src/modules/short_role_name/short_role_name_module.py similarity index 81% rename from kdb-bot/src/modules/short_role_name/short_role_name_module.py rename to bot/src/modules/short_role_name/short_role_name_module.py index 3a413eb1..19b732fe 100644 --- a/kdb-bot/src/modules/short_role_name/short_role_name_module.py +++ b/bot/src/modules/short_role_name/short_role_name_module.py @@ -7,9 +7,13 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC from bot_core.abc.module_abc import ModuleABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_data.abc.data_seeder_abc import DataSeederABC -from modules.short_role_name.events.short_role_name_on_member_update_event import ShortRoleNameOnMemberUpdateEvent +from modules.short_role_name.events.short_role_name_on_member_update_event import ( + ShortRoleNameOnMemberUpdateEvent, +) from modules.short_role_name.service.short_role_name_service import ShortRoleNameService -from modules.short_role_name.short_role_name_check_command import ShortRoleNameCheckCommand +from modules.short_role_name.short_role_name_check_command import ( + ShortRoleNameCheckCommand, +) from modules.short_role_name.short_role_name_seeder import ShortRoleNameSeeder @@ -25,6 +29,9 @@ class ShortRoleNameModule(ModuleABC): services.add_transient(ShortRoleNameService) # commands - self._dc.add_command(ShortRoleNameCheckCommand) + services.add_transient(ShortRoleNameCheckCommand) # events - self._dc.add_event(DiscordEventTypesEnum.on_member_update.value, ShortRoleNameOnMemberUpdateEvent) + services.add_transient( + DiscordEventTypesEnum.on_member_update.value, + ShortRoleNameOnMemberUpdateEvent, + ) diff --git a/kdb-bot/src/modules/short_role_name/short_role_name_seeder.py b/bot/src/modules/short_role_name/short_role_name_seeder.py similarity index 100% rename from kdb-bot/src/modules/short_role_name/short_role_name_seeder.py rename to bot/src/modules/short_role_name/short_role_name_seeder.py diff --git a/bot/src/modules/special_offers/__init__.py b/bot/src/modules/special_offers/__init__.py new file mode 100644 index 00000000..2470352b --- /dev/null +++ b/bot/src/modules/special_offers/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot sh-edraft.de Discord bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for customers of sh-edraft.de + +:copyright: (c) 2022 - 2023 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = "modules.special_offers" +__author__ = "Sven Heidemann" +__license__ = "MIT" +__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" +__version__ = "1.2.0" + +from collections import namedtuple + + +# imports + +VersionInfo = namedtuple("VersionInfo", "major minor micro") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/bot/src/modules/special_offers/special-offers.json b/bot/src/modules/special_offers/special-offers.json new file mode 100644 index 00000000..9d35ce51 --- /dev/null +++ b/bot/src/modules/special_offers/special-offers.json @@ -0,0 +1,46 @@ +{ + "ProjectSettings": { + "Name": "steam-special-offers", + "Version": { + "Major": "1", + "Minor": "2", + "Micro": "0" + }, + "Author": "", + "AuthorEmail": "", + "Description": "", + "LongDescription": "", + "URL": "", + "CopyrightDate": "", + "CopyrightName": "", + "LicenseName": "", + "LicenseDescription": "", + "Dependencies": [ + "cpl-core>=1.2.0" + ], + "DevDependencies": [ + "cpl-cli>=1.2.0" + ], + "PythonVersion": ">=3.10.4", + "PythonPath": { + "linux": "" + }, + "Classifiers": [] + }, + "BuildSettings": { + "ProjectType": "library", + "SourcePath": "", + "OutputPath": "../../dist", + "Main": "steam_special_offers.main", + "EntryPoint": "steam-special-offers", + "IncludePackageData": false, + "Included": [], + "Excluded": [ + "*/__pycache__", + "*/logs", + "*/tests" + ], + "PackageData": {}, + "ProjectReferences": [] + } +} \ No newline at end of file diff --git a/bot/src/modules/special_offers/special_offers_module.py b/bot/src/modules/special_offers/special_offers_module.py new file mode 100644 index 00000000..e64108b5 --- /dev/null +++ b/bot/src/modules/special_offers/special_offers_module.py @@ -0,0 +1,22 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceCollectionABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_discord.service.discord_collection_abc import DiscordCollectionABC + +from bot_core.abc.module_abc import ModuleABC +from bot_core.abc.task_abc import TaskABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from modules.special_offers.steam_offer_watcher import SteamOfferWatcher + + +class SteamSpecialOffersModule(ModuleABC): + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, FeatureFlagsEnum.steam_special_offers_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): + services.add_singleton(TaskABC, SteamOfferWatcher) + # commands + # events diff --git a/bot/src/modules/special_offers/steam_offer_watcher.py b/bot/src/modules/special_offers/steam_offer_watcher.py new file mode 100644 index 00000000..d2af2b4d --- /dev/null +++ b/bot/src/modules/special_offers/steam_offer_watcher.py @@ -0,0 +1,220 @@ +import asyncio +import datetime + +import bs4 +import discord +import requests +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_discord.service import DiscordBotServiceABC +from cpl_query.extension import List +from cpl_translation import TranslatePipe +from discord.ext import tasks + +from bot_core.abc.task_abc import TaskABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.logging.task_logger import TaskLogger +from bot_core.service.message_service import MessageService +from bot_data.abc.steam_special_offer_repository_abc import ( + SteamSpecialOfferRepositoryABC, +) +from bot_data.model.server_config import ServerConfig +from bot_data.model.steam_special_offer import SteamSpecialOffer +from bot_data.model.technician_config import TechnicianConfig + + +class SteamOfferWatcher(TaskABC): + def __init__( + self, + config: ConfigurationABC, + bot: DiscordBotServiceABC, + logger: TaskLogger, + db: DatabaseContextABC, + offers: SteamSpecialOfferRepositoryABC, + message_service: MessageService, + t: TranslatePipe, + tech_config: TechnicianConfig, + ): + TaskABC.__init__(self) + + self._config = config + self._logger = logger + self._db = db + self._offers = offers + self._bot = bot + self._message_service = message_service + self._t = t + self._tech_config = tech_config + + self._is_new = False + self._urls = {} + self._image_urls = {} + + if not self._is_maintenance(): + self.watch.start() + + @staticmethod + def _get_max_count() -> int: + count = 0 + result = requests.get(f"https://store.steampowered.com/search/results?specials=1") + soup = bs4.BeautifulSoup(result.text, "lxml") + element = soup.find_all("div", {"class": "search_results_count"}) + if len(element) < 1: + return count + + count = int(element[0].contents[0].split(" ")[0].replace(",", "")) + + return count + + def _get_games_from_page(self, start: int, count: int) -> List[SteamSpecialOffer]: + games = List(SteamSpecialOffer) + result = requests.get( + f"https://store.steampowered.com/search/results?query&start={start}&count={count}&force_infinite=1&specials=1&filter=topsellers" + ) + soup = bs4.BeautifulSoup(result.text, "lxml") + elements = soup.find_all("a", {"class": "search_result_row"}) + if len(elements) < 1: + return games + + for element in elements: + name_element = element.find("span", {"class": "title"}) + original_price_element = element.find("div", {"class": "discount_original_price"}) + discount_element = element.find("div", {"class": "discount_pct"}) + discount_price_element = element.find("div", {"class": "discount_final_price"}) + + if ( + name_element is None + or len(name_element.contents) < 1 + or original_price_element is None + or len(original_price_element.contents) < 1 + or discount_element is None + or len(discount_element.contents) < 1 + or discount_price_element is None + or len(discount_price_element.contents) < 1 + ): + continue + + name = name_element.contents[0].replace("'", "`").replace('"', "`") + original_price = float( + original_price_element.contents[0].replace(" ", "").replace("€", "").replace(",", ".") + ) + discount = int(discount_element.contents[0].replace("%", "")) + discount_price = float( + discount_price_element.contents[0].replace(" ", "").replace("€", "").replace(",", ".") + ) + games.add(SteamSpecialOffer(name, original_price, discount_price, discount)) + self._urls[name] = element.attrs["href"] + self._image_urls[name] = element.find("div", {"class": "search_capsule"}).find("img").attrs["src"] + + return games + + def _get_new_game_offers(self) -> List[SteamSpecialOffer]: + new_offers = List(SteamSpecialOffer) + + sale_count = self._tech_config.max_steam_offer_count + # todo: let admins change the value + self._logger.debug(__name__, f"Get special offers from 0 to {sale_count}") + for i in range(0, sale_count, 100): + if i > sale_count: + break + new_offers.extend(self._get_games_from_page(i, 100)) + + self._logger.debug(__name__, f"Got {new_offers.count()} offers") + + return new_offers + + async def _send_embed_for_offer(self, offer: SteamSpecialOffer, channel_id: int) -> discord.Embed: + embed = discord.Embed( + title=offer.name, + url=self._urls[offer.name], + color=int("ef9d0d", 16), + timestamp=datetime.datetime.now(), + ) + + embed.add_field( + name=self._t.transform("modules.special_offers.price"), + value=f"~~{offer.original_price}€~~", + inline=True, + ) + embed.add_field( + name=self._t.transform("modules.special_offers.discount"), + value=f"{offer.discount_pct}%", + inline=True, + ) + embed.add_field( + name=self._t.transform("modules.special_offers.discount_price"), + value=f"{offer.discount_price}€", + inline=True, + ) + + embed.set_image(url=self._image_urls[offer.name]) + + await self._message_service.send_channel_message( + self._bot.get_channel(channel_id), + embed, + is_persistent=True, + ) + + def _watch(self) -> List[SteamSpecialOffer]: + self._is_new = self._offers.get_steam_special_offers().count() == 0 + new_offers = self._get_new_game_offers() + new_offers_names = new_offers.select(lambda x: x.name).to_list() + + old_offers = self._offers.get_steam_special_offers() + old_offers_names = old_offers.select(lambda x: x.name).to_list() + + offers_for_notifications = List(SteamSpecialOffer) + + for offer in old_offers: + offer: SteamSpecialOffer = offer + if offer.name in new_offers_names: + continue + + self._offers.delete_steam_special_offer(offer) + self._db.save_changes() + + for offer in new_offers: + if offer.name in old_offers_names: + self._offers.update_steam_special_offer(offer) + self._db.save_changes() + continue + + self._offers.add_steam_special_offer(offer) + self._db.save_changes() + offers_for_notifications.add(offer) + + self._logger.trace(__name__, "Finished watching") + return offers_for_notifications + + @tasks.loop(hours=4) + async def watch(self): + self._logger.info(__name__, "Watching steam special offers") + try: + offers_for_notifications = self._watch() + self._logger.debug( + __name__, + f"Sending offer notifications for {offers_for_notifications.count()} offers", + ) + if self._is_new: + return + for guild in self._bot.guilds: + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}") + if ( + not FeatureFlagsSettings.get_flag_from_dict( + settings.feature_flags, FeatureFlagsEnum.steam_special_offers + ) + or settings.game_offer_notification_chat_id is None + ): + continue + + for offer in offers_for_notifications: + self._bot.loop.create_task( + self._send_embed_for_offer(offer, settings.game_offer_notification_chat_id) + ) + except Exception as e: + self._logger.error(__name__, f"Steam offer watcher failed", e) + + @watch.before_loop + async def wait(self): + await self._wait_until_ready() diff --git a/kdb-bot/src/modules/technician/__init__.py b/bot/src/modules/technician/__init__.py similarity index 84% rename from kdb-bot/src/modules/technician/__init__.py rename to bot/src/modules/technician/__init__.py index 09303612..7e184291 100644 --- a/kdb-bot/src/modules/technician/__init__.py +++ b/bot/src/modules/technician/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.technician" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/technician/api_key_seeder.py b/bot/src/modules/technician/api_key_seeder.py similarity index 100% rename from kdb-bot/src/modules/technician/api_key_seeder.py rename to bot/src/modules/technician/api_key_seeder.py diff --git a/kdb-bot/src/modules/technician/command/__init__.py b/bot/src/modules/technician/command/__init__.py similarity index 84% rename from kdb-bot/src/modules/technician/command/__init__.py rename to bot/src/modules/technician/command/__init__.py index 7317fca2..ef7939c0 100644 --- a/kdb-bot/src/modules/technician/command/__init__.py +++ b/bot/src/modules/technician/command/__init__.py @@ -15,7 +15,7 @@ __title__ = "modules.technician.command" __author__ = "Sven Heidemann" __license__ = "MIT" __copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.1.10" +__version__ = "1.2.0" from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="1", micro="10") +version_info = VersionInfo(major="1", minor="2", micro="0") diff --git a/kdb-bot/src/modules/technician/command/api_key_group.py b/bot/src/modules/technician/command/api_key_group.py similarity index 100% rename from kdb-bot/src/modules/technician/command/api_key_group.py rename to bot/src/modules/technician/command/api_key_group.py diff --git a/kdb-bot/src/modules/technician/command/log_command.py b/bot/src/modules/technician/command/log_command.py similarity index 100% rename from kdb-bot/src/modules/technician/command/log_command.py rename to bot/src/modules/technician/command/log_command.py diff --git a/kdb-bot/src/modules/technician/command/restart_command.py b/bot/src/modules/technician/command/restart_command.py similarity index 100% rename from kdb-bot/src/modules/technician/command/restart_command.py rename to bot/src/modules/technician/command/restart_command.py diff --git a/kdb-bot/src/modules/technician/command/shutdown_command.py b/bot/src/modules/technician/command/shutdown_command.py similarity index 100% rename from kdb-bot/src/modules/technician/command/shutdown_command.py rename to bot/src/modules/technician/command/shutdown_command.py diff --git a/kdb-bot/src/modules/technician/command/sync_xp_command.py b/bot/src/modules/technician/command/sync_xp_command.py similarity index 98% rename from kdb-bot/src/modules/technician/command/sync_xp_command.py rename to bot/src/modules/technician/command/sync_xp_command.py index e54a770f..a14bd8ac 100644 --- a/kdb-bot/src/modules/technician/command/sync_xp_command.py +++ b/bot/src/modules/technician/command/sync_xp_command.py @@ -129,7 +129,7 @@ class SyncXpGroup(DiscordCommandABC): other_server = self._servers.get_server_by_id(server_id) user = self._users.get_user_by_discord_id_and_server_id( - self._servers.get_server_by_discord_id(ctx.guild.id).id, member.id + member.id, self._servers.get_server_by_discord_id(ctx.guild.id).id ) try: diff --git a/kdb-bot/src/modules/technician/technician.json b/bot/src/modules/technician/technician.json similarity index 95% rename from kdb-bot/src/modules/technician/technician.json rename to bot/src/modules/technician/technician.json index 7ae46664..24080baa 100644 --- a/kdb-bot/src/modules/technician/technician.json +++ b/bot/src/modules/technician/technician.json @@ -3,8 +3,8 @@ "Name": "technician", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "", "AuthorEmail": "", diff --git a/kdb-bot/src/modules/technician/technician_module.py b/bot/src/modules/technician/technician_module.py similarity index 84% rename from kdb-bot/src/modules/technician/technician_module.py rename to bot/src/modules/technician/technician_module.py index 5d5472ba..8550b7d6 100644 --- a/kdb-bot/src/modules/technician/technician_module.py +++ b/bot/src/modules/technician/technician_module.py @@ -24,9 +24,9 @@ class TechnicianModule(ModuleABC): def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services.add_transient(DataSeederABC, ApiKeySeeder) # commands - self._dc.add_command(RestartCommand) - self._dc.add_command(ShutdownCommand) - self._dc.add_command(LogCommand) - self._dc.add_command(ApiKeyGroup) - self._dc.add_command(SyncXpGroup) + services.add_transient(RestartCommand) + services.add_transient(ShutdownCommand) + services.add_transient(LogCommand) + services.add_transient(ApiKeyGroup) + services.add_transient(SyncXpGroup) # events diff --git a/kdb-bot/tools/checks/UserJoinedVoiceChannel.json b/bot/tools/checks/UserJoinedVoiceChannel.json similarity index 100% rename from kdb-bot/tools/checks/UserJoinedVoiceChannel.json rename to bot/tools/checks/UserJoinedVoiceChannel.json diff --git a/kdb-bot/tools/checks/__init__.py b/bot/tools/checks/__init__.py similarity index 100% rename from kdb-bot/tools/checks/__init__.py rename to bot/tools/checks/__init__.py diff --git a/kdb-bot/tools/checks/checks.json b/bot/tools/checks/checks.json similarity index 96% rename from kdb-bot/tools/checks/checks.json rename to bot/tools/checks/checks.json index 295f0a4b..c95779e7 100644 --- a/kdb-bot/tools/checks/checks.json +++ b/bot/tools/checks/checks.json @@ -3,8 +3,8 @@ "Name": "checks", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/tools/checks/get_ontime_overlaps.py b/bot/tools/checks/get_ontime_overlaps.py similarity index 100% rename from kdb-bot/tools/checks/get_ontime_overlaps.py rename to bot/tools/checks/get_ontime_overlaps.py diff --git a/kdb-bot/tools/get_version/__init__.py b/bot/tools/get_version/__init__.py similarity index 100% rename from kdb-bot/tools/get_version/__init__.py rename to bot/tools/get_version/__init__.py diff --git a/kdb-bot/tools/get_version/application.py b/bot/tools/get_version/application.py similarity index 100% rename from kdb-bot/tools/get_version/application.py rename to bot/tools/get_version/application.py diff --git a/kdb-bot/tools/get_version/get-version.json b/bot/tools/get_version/get-version.json similarity index 96% rename from kdb-bot/tools/get_version/get-version.json rename to bot/tools/get_version/get-version.json index 0c0aacb6..bf6aa56f 100644 --- a/kdb-bot/tools/get_version/get-version.json +++ b/bot/tools/get_version/get-version.json @@ -3,8 +3,8 @@ "Name": "get-version", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/tools/get_version/main.py b/bot/tools/get_version/main.py similarity index 100% rename from kdb-bot/tools/get_version/main.py rename to bot/tools/get_version/main.py diff --git a/kdb-bot/tools/get_version/startup.py b/bot/tools/get_version/startup.py similarity index 100% rename from kdb-bot/tools/get_version/startup.py rename to bot/tools/get_version/startup.py diff --git a/kdb-bot/tools/post_build/__init__.py b/bot/tools/post_build/__init__.py similarity index 100% rename from kdb-bot/tools/post_build/__init__.py rename to bot/tools/post_build/__init__.py diff --git a/kdb-bot/tools/post_build/application.py b/bot/tools/post_build/application.py similarity index 100% rename from kdb-bot/tools/post_build/application.py rename to bot/tools/post_build/application.py diff --git a/kdb-bot/tools/post_build/appsettings.json b/bot/tools/post_build/appsettings.json similarity index 100% rename from kdb-bot/tools/post_build/appsettings.json rename to bot/tools/post_build/appsettings.json diff --git a/kdb-bot/tools/post_build/main.py b/bot/tools/post_build/main.py similarity index 100% rename from kdb-bot/tools/post_build/main.py rename to bot/tools/post_build/main.py diff --git a/kdb-bot/tools/post_build/post-build.json b/bot/tools/post_build/post-build.json similarity index 96% rename from kdb-bot/tools/post_build/post-build.json rename to bot/tools/post_build/post-build.json index f499bc71..97cd72d1 100644 --- a/kdb-bot/tools/post_build/post-build.json +++ b/bot/tools/post_build/post-build.json @@ -3,8 +3,8 @@ "Name": "post-build", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/tools/post_build/post_build_settings.py b/bot/tools/post_build/post_build_settings.py similarity index 100% rename from kdb-bot/tools/post_build/post_build_settings.py rename to bot/tools/post_build/post_build_settings.py diff --git a/kdb-bot/tools/post_build/service/__init__.py b/bot/tools/post_build/service/__init__.py similarity index 100% rename from kdb-bot/tools/post_build/service/__init__.py rename to bot/tools/post_build/service/__init__.py diff --git a/kdb-bot/tools/post_build/service/dependencies.py b/bot/tools/post_build/service/dependencies.py similarity index 100% rename from kdb-bot/tools/post_build/service/dependencies.py rename to bot/tools/post_build/service/dependencies.py diff --git a/kdb-bot/tools/post_build/service/remove_config.py b/bot/tools/post_build/service/remove_config.py similarity index 100% rename from kdb-bot/tools/post_build/service/remove_config.py rename to bot/tools/post_build/service/remove_config.py diff --git a/kdb-bot/tools/post_build/startup.py b/bot/tools/post_build/startup.py similarity index 100% rename from kdb-bot/tools/post_build/startup.py rename to bot/tools/post_build/startup.py diff --git a/kdb-bot/tools/set_version/__init__.py b/bot/tools/set_version/__init__.py similarity index 100% rename from kdb-bot/tools/set_version/__init__.py rename to bot/tools/set_version/__init__.py diff --git a/kdb-bot/tools/set_version/application.py b/bot/tools/set_version/application.py similarity index 92% rename from kdb-bot/tools/set_version/application.py rename to bot/tools/set_version/application.py index 92055455..882d819a 100644 --- a/kdb-bot/tools/set_version/application.py +++ b/bot/tools/set_version/application.py @@ -57,7 +57,9 @@ class Application(ApplicationABC): try: if branch.startswith("#"): self._configuration.add_json_file( - self._workspace.projects[self._workspace.default_project], optional=False, output=False + self._workspace.projects[self._workspace.default_project], + optional=False, + output=False, ) ps: ProjectSettings = self._configuration.get_configuration(ProjectSettings) @@ -111,10 +113,16 @@ class Application(ApplicationABC): Console.write_line(f"Set dependencies {self._version_pipe.transform(version)} for {project}") self._version_setter.set_dependencies( - self._workspace.projects[project], version, "Dependencies", skipped=skipped + self._workspace.projects[project], + version, + "Dependencies", + skipped=skipped, ) self._version_setter.set_dependencies( - self._workspace.projects[project], version, "DevDependencies", skipped=skipped + self._workspace.projects[project], + version, + "DevDependencies", + skipped=skipped, ) Console.write_line(f"Set version {self._version_pipe.transform(version)} for {project}") diff --git a/kdb-bot/tools/set_version/git_service.py b/bot/tools/set_version/git_service.py similarity index 100% rename from kdb-bot/tools/set_version/git_service.py rename to bot/tools/set_version/git_service.py diff --git a/kdb-bot/tools/set_version/main.py b/bot/tools/set_version/main.py similarity index 100% rename from kdb-bot/tools/set_version/main.py rename to bot/tools/set_version/main.py diff --git a/kdb-bot/tools/set_version/set-version.json b/bot/tools/set_version/set-version.json similarity index 96% rename from kdb-bot/tools/set_version/set-version.json rename to bot/tools/set_version/set-version.json index 6ea92728..0c2e47ff 100644 --- a/kdb-bot/tools/set_version/set-version.json +++ b/bot/tools/set_version/set-version.json @@ -3,8 +3,8 @@ "Name": "set-version", "Version": { "Major": "1", - "Minor": "1", - "Micro": "10" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/kdb-bot/tools/set_version/startup.py b/bot/tools/set_version/startup.py similarity index 100% rename from kdb-bot/tools/set_version/startup.py rename to bot/tools/set_version/startup.py diff --git a/kdb-bot/tools/set_version/version_setter_service.py b/bot/tools/set_version/version_setter_service.py similarity index 92% rename from kdb-bot/tools/set_version/version_setter_service.py rename to bot/tools/set_version/version_setter_service.py index e1dfcf8a..af019658 100644 --- a/kdb-bot/tools/set_version/version_setter_service.py +++ b/bot/tools/set_version/version_setter_service.py @@ -55,7 +55,10 @@ class VersionSetterService: continue new_deps.append( - dependency.replace(dep_version, f'{version["Major"]}.{version["Minor"]}.{version["Micro"]}') + dependency.replace( + dep_version, + f'{version["Major"]}.{version["Minor"]}.{version["Micro"]}', + ) ) project_json["ProjectSettings"][key] = new_deps diff --git a/kdb-bot/docker b/kdb-bot/docker deleted file mode 160000 index 7ae47838..00000000 --- a/kdb-bot/docker +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7ae4783874d5aa8015d8f0da2c19c293fcd72762 diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config deleted file mode 160000 index 23eafb2e..00000000 --- a/kdb-bot/src/bot/config +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 23eafb2e211241acbbc52833d139c67f1ecc69f5 diff --git a/kdb-bot/src/bot_api/config b/kdb-bot/src/bot_api/config deleted file mode 160000 index b6ffed4d..00000000 --- a/kdb-bot/src/bot_api/config +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b6ffed4da1f75f5fbad1ce7f312b67f32de010b5 diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/users.sql b/kdb-bot/src/bot_data/migration/db_history_scripts/users.sql deleted file mode 100644 index 8dfebf63..00000000 --- a/kdb-bot/src/bot_data/migration/db_history_scripts/users.sql +++ /dev/null @@ -1,46 +0,0 @@ -ALTER TABLE `Users` - CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6); - -ALTER TABLE `Users` - CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6); - -CREATE TABLE IF NOT EXISTS `UsersHistory` -( - `Id` BIGINT(20) NOT NULL, - `DiscordId` BIGINT(20) NOT NULL, - `XP` BIGINT(20) NOT NULL DEFAULT 0, - `ServerId` BIGINT(20) DEFAULT NULL, - `Deleted` BOOL DEFAULT FALSE, - `DateFrom` DATETIME(6) NOT NULL, - `DateTo` DATETIME(6) NOT NULL -); - -DROP TRIGGER IF EXISTS `TR_UsersUpdate`; - -CREATE TRIGGER `TR_UsersUpdate` - AFTER UPDATE - ON `Users` - FOR EACH ROW -BEGIN - INSERT INTO `UsersHistory` ( - `Id`, `DiscordId`, `XP`, `ServerId`, `DateFrom`, `DateTo` - ) - VALUES ( - OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6) - ); -END; - -DROP TRIGGER IF EXISTS `TR_UsersDelete`; - -CREATE TRIGGER `TR_UsersDelete` - AFTER DELETE - ON `Users` - FOR EACH ROW -BEGIN - INSERT INTO `UsersHistory` ( - `Id`, `DiscordId`, `XP`, `ServerId`, `Deleted`, `DateFrom`, `DateTo` - ) - VALUES ( - OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6) - ); -END; \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/mutations/user_mutation.py b/kdb-bot/src/bot_graphql/mutations/user_mutation.py deleted file mode 100644 index 9cd71438..00000000 --- a/kdb-bot/src/bot_graphql/mutations/user_mutation.py +++ /dev/null @@ -1,53 +0,0 @@ -from cpl_core.database.context import DatabaseContextABC -from cpl_discord.service import DiscordBotServiceABC - -from bot_data.abc.level_repository_abc import LevelRepositoryABC -from bot_data.abc.server_repository_abc import ServerRepositoryABC -from bot_data.abc.user_repository_abc import UserRepositoryABC -from bot_data.model.user_role_enum import UserRoleEnum -from bot_graphql.abc.query_abc import QueryABC -from modules.level.service.level_service import LevelService -from modules.permission.service.permission_service import PermissionService - - -class UserMutation(QueryABC): - def __init__( - self, - servers: ServerRepositoryABC, - users: UserRepositoryABC, - bot: DiscordBotServiceABC, - db: DatabaseContextABC, - permissions: PermissionService, - levels: LevelRepositoryABC, - level_service: LevelService, - ): - QueryABC.__init__(self, "UserMutation") - - self._servers = servers - self._users = users - self._bot = bot - self._db = db - self._permissions = permissions - self._levels = levels - self._level_service = level_service - - self.set_field("updateUser", self.resolve_update_user) - - def resolve_update_user(self, *_, input: dict): - user = self._users.get_user_by_id(input["id"]) - self._can_user_mutate_data(user.server, UserRoleEnum.moderator) - - new_xp = None - if "levelId" in input: - level = self._levels.get_level_by_id(input["levelId"]) - if user.level.id != level.id: - new_xp = level.min_xp - - user.xp = new_xp if new_xp is not None else input["xp"] if "xp" in input else user.xp - - self._users.update_user(user) - self._db.save_changes() - self._bot.loop.create_task(self._level_service.set_level(user)) - - user = self._users.get_user_by_id(input["id"]) - return user diff --git a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html b/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html deleted file mode 100644 index 5d9f5912..00000000 --- a/kdb-web/src/app/modules/view/server/levels/components/levels/levels.component.html +++ /dev/null @@ -1,226 +0,0 @@ -