diff --git a/kdb-bot/cpl-workspace.json b/kdb-bot/cpl-workspace.json index ed99de6618..7af45bfebe 100644 --- a/kdb-bot/cpl-workspace.json +++ b/kdb-bot/cpl-workspace.json @@ -10,6 +10,7 @@ "base": "src/modules/base/base.json", "boot-log": "src/modules/boot_log/boot-log.json", "database": "src/modules/database/database.json", + "level": "src/modules/level/level.json", "moderator": "src/modules/moderator/moderator.json", "permission": "src/modules/permission/permission.json", "bot-api": "src/bot_api/bot-api.json", @@ -18,7 +19,6 @@ "set-version": "tools/set_version/set-version.json" }, "Scripts": { - "sv": "cpl set-version", "set-version": "cpl run set-version $ARGS; echo '';", @@ -30,8 +30,10 @@ "pre-prod": "cpl build", "prod": "export KDB_ENVIRONMENT=production; export KDB_NAME=KDB-Prod; cpl start;", + "pre-stage": "cpl build", "stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;", + "pre-dev": "cpl build", "dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;", diff --git a/kdb-bot/src/bot/__init__.py b/kdb-bot/src/bot/__init__.py index 69dfae3aa8..9184f6b955 100644 --- a/kdb-bot/src/bot/__init__.py +++ b/kdb-bot/src/bot/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index 36270e64d3..db8ef6fe92 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -4,7 +4,7 @@ "Version": { "Major": "0", "Minor": "3", - "Micro": "dev70" + "Micro": "dev25" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -60,6 +60,7 @@ "../modules/base/base.json", "../modules/boot_log/boot-log.json", "../modules/database/database.json", + "../modules/level/level.json", "../modules/moderator/moderator.json", "../modules/permission/permission.json" ] diff --git a/kdb-bot/src/bot/config/appsettings.edrafts-pc.json b/kdb-bot/src/bot/config/appsettings.edrafts-pc.json index 2e9e52a3d7..e912b14863 100644 --- a/kdb-bot/src/bot/config/appsettings.edrafts-pc.json +++ b/kdb-bot/src/bot/config/appsettings.edrafts-pc.json @@ -8,7 +8,7 @@ "LoggingSettings": { "Path": "logs/", "Filename": "bot.log", - "ConsoleLogLevel": "TRACE", + "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" }, "BotLoggingSettings": { @@ -76,7 +76,12 @@ }, "BootLog": { "910199451145076828": { - "LoginMessageChannelId": "910199452915093588" + "LoginMessageChannelId": 910199452915093588 + } + }, + "Level": { + "910199451145076828": { + "ChangedLevelNotificationChannelId": 910199452667637892 } }, "Permission": { diff --git a/kdb-bot/src/bot/config/feature-flags.json b/kdb-bot/src/bot/config/feature-flags.json index 68bf6e002c..da07fa2398 100644 --- a/kdb-bot/src/bot/config/feature-flags.json +++ b/kdb-bot/src/bot/config/feature-flags.json @@ -1,6 +1,6 @@ { "FeatureFlags": { - "ApiModule": true, + "ApiModule": false, "AdminModule": true, "AutoRoleModule": true, "BaseModule": true, @@ -9,6 +9,7 @@ "CoreExtensionModule": true, "DatabaseModule": true, "ModeratorModule": true, + "LevelModule": true, "PermissionModule": true, "PresenceModule": true } diff --git a/kdb-bot/src/bot/module_list.py b/kdb-bot/src/bot/module_list.py index b818ad4bcd..03b8307cda 100644 --- a/kdb-bot/src/bot/module_list.py +++ b/kdb-bot/src/bot/module_list.py @@ -9,6 +9,7 @@ from modules.auto_role.auto_role_module import AutoRoleModule from modules.base.base_module import BaseModule from modules.boot_log.boot_log_module import BootLogModule from modules.database.database_module import DatabaseModule +from modules.level.level_module import LevelModule from modules.moderator.moderator_module import ModeratorModule from modules.permission.permission_module import PermissionModule @@ -25,6 +26,7 @@ class ModuleList: AutoRoleModule, BaseModule, DatabaseModule, + LevelModule, ModeratorModule, PermissionModule, ApiModule, diff --git a/kdb-bot/src/bot/startup_migration_extension.py b/kdb-bot/src/bot/startup_migration_extension.py index 62d4d39d85..a5d75b6dca 100644 --- a/kdb-bot/src/bot/startup_migration_extension.py +++ b/kdb-bot/src/bot/startup_migration_extension.py @@ -7,6 +7,7 @@ from bot_data.abc.migration_abc import MigrationABC from bot_data.migration.api_migration import ApiMigration from bot_data.migration.auto_role_migration import AutoRoleMigration from bot_data.migration.initial_migration import InitialMigration +from bot_data.migration.level_migration import LevelMigration from bot_data.service.migration_service import MigrationService @@ -23,3 +24,4 @@ class StartupMigrationExtension(StartupExtensionABC): services.add_transient(MigrationABC, InitialMigration) services.add_transient(MigrationABC, AutoRoleMigration) # 03.10.2022 #54 - 0.2.2 services.add_transient(MigrationABC, ApiMigration) # 15.10.2022 #70 - 0.3.0 + services.add_transient(MigrationABC, LevelMigration) # 06.11.2022 #25 - 0.3.0 diff --git a/kdb-bot/src/bot/startup_settings_extension.py b/kdb-bot/src/bot/startup_settings_extension.py index 4dcee8bf4d..655ccd7b6c 100644 --- a/kdb-bot/src/bot/startup_settings_extension.py +++ b/kdb-bot/src/bot/startup_settings_extension.py @@ -11,6 +11,7 @@ from bot_core.configuration.bot_logging_settings import BotLoggingSettings from bot_core.configuration.bot_settings import BotSettings from modules.base.configuration.base_settings import BaseSettings from modules.boot_log.configuration.boot_log_settings import BootLogSettings +from modules.level.configuration.level_settings import LevelSettings from modules.permission.configuration.permission_settings import PermissionSettings @@ -35,6 +36,7 @@ class StartupSettingsExtension(StartupExtensionABC): self._configure_settings_with_sub_settings(configuration, BotSettings, lambda x: x.servers, lambda x: x.id) self._configure_settings_with_sub_settings(configuration, BaseSettings, lambda x: x.servers, lambda x: x.id) self._configure_settings_with_sub_settings(configuration, BootLogSettings, lambda x: x.servers, lambda x: x.id) + self._configure_settings_with_sub_settings(configuration, LevelSettings, lambda x: x.servers, lambda x: x.id) self._configure_settings_with_sub_settings(configuration, PermissionSettings, lambda x: x.servers, lambda x: x.id) self._configure_settings_with_sub_settings(configuration, BotLoggingSettings, lambda x: x.files, lambda x: x.key) diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 206df3ea17..447b232e4c 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -149,6 +149,9 @@ "boot_log": { "login_message": "Ich bin on the line :D\nDer Scheiß hat {} Sekunden gedauert" }, + "level": { + "new_level_message": "<@{}> ist nun Level {}" + }, "database": {}, "permission": { } diff --git a/kdb-bot/src/bot_api/__init__.py b/kdb-bot/src/bot_api/__init__.py index 3b884c17ab..c2ec271ab4 100644 --- a/kdb-bot/src/bot_api/__init__.py +++ b/kdb-bot/src/bot_api/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/abc/__init__.py b/kdb-bot/src/bot_api/abc/__init__.py index 93c7c132eb..20368eb69a 100644 --- a/kdb-bot/src/bot_api/abc/__init__.py +++ b/kdb-bot/src/bot_api/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/configuration/__init__.py b/kdb-bot/src/bot_api/configuration/__init__.py index e6ba2a1ba8..ab482a2816 100644 --- a/kdb-bot/src/bot_api/configuration/__init__.py +++ b/kdb-bot/src/bot_api/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/controller/__init__.py b/kdb-bot/src/bot_api/controller/__init__.py index 3a46a81cba..122f580c77 100644 --- a/kdb-bot/src/bot_api/controller/__init__.py +++ b/kdb-bot/src/bot_api/controller/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.controller' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/controller/discord/__init__.py b/kdb-bot/src/bot_api/controller/discord/__init__.py index a23ef46015..975b9cff5c 100644 --- a/kdb-bot/src/bot_api/controller/discord/__init__.py +++ b/kdb-bot/src/bot_api/controller/discord/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.controller.discord' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/event/__init__.py b/kdb-bot/src/bot_api/event/__init__.py index 7a717ae74a..23b33965cc 100644 --- a/kdb-bot/src/bot_api/event/__init__.py +++ b/kdb-bot/src/bot_api/event/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.event' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/exception/__init__.py b/kdb-bot/src/bot_api/exception/__init__.py index d23b0c2237..a8c5329d0e 100644 --- a/kdb-bot/src/bot_api/exception/__init__.py +++ b/kdb-bot/src/bot_api/exception/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.exception' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/filter/__init__.py b/kdb-bot/src/bot_api/filter/__init__.py index 800e73009a..8dc3d9742e 100644 --- a/kdb-bot/src/bot_api/filter/__init__.py +++ b/kdb-bot/src/bot_api/filter/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.filter' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/filter/discord/__init__.py b/kdb-bot/src/bot_api/filter/discord/__init__.py index cb6b161f2a..d228164ff0 100644 --- a/kdb-bot/src/bot_api/filter/discord/__init__.py +++ b/kdb-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 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/logging/__init__.py b/kdb-bot/src/bot_api/logging/__init__.py index 7877e2bb00..24cc8ae16c 100644 --- a/kdb-bot/src/bot_api/logging/__init__.py +++ b/kdb-bot/src/bot_api/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.logging' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/model/__init__.py b/kdb-bot/src/bot_api/model/__init__.py index bf076571f6..be2392ef04 100644 --- a/kdb-bot/src/bot_api/model/__init__.py +++ b/kdb-bot/src/bot_api/model/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.model' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/model/discord/__init__.py b/kdb-bot/src/bot_api/model/discord/__init__.py index 9e0ec39b52..667ceb2a96 100644 --- a/kdb-bot/src/bot_api/model/discord/__init__.py +++ b/kdb-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 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/route/__init__.py b/kdb-bot/src/bot_api/route/__init__.py index f781f96da8..230ae05d39 100644 --- a/kdb-bot/src/bot_api/route/__init__.py +++ b/kdb-bot/src/bot_api/route/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.route' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/service/__init__.py b/kdb-bot/src/bot_api/service/__init__.py index ae381d3d93..d6b86d11b2 100644 --- a/kdb-bot/src/bot_api/service/__init__.py +++ b/kdb-bot/src/bot_api/service/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_api/transformer/__init__.py b/kdb-bot/src/bot_api/transformer/__init__.py index 0dc9db2a45..50cc9ad57c 100644 --- a/kdb-bot/src/bot_api/transformer/__init__.py +++ b/kdb-bot/src/bot_api/transformer/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_api.transformer' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/__init__.py b/kdb-bot/src/bot_core/__init__.py index 178a3f4eda..bc622310bc 100644 --- a/kdb-bot/src/bot_core/__init__.py +++ b/kdb-bot/src/bot_core/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/abc/__init__.py b/kdb-bot/src/bot_core/abc/__init__.py index a388e22a50..4056210a9a 100644 --- a/kdb-bot/src/bot_core/abc/__init__.py +++ b/kdb-bot/src/bot_core/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/configuration/__init__.py b/kdb-bot/src/bot_core/configuration/__init__.py index 6dbe179135..8e677c73a5 100644 --- a/kdb-bot/src/bot_core/configuration/__init__.py +++ b/kdb-bot/src/bot_core/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/configuration/feature_flags_enum.py b/kdb-bot/src/bot_core/configuration/feature_flags_enum.py index b41ec6e53e..226ca1d8e0 100644 --- a/kdb-bot/src/bot_core/configuration/feature_flags_enum.py +++ b/kdb-bot/src/bot_core/configuration/feature_flags_enum.py @@ -13,6 +13,7 @@ class FeatureFlagsEnum(Enum): core_extension_module = 'CoreExtensionModule' data_module = 'DataModule', database_module = 'DatabaseModule', + level_module = 'LevelModule' moderator_module = 'ModeratorModule' permission_module = 'PermissionModule' # features diff --git a/kdb-bot/src/bot_core/core_extension/__init__.py b/kdb-bot/src/bot_core/core_extension/__init__.py index 09f8f2371f..a107f3d828 100644 --- a/kdb-bot/src/bot_core/core_extension/__init__.py +++ b/kdb-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 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/events/__init__.py b/kdb-bot/src/bot_core/events/__init__.py index 885b39c3ac..b73ac3fb7f 100644 --- a/kdb-bot/src/bot_core/events/__init__.py +++ b/kdb-bot/src/bot_core/events/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core.events' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/helper/__init__.py b/kdb-bot/src/bot_core/helper/__init__.py index 1b4972d082..0f0edc20ad 100644 --- a/kdb-bot/src/bot_core/helper/__init__.py +++ b/kdb-bot/src/bot_core/helper/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core.helper' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/logging/__init__.py b/kdb-bot/src/bot_core/logging/__init__.py index eb87740c37..ba6fe7adc3 100644 --- a/kdb-bot/src/bot_core/logging/__init__.py +++ b/kdb-bot/src/bot_core/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core.logging' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/pipes/__init__.py b/kdb-bot/src/bot_core/pipes/__init__.py index 1cad1f886e..85c44be76b 100644 --- a/kdb-bot/src/bot_core/pipes/__init__.py +++ b/kdb-bot/src/bot_core/pipes/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core.pipes' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/service/__init__.py b/kdb-bot/src/bot_core/service/__init__.py index a5c0718e8a..1266f4f1ea 100644 --- a/kdb-bot/src/bot_core/service/__init__.py +++ b/kdb-bot/src/bot_core/service/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_core.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_core/service/message_service.py b/kdb-bot/src/bot_core/service/message_service.py index 7094236d8b..6a43f32cc6 100644 --- a/kdb-bot/src/bot_core/service/message_service.py +++ b/kdb-bot/src/bot_core/service/message_service.py @@ -49,7 +49,7 @@ class MessageService(MessageServiceABC): self._db.save_changes() self._logger.info(__name__, f'Deleted message {message}') - async def send_channel_message(self, channel: discord.TextChannel, message: Union[str, discord.Embed], without_tracking=False): + async def send_channel_message(self, channel: discord.TextChannel, message: Union[str, discord.Embed], is_persistent: bool = False, wait_before_delete: int = None, without_tracking=False): self._logger.debug(__name__, f'Try to send message\n\t{message}\n\tto: {channel}') msg = None try: @@ -64,6 +64,13 @@ class MessageService(MessageServiceABC): if not without_tracking: self._clients.append_sent_message_count(self._bot.user.id, channel.guild.id, 1) self._db.save_changes() + + if wait_before_delete is not None: + await asyncio.sleep(wait_before_delete) + + if is_persistent: + return + await self.delete_message(msg, without_tracking) async def send_dm_message(self, message: Union[str, discord.Embed], receiver: Union[discord.User, discord.Member], without_tracking=False): diff --git a/kdb-bot/src/bot_data/__init__.py b/kdb-bot/src/bot_data/__init__.py index cf89c13c97..5a1acbdfa4 100644 --- a/kdb-bot/src/bot_data/__init__.py +++ b/kdb-bot/src/bot_data/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_data' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_data/abc/__init__.py b/kdb-bot/src/bot_data/abc/__init__.py index 1e3d6dcf60..7209be452e 100644 --- a/kdb-bot/src/bot_data/abc/__init__.py +++ b/kdb-bot/src/bot_data/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_data.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_data/abc/data_seeder_abc.py b/kdb-bot/src/bot_data/abc/data_seeder_abc.py new file mode 100644 index 0000000000..a4fecdd77e --- /dev/null +++ b/kdb-bot/src/bot_data/abc/data_seeder_abc.py @@ -0,0 +1,10 @@ +from abc import ABC, abstractmethod + + +class DataSeederABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + def seed(self): pass diff --git a/kdb-bot/src/bot_data/abc/level_repository_abc.py b/kdb-bot/src/bot_data/abc/level_repository_abc.py new file mode 100644 index 0000000000..89a2a67f55 --- /dev/null +++ b/kdb-bot/src/bot_data/abc/level_repository_abc.py @@ -0,0 +1,36 @@ +from abc import ABC, abstractmethod +from typing import Optional + +from cpl_query.extension import List + +from bot_data.model.level import Level + + +class LevelRepositoryABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + def get_levels(self) -> List[Level]: pass + + @abstractmethod + def get_level_by_id(self, id: int) -> Level: pass + + @abstractmethod + def find_level_by_id(self, id: int) -> Optional[Level]: pass + + @abstractmethod + def get_levels_by_server_id(self, server_id: int) -> List[Level]: pass + + @abstractmethod + def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]: pass + + @abstractmethod + def add_level(self, level: Level): pass + + @abstractmethod + def update_level(self, level: Level): pass + + @abstractmethod + def delete_level(self, level: Level): pass diff --git a/kdb-bot/src/bot_data/data_module.py b/kdb-bot/src/bot_data/data_module.py index 7537b6f282..0668bffed8 100644 --- a/kdb-bot/src/bot_data/data_module.py +++ b/kdb-bot/src/bot_data/data_module.py @@ -9,6 +9,7 @@ from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.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_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC @@ -17,6 +18,8 @@ from bot_data.service.auth_user_repository_service import AuthUserRepositoryServ from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService from bot_data.service.client_repository_service import ClientRepositoryService from bot_data.service.known_user_repository_service import KnownUserRepositoryService +from bot_data.service.level_repository_service import LevelRepositoryService +from bot_data.service.seeder_service import SeederService from bot_data.service.server_repository_service import ServerRepositoryService from bot_data.service.user_joined_server_repository_service import UserJoinedServerRepositoryService from bot_data.service.user_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService @@ -40,3 +43,6 @@ class DataModule(ModuleABC): services.add_transient(UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService) services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService) services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService) + services.add_transient(LevelRepositoryABC, LevelRepositoryService) + + services.add_transient(SeederService) diff --git a/kdb-bot/src/bot_data/migration/__init__.py b/kdb-bot/src/bot_data/migration/__init__.py index b716abf99d..ed8bf58fd9 100644 --- a/kdb-bot/src/bot_data/migration/__init__.py +++ b/kdb-bot/src/bot_data/migration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_data.migration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_data/migration/level_migration.py b/kdb-bot/src/bot_data/migration/level_migration.py new file mode 100644 index 0000000000..5b1dbc0fc3 --- /dev/null +++ b/kdb-bot/src/bot_data/migration/level_migration.py @@ -0,0 +1,37 @@ +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.migration_abc import MigrationABC +from bot_data.db_context import DBContext + + +class LevelMigration(MigrationABC): + name = '0.3_LevelMigration' + + 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 `Levels` ( + `Id` BIGINT NOT NULL AUTO_INCREMENT, + `Name` VARCHAR(255) NOT NULL, + `Color` VARCHAR(8) NOT NULL, + `MinXp` BIGINT NOT NULL, + `PermissionInt` BIGINT NOT NULL, + `ServerId` BIGINT, + `CreatedAt` DATETIME(6), + `LastModifiedAt` DATETIME(6), + PRIMARY KEY(`Id`), + FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`) + ); + """) + ) + + def downgrade(self): + self._cursor.execute('DROP TABLE `Levels`;') + diff --git a/kdb-bot/src/bot_data/model/__init__.py b/kdb-bot/src/bot_data/model/__init__.py index 562dec8460..0c33f8c760 100644 --- a/kdb-bot/src/bot_data/model/__init__.py +++ b/kdb-bot/src/bot_data/model/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_data.model' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_data/model/level.py b/kdb-bot/src/bot_data/model/level.py new file mode 100644 index 0000000000..9cfc63f179 --- /dev/null +++ b/kdb-bot/src/bot_data/model/level.py @@ -0,0 +1,119 @@ +from datetime import datetime +from typing import Optional +from cpl_core.database import TableABC + +from bot_data.model.server import Server + + +class Level(TableABC): + + def __init__(self, name: str, color: str, min_xp: int, permissions: int, server: Optional[Server], created_at: datetime = None, modified_at: datetime = None, id=0): + self._id = id + self._name = name + self._color = color + self._min_xp = min_xp + self._permissions = permissions + self._server = server + + TableABC.__init__(self) + self._created_at = created_at if created_at is not None else self._created_at + self._modified_at = modified_at if modified_at is not None else self._modified_at + + @property + def id(self) -> int: + return self._id + + @property + def name(self) -> str: + return self._name + + @name.setter + def name(self, value: str): + self._name = value + + @property + def color(self) -> str: + return self._color + + @color.setter + def color(self, value: str): + self._color = value + + @property + def min_xp(self) -> int: + return self._min_xp + + @min_xp.setter + def min_xp(self, value: int): + self._min_xp = value + + @property + def permissions(self) -> int: + return self._permissions + + @permissions.setter + def permissions(self, value: int): + self._permissions = value + + @property + def server(self) -> Server: + return self._server + + @server.setter + def server(self, value: Server): + self._server = value + + @staticmethod + def get_select_all_string() -> str: + return str(f""" + SELECT * FROM `Levels`; + """) + + @staticmethod + def get_select_by_id_string(id: int) -> str: + return str(f""" + SELECT * FROM `Levels` + WHERE `Id` = {id}; + """) + + @staticmethod + def get_select_by_server_id_string(s_id: int) -> str: + return str(f""" + SELECT * FROM `Levels` + WHERE `ServerId` = {s_id}; + """) + + @property + def insert_string(self) -> str: + return str(f""" + INSERT INTO `Levels` ( + `Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `CreatedAt`, `LastModifiedAt` + ) VALUES ( + '{self._name}', + '{self._color}', + {self._min_xp}, + {self._permissions}, + {self._server.server_id}, + '{self._created_at}', + '{self._modified_at}' + ); + """) + + @property + def udpate_string(self) -> str: + return str(f""" + UPDATE `Levels` + SET `Name` = '{self._name}', + `Color` = '{self._color}', + `MinXp` = {self._min_xp}, + `PermissionInt` = {self._permissions}, + `LastModifiedAt` = '{self._modified_at}' + WHERE `Id` = {self._id}; + """) + + @property + def delete_string(self) -> str: + return str(f""" + DELETE FROM `Levels` + WHERE `Id` = {self._id}; + """) diff --git a/kdb-bot/src/bot_data/service/__init__.py b/kdb-bot/src/bot_data/service/__init__.py index 3ff47a8a2f..c2b4323a57 100644 --- a/kdb-bot/src/bot_data/service/__init__.py +++ b/kdb-bot/src/bot_data/service/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot_data.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/bot_data/service/level_repository_service.py b/kdb-bot/src/bot_data/service/level_repository_service.py new file mode 100644 index 0000000000..3e41fc1b4b --- /dev/null +++ b/kdb-bot/src/bot_data/service/level_repository_service.py @@ -0,0 +1,97 @@ +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.level_repository_abc import LevelRepositoryABC +from bot_data.model.level import Level + + +class LevelRepositoryService(LevelRepositoryABC): + + def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + self._logger = logger + self._context = db_context + + self._servers = servers + + LevelRepositoryABC.__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 _level_from_result(self, sql_result: tuple) -> Level: + return Level( + self._get_value_from_result(sql_result[1]), # name + self._get_value_from_result(sql_result[2]), # color + int(self._get_value_from_result(sql_result[3])), # min xp + int(self._get_value_from_result(sql_result[4])), # permissions + self._servers.get_server_by_id(sql_result[5]), # server + id=self._get_value_from_result(sql_result[0]) # id + ) + + def get_levels(self) -> List[Level]: + levels = List(Level) + self._logger.trace(__name__, f'Send SQL command: {Level.get_select_all_string()}') + results = self._context.select(Level.get_select_all_string()) + for result in results: + self._logger.trace(__name__, f'Get level with id {result[0]}') + levels.append(self._level_from_result(result)) + + return levels + + def get_level_by_id(self, id: int) -> Level: + self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_id_string(id)}') + result = self._context.select(Level.get_select_by_id_string(id))[0] + + return self._level_from_result(result) + + def find_level_by_id(self, id: int) -> Optional[Level]: + self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_id_string(id)}') + result = self._context.select(Level.get_select_by_id_string(id)) + if result is None or len(result) == 0: + return None + + return self._level_from_result(result[0]) + + def get_levels_by_server_id(self, server_id: int) -> List[Level]: + levels = List(Level) + self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_server_id_string(server_id)}') + results = self._context.select(Level.get_select_by_server_id_string(server_id)) + + for result in results: + self._logger.trace(__name__, f'Get level with id {result[0]}') + levels.append(self._level_from_result(result)) + + return levels + + def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]: + levels = List(Level) + self._logger.trace(__name__, f'Send SQL command: {Level.get_select_by_server_id_string(server_id)}') + results = self._context.select(Level.get_select_by_server_id_string(server_id)) + if results is None or len(results) == 0: + return None + + for result in results: + self._logger.trace(__name__, f'Get level with id {result[0]}') + levels.append(self._level_from_result(result)) + + return levels + + def add_level(self, level: Level): + self._logger.trace(__name__, f'Send SQL command: {level.insert_string}') + self._context.cursor.execute(level.insert_string) + + def update_level(self, level: Level): + self._logger.trace(__name__, f'Send SQL command: {level.udpate_string}') + self._context.cursor.execute(level.udpate_string) + + def delete_level(self, level: Level): + self._logger.trace(__name__, f'Send SQL command: {level.delete_string}') + self._context.cursor.execute(level.delete_string) diff --git a/kdb-bot/src/bot_data/service/seeder_service.py b/kdb-bot/src/bot_data/service/seeder_service.py new file mode 100644 index 0000000000..6d0f9b7df4 --- /dev/null +++ b/kdb-bot/src/bot_data/service/seeder_service.py @@ -0,0 +1,25 @@ +from cpl_core.database.context import DatabaseContextABC +from cpl_core.dependency_injection import ServiceProviderABC +from cpl_query.extension import List + +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.data_seeder_abc import DataSeederABC + + +class SeederService: + + def __init__(self, logger: DatabaseLogger, services: ServiceProviderABC, db: DatabaseContextABC): + self._logger = logger + self._services = services + + self._db = db + + self._seeder = List(type, DataSeederABC.__subclasses__()) + + async def seed(self): + self._logger.info(__name__, f"Seed data") + for seeder in self._seeder: + seeder_as_service: DataSeederABC = self._services.get_service(seeder) + self._logger.debug(__name__, f"Starting seeder {seeder.__name__}") + await seeder_as_service.seed() + self._db.save_changes() diff --git a/kdb-bot/src/modules/admin/__init__.py b/kdb-bot/src/modules/admin/__init__.py index 0b4143b89a..afcd237eb4 100644 --- a/kdb-bot/src/modules/admin/__init__.py +++ b/kdb-bot/src/modules/admin/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.admin' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/admin/command/__init__.py b/kdb-bot/src/modules/admin/command/__init__.py index 560c44e583..ed0cff3be5 100644 --- a/kdb-bot/src/modules/admin/command/__init__.py +++ b/kdb-bot/src/modules/admin/command/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.admin.command' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/auto_role/__init__.py b/kdb-bot/src/modules/auto_role/__init__.py index c98076f25c..4a85332301 100644 --- a/kdb-bot/src/modules/auto_role/__init__.py +++ b/kdb-bot/src/modules/auto_role/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.auto_role' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/auto_role/command/__init__.py b/kdb-bot/src/modules/auto_role/command/__init__.py index 893b4fd8cf..86a6041df9 100644 --- a/kdb-bot/src/modules/auto_role/command/__init__.py +++ b/kdb-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 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/auto_role/events/__init__.py b/kdb-bot/src/modules/auto_role/events/__init__.py index b3c13b1c2f..2946309621 100644 --- a/kdb-bot/src/modules/auto_role/events/__init__.py +++ b/kdb-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 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/auto_role/helper/__init__.py b/kdb-bot/src/modules/auto_role/helper/__init__.py index dde66d85e0..a19a540f30 100644 --- a/kdb-bot/src/modules/auto_role/helper/__init__.py +++ b/kdb-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 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/base/__init__.py b/kdb-bot/src/modules/base/__init__.py index 9013b6d0db..624c476ecc 100644 --- a/kdb-bot/src/modules/base/__init__.py +++ b/kdb-bot/src/modules/base/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.base' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/base/abc/__init__.py b/kdb-bot/src/modules/base/abc/__init__.py index 4f366eaa16..ccc3e98a76 100644 --- a/kdb-bot/src/modules/base/abc/__init__.py +++ b/kdb-bot/src/modules/base/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.base.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/base/command/__init__.py b/kdb-bot/src/modules/base/command/__init__.py index a1c9429739..c9fccb7ac9 100644 --- a/kdb-bot/src/modules/base/command/__init__.py +++ b/kdb-bot/src/modules/base/command/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.base.command' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/base/configuration/__init__.py b/kdb-bot/src/modules/base/configuration/__init__.py index 1c3feda70b..5dfdba22e7 100644 --- a/kdb-bot/src/modules/base/configuration/__init__.py +++ b/kdb-bot/src/modules/base/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.base.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/base/events/__init__.py b/kdb-bot/src/modules/base/events/__init__.py index 85e09931a0..8b0480696d 100644 --- a/kdb-bot/src/modules/base/events/__init__.py +++ b/kdb-bot/src/modules/base/events/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.base.events' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/base/service/__init__.py b/kdb-bot/src/modules/base/service/__init__.py index 26d484dac9..4362aaf149 100644 --- a/kdb-bot/src/modules/base/service/__init__.py +++ b/kdb-bot/src/modules/base/service/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.base.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/boot_log/__init__.py b/kdb-bot/src/modules/boot_log/__init__.py index a8e3acd4df..afe1ddbda5 100644 --- a/kdb-bot/src/modules/boot_log/__init__.py +++ b/kdb-bot/src/modules/boot_log/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.boot_log' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/boot_log/configuration/__init__.py b/kdb-bot/src/modules/boot_log/configuration/__init__.py index a7ee6a4ec8..1eee9aba97 100644 --- a/kdb-bot/src/modules/boot_log/configuration/__init__.py +++ b/kdb-bot/src/modules/boot_log/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.boot_log.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/database/__init__.py b/kdb-bot/src/modules/database/__init__.py index 122dd6eba0..a1425bbbd4 100644 --- a/kdb-bot/src/modules/database/__init__.py +++ b/kdb-bot/src/modules/database/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.database' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/database/database_extension.py b/kdb-bot/src/modules/database/database_extension.py index 8bc111e9a9..1cc7a77fe5 100644 --- a/kdb-bot/src/modules/database/database_extension.py +++ b/kdb-bot/src/modules/database/database_extension.py @@ -9,6 +9,7 @@ from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.logging.database_logger import DatabaseLogger from bot_data.service.migration_service import MigrationService +from bot_data.service.seeder_service import SeederService class DatabaseExtension(ApplicationExtensionABC): diff --git a/kdb-bot/src/modules/database/database_on_ready_event.py b/kdb-bot/src/modules/database/database_on_ready_event.py index 9176a26c15..96f013eefc 100644 --- a/kdb-bot/src/modules/database/database_on_ready_event.py +++ b/kdb-bot/src/modules/database/database_on_ready_event.py @@ -20,6 +20,7 @@ from bot_data.model.server import Server from bot_data.model.user import User from bot_data.model.user_joined_server import UserJoinedServer from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel +from bot_data.service.seeder_service import SeederService from bot_data.service.user_repository_service import ServerRepositoryABC from modules.base.configuration.base_server_settings import BaseServerSettings @@ -30,6 +31,7 @@ class DatabaseOnReadyEvent(OnReadyABC): self, config: ConfigurationABC, logger: DatabaseLogger, + seeder: SeederService, bot: DiscordBotServiceABC, db_context: DatabaseContextABC, server_repo: ServerRepositoryABC, @@ -43,6 +45,7 @@ class DatabaseOnReadyEvent(OnReadyABC): self._config = config self._logger = logger + self._seeder = seeder self._bot = bot self._db_context = db_context self._servers = server_repo @@ -303,6 +306,8 @@ class DatabaseOnReadyEvent(OnReadyABC): async def on_ready(self): self._logger.debug(__name__, f'Module {type(self)} started') + await self._seeder.seed() + self._check_known_users() self._check_servers() self._check_clients() diff --git a/kdb-bot/src/modules/level/__init__.py b/kdb-bot/src/modules/level/__init__.py new file mode 100644 index 0000000000..d1d67ee323 --- /dev/null +++ b/kdb-bot/src/modules/level/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'modules.level' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.dev25' + +from collections import namedtuple + + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/level/configuration/__init__.py b/kdb-bot/src/modules/level/configuration/__init__.py new file mode 100644 index 0000000000..a30d06e06f --- /dev/null +++ b/kdb-bot/src/modules/level/configuration/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'modules.level.configuration' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.dev25' + +from collections import namedtuple + + +# imports + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/level/configuration/default_level_settings.py b/kdb-bot/src/modules/level/configuration/default_level_settings.py new file mode 100644 index 0000000000..3687ab83a9 --- /dev/null +++ b/kdb-bot/src/modules/level/configuration/default_level_settings.py @@ -0,0 +1,39 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console +from cpl_query.extension import List + +from bot_data.model.level import Level + + +class DefaultLevelSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._levels = List(Level) + self._level_header = '' + + @property + def levels(self) -> List[Level]: + return self._levels + + @property + def level_header(self) -> str: + return self._level_header + + def from_dict(self, settings: dict): + try: + self._level_header = settings['LevelHeader'] + for level in settings['Levels']: + self._levels.append(Level( + level['Name'], + level['Color'], + int(level['MinXp']), + int(level['Permissions']), + None + )) + except Exception as e: + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings') + Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/kdb-bot/src/modules/level/configuration/level_server_settings.py b/kdb-bot/src/modules/level/configuration/level_server_settings.py new file mode 100644 index 0000000000..85985cffc3 --- /dev/null +++ b/kdb-bot/src/modules/level/configuration/level_server_settings.py @@ -0,0 +1,29 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class LevelServerSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._id: int = 0 + self._changed_level_notification_channel = 0 + + @property + def id(self) -> int: + return self._id + + @property + def changed_level_notification_channel(self) -> int: + return self._changed_level_notification_channel + + def from_dict(self, settings: dict): + try: + self._id = int(settings['Id']) + self._changed_level_notification_channel = int(settings['ChangedLevelNotificationChannelId']) + except Exception as e: + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings') + Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/kdb-bot/src/modules/level/configuration/level_settings.py b/kdb-bot/src/modules/level/configuration/level_settings.py new file mode 100644 index 0000000000..7962941ca0 --- /dev/null +++ b/kdb-bot/src/modules/level/configuration/level_settings.py @@ -0,0 +1,32 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console +from cpl_query.extension import List + +from modules.level.configuration.level_server_settings import LevelServerSettings + + +class LevelSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._servers: List[LevelServerSettings] = List() + + @property + def servers(self) -> List[LevelServerSettings]: + return self._servers + + def from_dict(self, settings: dict): + try: + servers = List(LevelServerSettings) + for s in settings: + st = LevelServerSettings() + settings[s]['Id'] = s + st.from_dict(settings[s]) + servers.append(st) + self._servers = servers + except Exception as e: + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings') + Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/kdb-bot/src/modules/level/default-level.json b/kdb-bot/src/modules/level/default-level.json new file mode 100644 index 0000000000..047b811a28 --- /dev/null +++ b/kdb-bot/src/modules/level/default-level.json @@ -0,0 +1,31 @@ +{ + "DefaultLevel": { + "LevelHeader": "~~~ Level ~~~", + "Levels": [ + { + "Name": "Newbie", + "Color": "0x1abc9c", + "MinXp": 0, + "Permissions": 968552209984 + }, + { + "Name": "Keks", + "Color": "0x2ecc71", + "MinXp": 100, + "Permissions": 1002928856640 + }, + { + "Name": "Doppelkeks", + "Color": "0x3498db", + "MinXp": 200, + "Permissions": 1071849660224 + }, + { + "Name": "Auror", + "Color": "0xf1c40f", + "MinXp": 300, + "Permissions": 1089042120513 + } + ] + } +} \ No newline at end of file diff --git a/kdb-bot/src/modules/level/events/__init__.py b/kdb-bot/src/modules/level/events/__init__.py new file mode 100644 index 0000000000..5925acf8c6 --- /dev/null +++ b/kdb-bot/src/modules/level/events/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'modules.level.events' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.dev25' + +from collections import namedtuple + + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/level/events/level_on_message_event.py b/kdb-bot/src/modules/level/events/level_on_message_event.py new file mode 100644 index 0000000000..cd69622e07 --- /dev/null +++ b/kdb-bot/src/modules/level/events/level_on_message_event.py @@ -0,0 +1,21 @@ +import discord +from cpl_discord.events import OnMessageABC + +from bot_core.logging.message_logger import MessageLogger +from modules.level.service.level_service import LevelService + + +class LevelOnMessageEvent(OnMessageABC): + + def __init__( + self, + logger: MessageLogger, + level: LevelService + ): + OnMessageABC.__init__(self) + self._logger = logger + self._level = level + + async def on_message(self, message: discord.Message): + self._logger.debug(__name__, f'Module {type(self)} started') + await self._level.check_level(message.author) diff --git a/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py b/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py new file mode 100644 index 0000000000..c9127e0376 --- /dev/null +++ b/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py @@ -0,0 +1,23 @@ +import discord +from cpl_core.logging import LoggerABC +from cpl_discord.events import OnVoiceStateUpdateABC + +from modules.level.service.level_service import LevelService + + +class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): + + def __init__( + self, + logger: LoggerABC, + level: LevelService + ): + OnVoiceStateUpdateABC.__init__(self) + self._logger = logger + self._level = level + + self._logger.info(__name__, f'Module {type(self)} loaded') + + async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): + self._logger.debug(__name__, f'Module {type(self)} started') + await self._level.check_level(member) diff --git a/kdb-bot/src/modules/level/level.json b/kdb-bot/src/modules/level/level.json new file mode 100644 index 0000000000..7ceaa22524 --- /dev/null +++ b/kdb-bot/src/modules/level/level.json @@ -0,0 +1,46 @@ +{ + "ProjectSettings": { + "Name": "level", + "Version": { + "Major": "1", + "Minor": "0", + "Micro": "0" + }, + "Author": "", + "AuthorEmail": "", + "Description": "", + "LongDescription": "", + "URL": "", + "CopyrightDate": "", + "CopyrightName": "", + "LicenseName": "", + "LicenseDescription": "", + "Dependencies": [ + "cpl-core>=2022.10.0.post7" + ], + "DevDependencies": [ + "cpl-cli>=2022.10.1" + ], + "PythonVersion": ">=3.10.4", + "PythonPath": { + "linux": "" + }, + "Classifiers": [] + }, + "BuildSettings": { + "ProjectType": "library", + "SourcePath": "", + "OutputPath": "../../dist", + "Main": "level.main", + "EntryPoint": "level", + "IncludePackageData": false, + "Included": [], + "Excluded": [ + "*/__pycache__", + "*/logs", + "*/tests" + ], + "PackageData": {}, + "ProjectReferences": [] + } +} \ No newline at end of file diff --git a/kdb-bot/src/modules/level/level_module.py b/kdb-bot/src/modules/level/level_module.py new file mode 100644 index 0000000000..1943e73cf4 --- /dev/null +++ b/kdb-bot/src/modules/level/level_module.py @@ -0,0 +1,33 @@ +import os + +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceCollectionABC +from cpl_core.environment import ApplicationEnvironmentABC +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.configuration.feature_flags_enum import FeatureFlagsEnum +from modules.level.events.level_on_message_event import LevelOnMessageEvent +from modules.level.events.level_on_voice_state_update_event import LevelOnVoiceStateUpdateEvent +from modules.level.level_seeder import LevelSeeder +from modules.level.service.level_service import LevelService + + +class LevelModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, FeatureFlagsEnum.level_module) + + 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) + env.set_working_directory(cwd) + + def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): + services.add_transient(LevelSeeder) + services.add_transient(LevelService) + + self._dc.add_event(DiscordEventTypesEnum.on_message.value, LevelOnMessageEvent) + self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, LevelOnVoiceStateUpdateEvent) diff --git a/kdb-bot/src/modules/level/level_seeder.py b/kdb-bot/src/modules/level/level_seeder.py new file mode 100644 index 0000000000..9a1148bb49 --- /dev/null +++ b/kdb-bot/src/modules/level/level_seeder.py @@ -0,0 +1,83 @@ +from cpl_discord.container import Guild, Role +from cpl_discord.service import DiscordBotServiceABC +from cpl_query.extension import List +from discord import Permissions, Colour + +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.data_seeder_abc import DataSeederABC +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.model.level import Level +from bot_data.model.server import Server +from bot_data.service.level_repository_service import LevelRepositoryService +from modules.level.configuration.default_level_settings import DefaultLevelSettings + + +class LevelSeeder(DataSeederABC): + + def __init__(self, logger: DatabaseLogger, levels: DefaultLevelSettings, level_repo: LevelRepositoryService, servers: ServerRepositoryABC, bot: DiscordBotServiceABC): + DataSeederABC.__init__(self) + + self._logger = logger + self._levels = level_repo + self._servers = servers + self._bot = bot + + self._level_header = levels.level_header + self._default_levels = levels.levels.order_by_descending(lambda l: l.min_xp) + + async def _create_level(self, level: Level, guild: Guild, server: Server): + try: + if guild.roles.where(lambda r: r.name == level.name).first_or_default() is not None: + return + + await guild.create_role(name=level.name, colour=Colour(int(level.color, 16)), hoist=False, mentionable=True, permissions=Permissions(level.permissions)) + self._logger.info(__name__, f'Created level {level.name}') + level.server = server + self._levels.add_level(level) + except Exception as e: + self._logger.error(__name__, f'Creating level failed', e) + + async def seed(self): + # create levels + for guild in self._bot.guilds: + created_default = False + if guild.roles.where(lambda r: r.name == self._level_header).first_or_default() is None: + await guild.create_role(name=self._level_header) + + server = self._servers.find_server_by_discord_id(guild.id) + if server is None: + continue + + levels = self._levels.find_levels_by_server_id(server.server_id) + if levels is not None and levels.count() > 0: + # create levels from db + for level in levels: + await self._create_level(level, guild, server) + + self._logger.debug(__name__, f'Seeded levels') + else: + # create default levels + for level in self._default_levels: + created_default = True + await self._create_level(level, guild, server) + + self._logger.debug(__name__, f'Seeded default levels') + + if created_default: + continue + + position_above_levels = guild.roles.where(lambda r: r.name == self._level_header).single().position + for role in guild.roles.order_by_descending(lambda r: r.position): + if levels.where(lambda l: l.name == role.name).count() == 0: + continue + + new_position = position_above_levels - (levels.index(levels.where(lambda l: l.name == role.name).single()) + 1) + if new_position <= 0: + new_position = 1 + try: + self._logger.debug(__name__, f'Moved {role.name} from {role.position} to {new_position}') + await role.edit(position=new_position) + except Exception as e: + self._logger.error(__name__, f'Cannot change position of {role.name}', e) + + self._logger.debug(__name__, f'Checked role order') diff --git a/kdb-bot/src/modules/level/service/__init__.py b/kdb-bot/src/modules/level/service/__init__.py new file mode 100644 index 0000000000..4ed3b99f0b --- /dev/null +++ b/kdb-bot/src/modules/level/service/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'modules.level.service' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.dev25' + +from collections import namedtuple + + +# imports + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/level/service/level_service.py b/kdb-bot/src/modules/level/service/level_service.py new file mode 100644 index 0000000000..bf53b11ce8 --- /dev/null +++ b/kdb-bot/src/modules/level/service/level_service.py @@ -0,0 +1,92 @@ +import asyncio + +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC +from cpl_discord.container import Guild, Role, Member +from cpl_discord.service import DiscordBotServiceABC +from cpl_translation import TranslatePipe + +from bot_core.service.message_service import MessageService +from bot_data.model.level import Level +from bot_data.model.user import User +from bot_data.service.level_repository_service import LevelRepositoryService +from bot_data.service.server_repository_service import ServerRepositoryService +from bot_data.service.user_repository_service import UserRepositoryService +from modules.level.configuration.level_server_settings import LevelServerSettings + + +class LevelService: + + def __init__( + self, + config: ConfigurationABC, + logger: LoggerABC, + db: DatabaseContextABC, + levels: LevelRepositoryService, + users: UserRepositoryService, + servers: ServerRepositoryService, + bot: DiscordBotServiceABC, + message_service: MessageService, + t: TranslatePipe + ): + self._config = config + self._logger = logger + self._db = db + self._levels = levels + self._users = users + self._servers = servers + self._bot = bot + self._message_service = message_service + self._t = t + + def get_level(self, user: User) -> Level: + levels = self._levels.get_levels_by_server_id(user.server.server_id).order_by(lambda l: l.min_xp) + return levels.where(lambda l: user.xp >= l.min_xp).last() + + async def set_level(self, user: User): + level_names = self._levels.get_levels_by_server_id(user.server.server_id).select(lambda l: l.name) + guild: Guild = self._bot.guilds.where(lambda g: g.id == user.server.discord_server_id).single() + member: Member = guild.members.where(lambda m: m.id == user.discord_id).single() + + level = self.get_level(user) + level_role: Role = guild.roles.where(lambda r: r.name == level.name).single() + if level_role in member.roles: + return + + for role in member.roles: + if role.name not in level_names.to_list(): + continue + + try: + self._logger.debug(__name__, f'Try to remove role {role.name} from {member.name}') + await member.remove_roles(role) + self._logger.info(__name__, f'Removed role {role.name} from {member.name}') + except Exception as e: + self._logger.error(__name__, f'Removing role {role.name} from {member.name} failed!', e) + + try: + self._logger.debug(__name__, f'Try to add role {level_role.name} to {member.name}') + await member.add_roles(level_role) + self._logger.info(__name__, f'Add role {level_role.name} to {member.name}') + except Exception as e: + self._logger.error(__name__, f'Adding role {level_role.name} to {member.name} failed!', e) + + level_settings: LevelServerSettings = self._config.get_configuration(f'LevelServerSettings_{guild.id}') + await self._message_service.send_channel_message( + self._bot.get_channel(level_settings.changed_level_notification_channel), + self._t.transform('modules.level.new_level_message'.format(member.id, level.name)), + is_persistent=True + ) + + async def check_level(self, member: discord.Member): + if member.bot: + return + + server = self._servers.get_server_by_discord_id(member.guild.id) + user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id) + if user is None: + self._logger.warn(__name__, f'User not found {member.guild.name}@{member.name}') + + await self.set_level(user) diff --git a/kdb-bot/src/modules/moderator/__init__.py b/kdb-bot/src/modules/moderator/__init__.py index 2582b00b71..ab63ed9f20 100644 --- a/kdb-bot/src/modules/moderator/__init__.py +++ b/kdb-bot/src/modules/moderator/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.moderator' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/moderator/command/__init__.py b/kdb-bot/src/modules/moderator/command/__init__.py index bdd9ddbd21..68d0c50bf8 100644 --- a/kdb-bot/src/modules/moderator/command/__init__.py +++ b/kdb-bot/src/modules/moderator/command/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.moderator.command' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/permission/__init__.py b/kdb-bot/src/modules/permission/__init__.py index 151c717547..2215351384 100644 --- a/kdb-bot/src/modules/permission/__init__.py +++ b/kdb-bot/src/modules/permission/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.permission' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/permission/abc/__init__.py b/kdb-bot/src/modules/permission/abc/__init__.py index 460f1ab59a..294d277c41 100644 --- a/kdb-bot/src/modules/permission/abc/__init__.py +++ b/kdb-bot/src/modules/permission/abc/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.permission.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/permission/configuration/__init__.py b/kdb-bot/src/modules/permission/configuration/__init__.py index 062b17ee96..2a385a0dee 100644 --- a/kdb-bot/src/modules/permission/configuration/__init__.py +++ b/kdb-bot/src/modules/permission/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.permission.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/permission/events/__init__.py b/kdb-bot/src/modules/permission/events/__init__.py index 32488e5aa0..d51f9b129d 100644 --- a/kdb-bot/src/modules/permission/events/__init__.py +++ b/kdb-bot/src/modules/permission/events/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.permission.events' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25') diff --git a/kdb-bot/src/modules/permission/service/__init__.py b/kdb-bot/src/modules/permission/service/__init__.py index ddc1eb808b..930246c113 100644 --- a/kdb-bot/src/modules/permission/service/__init__.py +++ b/kdb-bot/src/modules/permission/service/__init__.py @@ -15,7 +15,7 @@ __title__ = 'modules.permission.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.3.dev70' +__version__ = '0.3.dev25' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='dev70') +version_info = VersionInfo(major='0', minor='3', micro='dev25')