diff --git a/kdb-bot/cpl-workspace.json b/kdb-bot/cpl-workspace.json index ed99de6618..37a8b6c688 100644 --- a/kdb-bot/cpl-workspace.json +++ b/kdb-bot/cpl-workspace.json @@ -15,26 +15,22 @@ "bot-api": "src/bot_api/bot-api.json", "get-version": "tools/get_version/get-version.json", "post-build": "tools/post_build/post-build.json", - "set-version": "tools/set_version/set-version.json" + "set-version": "tools/set_version/set-version.json", + "level": "src/modules/level/level.json" }, "Scripts": { - "sv": "cpl set-version", "set-version": "cpl run set-version $ARGS; echo '';", - "gv": "cpl get-version", "get-version": "export VERSION=$(cpl run get-version); echo $VERSION;", - "pre-build": "cpl set-version $ARGS", "post-build": "cpl run post-build", - "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;", - "docker-build": "cpl b; docker-compose down; docker build -t kdb-bot/kdb-bot:$(cpl gv) .", "docker-compose": "docker-compose up -d", "docker": "cpl docker-build; cpl docker-compose;" 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_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_data/migration/level_migration.py b/kdb-bot/src/bot_data/migration/level_migration.py new file mode 100644 index 0000000000..d01b567744 --- /dev/null +++ b/kdb-bot/src/bot_data/migration/level_migration.py @@ -0,0 +1,33 @@ +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, + `PermissionInt` BIGINT NOT NULL, + `ServerId` BIGINT, + PRIMARY KEY(`Id`), + FOREIGN KEY (`ServerId`) REFERENCES `Servers`(`ServerId`) + ); + """) + ) + + def downgrade(self): + self._cursor.execute('DROP TABLE `Levels`;') + diff --git a/kdb-bot/src/modules/level/__init__.py b/kdb-bot/src/modules/level/__init__.py new file mode 100644 index 0000000000..ad5eca3064 --- /dev/null +++ b/kdb-bot/src/modules/level/__init__.py @@ -0,0 +1 @@ +# imports: diff --git a/kdb-bot/src/modules/level/level.json b/kdb-bot/src/modules/level/level.json new file mode 100644 index 0000000000..1d8d742502 --- /dev/null +++ b/kdb-bot/src/modules/level/level.json @@ -0,0 +1,46 @@ +{ + "ProjectSettings": { + "Name": "level", + "Version": { + "Major": "0", + "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..dfdd9bdae3 --- /dev/null +++ b/kdb-bot/src/modules/level/level_module.py @@ -0,0 +1,19 @@ +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.configuration.feature_flags_enum import FeatureFlagsEnum + + +class LevelModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, FeatureFlagsEnum.level_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC): + pass