From 6356d455f45bac3ddd5dba318c0c389a9712805f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 13:46:53 +0100 Subject: [PATCH 01/13] Removed cpl-extension project --- cpl-workspace.json | 1 - src/cpl_extension/__init__.py | 25 ---------------- src/cpl_extension/cpl-extension.json | 44 ---------------------------- 3 files changed, 70 deletions(-) delete mode 100644 src/cpl_extension/__init__.py delete mode 100644 src/cpl_extension/cpl-extension.json diff --git a/cpl-workspace.json b/cpl-workspace.json index e3781d9..72237cd 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -6,7 +6,6 @@ "gismo-cli": "src/gismo_cli/gismo-cli.json", "gismo-core": "src/gismo_core/gismo-core.json", "gismo-data": "src/gismo_data/gismo-data.json", - "cpl-extension": "src/cpl_extension/cpl-extension.json", "modules-core": "src/modules_core/modules-core.json", "boot-log": "src/modules/boot_log/boot-log.json", "level-generator": "tools/level_generator/level-generator.json", diff --git a/src/cpl_extension/__init__.py b/src/cpl_extension/__init__.py deleted file mode 100644 index 8fe1072..0000000 --- a/src/cpl_extension/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -gismo sh-edraft Gismo -~~~~~~~~~~~~~~~~~~~ - -sh-edraft Dicord bot Gismo - -:copyright: (c) 2021 - 2022 sh-edraft.de -:license: MIT, see LICENSE for more details. - -""" - -__title__ = 'cpl_extension' -__author__ = 'Sven Heidemann' -__license__ = 'MIT' -__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' - -from collections import namedtuple - -# imports: - -VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') diff --git a/src/cpl_extension/cpl-extension.json b/src/cpl_extension/cpl-extension.json deleted file mode 100644 index b6d271b..0000000 --- a/src/cpl_extension/cpl-extension.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "ProjectSettings": { - "Name": "cpl-extension", - "Version": { - "Major": "0", - "Minor": "1", - "Micro": "0" - }, - "Author": "Sven Heidemann", - "AuthorEmail": "sven.heidemann@sh-edraft.de", - "Description": "sh-edraft Gismo - cpl extension - database core", - "LongDescription": "sh-edraft Dicord bot Gismo - database implementation of cpl.database", - "URL": "https://www.sh-edraft.de", - "CopyrightDate": "2021 - 2022", - "CopyrightName": "sh-edraft.de", - "LicenseName": "MIT", - "LicenseDescription": "MIT, see LICENSE for more details.", - "Dependencies": [ - "sh_cpl-core>=2021.10.2", - "sh_cpl-query>=2021.10.3" - ], - "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "../../venv/bin/python" - }, - "Classifiers": [] - }, - "BuildSettings": { - "ProjectType": "library", - "SourcePath": "", - "OutputPath": "../../dist", - "Main": "", - "EntryPoint": "", - "IncludePackageData": false, - "Included": [], - "Excluded": [ - "*/__pycache__", - "*/logs", - "*/tests" - ], - "PackageData": {}, - "ProjectReferences": [] - } -} \ No newline at end of file From c5d2639e0a4cbd4626e3d0aabb5644d150b491c5 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 13:48:50 +0100 Subject: [PATCH 02/13] Updated cpl=2021.10 -> 2021.11 --- src/gismo/gismo.json | 4 ++-- src/gismo_cli/gismo-cli.json | 4 ++-- src/gismo_core/gismo-core.json | 4 ++-- src/gismo_data/gismo-data.json | 4 ++-- src/modules/boot_log/boot-log.json | 4 ++-- src/modules_core/modules-core.json | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gismo/gismo.json b/src/gismo/gismo.json index 147a433..0515ded 100644 --- a/src/gismo/gismo.json +++ b/src/gismo/gismo.json @@ -16,8 +16,8 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "sh_cpl-core>=2021.10.2", - "sh_cpl-query>=2021.10.3", + "sh_cpl-core>=2021.11.0", + "sh_cpl-query>=2021.11.0", "discord.py==1.7.3" ], "PythonVersion": ">=3.9.2", diff --git a/src/gismo_cli/gismo-cli.json b/src/gismo_cli/gismo-cli.json index e34e102..0c7ab06 100644 --- a/src/gismo_cli/gismo-cli.json +++ b/src/gismo_cli/gismo-cli.json @@ -16,8 +16,8 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "sh_cpl-core>=2021.10.2", - "sh_cpl-query>=2021.10.3" + "sh_cpl-core>=2021.11.0", + "sh_cpl-query>=2021.11.0" ], "PythonVersion": ">=3.9.2", "PythonPath": { diff --git a/src/gismo_core/gismo-core.json b/src/gismo_core/gismo-core.json index 0de1eff..ce5bd3b 100644 --- a/src/gismo_core/gismo-core.json +++ b/src/gismo_core/gismo-core.json @@ -16,8 +16,8 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "sh_cpl-core>=2021.10.2", - "sh_cpl-query>=2021.10.3" + "sh_cpl-core>=2021.11.0", + "sh_cpl-query>=2021.11.0" ], "PythonVersion": ">=3.9.2", "PythonPath": { diff --git a/src/gismo_data/gismo-data.json b/src/gismo_data/gismo-data.json index 6f32731..a9552f0 100644 --- a/src/gismo_data/gismo-data.json +++ b/src/gismo_data/gismo-data.json @@ -16,8 +16,8 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "sh_cpl-core>=2021.10.2", - "sh_cpl-query>=2021.10.3" + "sh_cpl-core>=2021.11.0", + "sh_cpl-query>=2021.11.0" ], "PythonVersion": ">=3.9.2", "PythonPath": { diff --git a/src/modules/boot_log/boot-log.json b/src/modules/boot_log/boot-log.json index f4413c8..5cbcd68 100644 --- a/src/modules/boot_log/boot-log.json +++ b/src/modules/boot_log/boot-log.json @@ -16,8 +16,8 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "sh_cpl-core>=2021.10.2", - "sh_cpl-query>=2021.10.3" + "sh_cpl-core>=2021.11.0", + "sh_cpl-query>=2021.11.0" ], "PythonVersion": ">=3.9.2", "PythonPath": { diff --git a/src/modules_core/modules-core.json b/src/modules_core/modules-core.json index 74f6095..9324f5f 100644 --- a/src/modules_core/modules-core.json +++ b/src/modules_core/modules-core.json @@ -16,8 +16,8 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "sh_cpl-core>=2021.10.2", - "sh_cpl-query>=2021.10.3" + "sh_cpl-core>=2021.11.0", + "sh_cpl-query>=2021.11.0" ], "PythonVersion": ">=3.9.2", "PythonPath": { From 01cf17ef86660fd239b5d928a02ffde7728613eb Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 13:49:33 +0100 Subject: [PATCH 03/13] Build with new version --- src/gismo/__init__.py | 4 ++-- src/gismo/gismo.json | 3 +-- src/gismo_core/__init__.py | 4 ++-- src/gismo_core/abc/__init__.py | 4 ++-- src/gismo_core/configuration/__init__.py | 4 ++-- src/gismo_core/service/__init__.py | 4 ++-- src/gismo_data/__init__.py | 4 ++-- src/modules/boot_log/__init__.py | 4 ++-- src/modules_core/__init__.py | 4 ++-- src/modules_core/abc/__init__.py | 4 ++-- src/modules_core/service/__init__.py | 4 ++-- 11 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/gismo/__init__.py b/src/gismo/__init__.py index ca405f7..a9e4465 100644 --- a/src/gismo/__init__.py +++ b/src/gismo/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/gismo/gismo.json b/src/gismo/gismo.json index 0515ded..d8f8c8d 100644 --- a/src/gismo/gismo.json +++ b/src/gismo/gismo.json @@ -3,7 +3,7 @@ "Name": "gismo", "Version": { "Major": "0", - "Minor": "1", + "Minor": "2", "Micro": "0" }, "Author": "Sven Heidemann", @@ -47,7 +47,6 @@ "ProjectReferences": [ "../gismo_core/gismo-core.json", "../gismo_data/gismo-data.json", - "../cpl_extension/cpl-extension.json", "../modules_core/modules-core.json", "../modules/boot_log/boot-log.json" ] diff --git a/src/gismo_core/__init__.py b/src/gismo_core/__init__.py index 2dcbf1d..f1838fc 100644 --- a/src/gismo_core/__init__.py +++ b/src/gismo_core/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/gismo_core/abc/__init__.py b/src/gismo_core/abc/__init__.py index 79226e4..b41756e 100644 --- a/src/gismo_core/abc/__init__.py +++ b/src/gismo_core/abc/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/gismo_core/configuration/__init__.py b/src/gismo_core/configuration/__init__.py index a5a1baa..affff5f 100644 --- a/src/gismo_core/configuration/__init__.py +++ b/src/gismo_core/configuration/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/gismo_core/service/__init__.py b/src/gismo_core/service/__init__.py index 1947127..97f2495 100644 --- a/src/gismo_core/service/__init__.py +++ b/src/gismo_core/service/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/gismo_data/__init__.py b/src/gismo_data/__init__.py index c4ee28a..e182ec3 100644 --- a/src/gismo_data/__init__.py +++ b/src/gismo_data/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_data' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/boot_log/__init__.py b/src/modules/boot_log/__init__.py index 3354a8e..a6127ce 100644 --- a/src/modules/boot_log/__init__.py +++ b/src/modules/boot_log/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.boot_log' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules_core/__init__.py b/src/modules_core/__init__.py index 979887f..60a2666 100644 --- a/src/modules_core/__init__.py +++ b/src/modules_core/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules_core' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules_core/abc/__init__.py b/src/modules_core/abc/__init__.py index a65a733..235e917 100644 --- a/src/modules_core/abc/__init__.py +++ b/src/modules_core/abc/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules_core.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules_core/service/__init__.py b/src/modules_core/service/__init__.py index 3f494a0..b5b68cb 100644 --- a/src/modules_core/service/__init__.py +++ b/src/modules_core/service/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules_core.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.1.0' +__version__ = '0.2.0' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='0') +version_info = VersionInfo(major='0', minor='2', micro='0') From 14ecc46d924f4e52fc4f341c0fdfd1e9fea08218 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 14:51:58 +0100 Subject: [PATCH 04/13] Added database context --- src/gismo/application.py | 2 +- src/gismo/appsettings.edrafts-pc.json | 10 +++ src/gismo/startup.py | 13 ++- src/gismo_data/__init__.py | 26 +----- src/gismo_data/abc/__init__.py | 1 + src/gismo_data/abc/server_repository_abc.py | 20 +++++ src/gismo_data/abc/user_repository_abc.py | 20 +++++ src/gismo_data/db_context.py | 32 ++++++++ src/gismo_data/model/__init__.py | 1 + src/gismo_data/model/server.py | 62 ++++++++++++++ src/gismo_data/model/user.py | 80 +++++++++++++++++++ src/gismo_data/service/__init__.py | 1 + .../service/server_repository_service.py | 37 +++++++++ .../service/user_repository_service.py | 47 +++++++++++ 14 files changed, 325 insertions(+), 27 deletions(-) create mode 100644 src/gismo_data/abc/__init__.py create mode 100644 src/gismo_data/abc/server_repository_abc.py create mode 100644 src/gismo_data/abc/user_repository_abc.py create mode 100644 src/gismo_data/db_context.py create mode 100644 src/gismo_data/model/__init__.py create mode 100644 src/gismo_data/model/server.py create mode 100644 src/gismo_data/model/user.py create mode 100644 src/gismo_data/service/__init__.py create mode 100644 src/gismo_data/service/server_repository_service.py create mode 100644 src/gismo_data/service/user_repository_service.py diff --git a/src/gismo/application.py b/src/gismo/application.py index 9602da6..7b2ce54 100644 --- a/src/gismo/application.py +++ b/src/gismo/application.py @@ -21,7 +21,7 @@ class Gismo(ApplicationABC): async def main(self): try: self._logger.trace(__name__, f'Try to start {BotService}') - await self._bot.start_async() + # await self._bot.start_async() except Exception as e: self._logger.error(__name__, 'Start failed', e) diff --git a/src/gismo/appsettings.edrafts-pc.json b/src/gismo/appsettings.edrafts-pc.json index 1a0300b..ef10539 100644 --- a/src/gismo/appsettings.edrafts-pc.json +++ b/src/gismo/appsettings.edrafts-pc.json @@ -5,6 +5,16 @@ "ConsoleLogLevel": "TRACE", "FileLogLevel": "TRACE" }, + "DatabaseSettings": { + "Host": "localhost", + "User": "sh_gismo", + "Password": "c2hfZ2lzbW8=", + "Database": "sh_gismo_dev", + "Charset": "utf8mb4", + "UseUnicode": "true", + "Buffered": "true", + "AuthPlugin": "mysql_native_password" + }, "Discord": { "Token": "OTExNTc0NDQyMzMxNzM0MDI2.YZjX2w.9yhsrTfrmkoDUqRJVzV5FVEwF3U" }, diff --git a/src/gismo/startup.py b/src/gismo/startup.py index 5ab947f..a09983e 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -1,9 +1,10 @@ -from datetime import datetime import os +from datetime import datetime from typing import Optional from cpl_core.application import StartupABC from cpl_core.configuration import ConfigurationABC +from cpl_core.database import DatabaseSettings from cpl_core.dependency_injection import (ServiceCollectionABC, ServiceProviderABC) from cpl_core.environment import ApplicationEnvironment @@ -12,6 +13,11 @@ from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.service.bot_service import BotService from gismo_core.service.message_service import MessageService +from gismo_data.abc.server_repository_abc import ServerRepositoryABC +from gismo_data.abc.user_repository_abc import UserRepositoryABC +from gismo_data.db_context import DBContext +from gismo_data.service.server_repository_service import ServerRepositoryService +from gismo_data.service.user_repository_service import UserRepositoryService from modules.boot_log.boot_log import BootLog from modules_core.abc.module_abc import ModuleABC from modules_core.abc.module_service_abc import ModuleServiceABC @@ -42,10 +48,15 @@ class Startup(StartupABC): async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: services.add_logging() + services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) + services.add_singleton(ModuleServiceABC, ModuleService) services.add_singleton(BotServiceABC, BotService) services.add_transient(MessageServiceABC, MessageService) + services.add_transient(ServerRepositoryABC, ServerRepositoryService) + services.add_transient(UserRepositoryABC, UserRepositoryService) + services.add_transient(ModuleABC, BootLog) provider: ServiceProviderABC = services.build_service_provider() diff --git a/src/gismo_data/__init__.py b/src/gismo_data/__init__.py index e182ec3..425ab6c 100644 --- a/src/gismo_data/__init__.py +++ b/src/gismo_data/__init__.py @@ -1,25 +1 @@ -# -*- coding: utf-8 -*- - -""" -gismo sh-edraft Gismo -~~~~~~~~~~~~~~~~~~~ - -sh-edraft Dicord bot Gismo - -:copyright: (c) 2021 - 2022 sh-edraft.de -:license: MIT, see LICENSE for more details. - -""" - -__title__ = 'gismo_data' -__author__ = 'Sven Heidemann' -__license__ = 'MIT' -__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.2.0' - -from collections import namedtuple - -# imports: - -VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='2', micro='0') +# imports diff --git a/src/gismo_data/abc/__init__.py b/src/gismo_data/abc/__init__.py new file mode 100644 index 0000000..425ab6c --- /dev/null +++ b/src/gismo_data/abc/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/gismo_data/abc/server_repository_abc.py b/src/gismo_data/abc/server_repository_abc.py new file mode 100644 index 0000000..966e020 --- /dev/null +++ b/src/gismo_data/abc/server_repository_abc.py @@ -0,0 +1,20 @@ +from abc import ABC, abstractmethod + +from cpl_query.extension import List + +from gismo_data.model.server import Server + + +class ServerRepositoryABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + def get_servers(self) -> List[Server]: pass + + @abstractmethod + def get_server_by_id(self, id: int) -> Server: pass + + @abstractmethod + def get_server_by_discord_id(self, discord_id: int) -> Server: pass diff --git a/src/gismo_data/abc/user_repository_abc.py b/src/gismo_data/abc/user_repository_abc.py new file mode 100644 index 0000000..b135e29 --- /dev/null +++ b/src/gismo_data/abc/user_repository_abc.py @@ -0,0 +1,20 @@ +from abc import ABC, abstractmethod + +from cpl_query.extension import List + +from gismo_data.model.user import User + + +class UserRepositoryABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + def get_users(self) -> List[User]: pass + + @abstractmethod + def get_user_by_id(self, id: int) -> User: pass + + @abstractmethod + def get_user_by_discord_id(self, discord_id: int) -> User: pass diff --git a/src/gismo_data/db_context.py b/src/gismo_data/db_context.py new file mode 100644 index 0000000..a086f3a --- /dev/null +++ b/src/gismo_data/db_context.py @@ -0,0 +1,32 @@ +from cpl_core.database import DatabaseSettings +from cpl_core.database.context import DatabaseContext +from cpl_core.logging import LoggerABC + + +class DBContext(DatabaseContext): + + def __init__(self, logger: LoggerABC): + + self._logger = logger + + DatabaseContext.__init__(self) + + + def connect(self, database_settings: DatabaseSettings): + try: + self._logger.debug(__name__, "Connecting to database") + super(DatabaseContext, self).connect(database_settings) + self._logger.info(__name__, "Connected to database") + except Exception as e: + self._logger.fatal(__name__, "Connecting to database failed", e) + + def save_changes(self): + try: + self._logger.trace(__name__, "Save changes") + super(DatabaseContext, self).save_changes + self._logger.debug(__name__, "Saved changes") + except Exception as e: + self._logger.error(__name__, "Saving changes failed", e) + + def select(self, statement: str) -> list[tuple]: + return super(DatabaseContext, self).select(statement) \ No newline at end of file diff --git a/src/gismo_data/model/__init__.py b/src/gismo_data/model/__init__.py new file mode 100644 index 0000000..425ab6c --- /dev/null +++ b/src/gismo_data/model/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/gismo_data/model/server.py b/src/gismo_data/model/server.py new file mode 100644 index 0000000..a1b25f7 --- /dev/null +++ b/src/gismo_data/model/server.py @@ -0,0 +1,62 @@ +from typing import Optional +from cpl_core.database import TableABC + + +class Server(TableABC): + + def __init__(self, dc_id: int, id=0): + self._server_id = id + self._discord_server_id = dc_id + + @property + def server_id(self) -> int: + return self._server_id + + @property + def discord_server_id(self) -> int: + return self._discord_server_id + + @staticmethod + def get_create_string() -> str: + return str(f""" + CREATE TABLE IF NOT EXISTS `Servers` ( + `ServerId` INT(30) NOT NULL AUTO_INCREMENT, + `DiscordServerId` INT(30) NOT NULL, + PRIMARY KEY(`ServerId`) + ); + """) + + @staticmethod + def get_select_all_string() -> str: + return str(f""" + SELECT * FROM `Servers`; + """) + + @staticmethod + def get_select_by_id_string(id: int) -> str: + return str(f""" + SELECT * FROM `Servers` + WHERE `ServerId` = {id}; + """) + + @staticmethod + def get_select_by_discord_id_string(id: int) -> str: + return str(f""" + SELECT * FROM `Servers` + WHERE `DiscordServerId` = {id}; + """) + + @property + def insert_string(self) -> str: + return str(f""" + """) + + @property + def udpate_string(self) -> str: + return str(f""" + """) + + @property + def delete_string(self) -> str: + return str(f""" + """) diff --git a/src/gismo_data/model/user.py b/src/gismo_data/model/user.py new file mode 100644 index 0000000..b0f9817 --- /dev/null +++ b/src/gismo_data/model/user.py @@ -0,0 +1,80 @@ +from typing import Optional +from cpl_core.database import TableABC + +from gismo_data.model.server import Server + +class User(TableABC): + + def __init__(self, dc_id: int, xp: int, server: Optional[Server], id=0): + self._user_id = id + self._discord_id = dc_id + self._xp = xp + self._server = server + + @property + def user_id(self) -> int: + return self._user_id + + @property + def discord_id(self) -> int: + return self._discord_id + + @property + def xp(self) -> int: + return self._xp + + @xp.setter + def xp(self, value: int): + self._xp = value + + @property + def server(self) -> Optional[Server]: + return self._server + + @staticmethod + def get_create_string() -> str: + return str(f""" + CREATE TABLE IF NOT EXISTS `Users` ( + `UserId` INT(30) NOT NULL AUTO_INCREMENT, + `DiscordId` INT(30) NOT NULL, + `XP` INT(30) NOT NULL DEFAULT 0, + `ServerId` INT(30), + FOREIGN KEY (`UserId`) REFERENCES Server(`ServerId`), + PRIMARY KEY(`UserId`) + ); + """) + + @staticmethod + def get_select_all_string() -> str: + return str(f""" + SELECT * FROM `Users`; + """) + + @staticmethod + def get_select_by_id_string(id: int) -> str: + return str(f""" + SELECT * FROM `Users` + WHERE `UserId` = {id}; + """) + + @staticmethod + def get_select_by_discord_id_string(id: int) -> str: + return str(f""" + SELECT * FROM `Users` + WHERE `DiscordId` = {id}; + """) + + @property + def insert_string(self) -> str: + return str(f""" + """) + + @property + def udpate_string(self) -> str: + return str(f""" + """) + + @property + def delete_string(self) -> str: + return str(f""" + """) diff --git a/src/gismo_data/service/__init__.py b/src/gismo_data/service/__init__.py new file mode 100644 index 0000000..425ab6c --- /dev/null +++ b/src/gismo_data/service/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/gismo_data/service/server_repository_service.py b/src/gismo_data/service/server_repository_service.py new file mode 100644 index 0000000..cee862d --- /dev/null +++ b/src/gismo_data/service/server_repository_service.py @@ -0,0 +1,37 @@ +from cpl_core.database.context import DatabaseContextABC +from cpl_query.extension import List +from gismo_data.abc.server_repository_abc import ServerRepositoryABC +from gismo_data.model.server import Server + + +class ServerRepositoryService(ServerRepositoryABC): + + def __init__(self, db_context: DatabaseContextABC): + self._context = db_context + + ServerRepositoryABC.__init__(self) + + def get_servers(self) -> List[Server]: + servers = List(Server) + results = self._context.select(Server.get_select_all_string()) + for result in results: + servers.append(Server( + result[1], + id=result[0] + )) + + return servers + + def get_server_by_id(self, id: int) -> Server: + result = self._context.select(Server.get_select_by_id_string(id)) + return Server( + result[1], + id=result[0] + ) + + def get_server_by_discord_id(self, discord_id: int) -> Server: + result = self._context.select(Server.get_select_by_discord_id_string(discord_id)) + return Server( + result[1], + id=result[0] + ) diff --git a/src/gismo_data/service/user_repository_service.py b/src/gismo_data/service/user_repository_service.py new file mode 100644 index 0000000..c4e64f0 --- /dev/null +++ b/src/gismo_data/service/user_repository_service.py @@ -0,0 +1,47 @@ +from cpl_core.database.context import DatabaseContextABC +from cpl_query.extension import List +from gismo_data.abc.server_repository_abc import ServerRepositoryABC + +from gismo_data.abc.user_repository_abc import UserRepositoryABC +from gismo_data.model.user import User + + +class UserRepositoryService(UserRepositoryABC): + + def __init__(self, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + self._context = db_context + + self._servers = servers + + UserRepositoryABC.__init__(self) + + def get_users(self) -> List[User]: + users = List(User) + results = self._context.select(User.get_select_all_string()) + for result in results: + users.append(User( + result[1], + result[2], + self._servers.get_server_by_id(result[3]), + id=result[0] + )) + + return users + + def get_user_by_id(self, id: int) -> User: + result = self._context.select(User.get_select_by_id_string(id)) + return User( + result[1], + result[2], + self._servers.get_server_by_id(result[3]), + id=result[0] + ) + + def get_user_by_discord_id(self, discord_id: int) -> User: + result = self._context.select(User.get_select_by_discord_id_string(discord_id)) + return User( + result[1], + result[2], + self._servers.get_server_by_id(result[3]), + id=result[0] + ) From 61101eb57633d2e9bff645d52fcaeb745961c209 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 15:13:36 +0100 Subject: [PATCH 05/13] Improved database --- src/gismo/application.py | 2 +- src/gismo_data/db_context.py | 2 +- src/gismo_data/model/user.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gismo/application.py b/src/gismo/application.py index 7b2ce54..9602da6 100644 --- a/src/gismo/application.py +++ b/src/gismo/application.py @@ -21,7 +21,7 @@ class Gismo(ApplicationABC): async def main(self): try: self._logger.trace(__name__, f'Try to start {BotService}') - # await self._bot.start_async() + await self._bot.start_async() except Exception as e: self._logger.error(__name__, 'Start failed', e) diff --git a/src/gismo_data/db_context.py b/src/gismo_data/db_context.py index a086f3a..b40a8f1 100644 --- a/src/gismo_data/db_context.py +++ b/src/gismo_data/db_context.py @@ -15,7 +15,7 @@ class DBContext(DatabaseContext): def connect(self, database_settings: DatabaseSettings): try: self._logger.debug(__name__, "Connecting to database") - super(DatabaseContext, self).connect(database_settings) + super(DBContext, self).connect(database_settings) self._logger.info(__name__, "Connected to database") except Exception as e: self._logger.fatal(__name__, "Connecting to database failed", e) diff --git a/src/gismo_data/model/user.py b/src/gismo_data/model/user.py index b0f9817..2e1e904 100644 --- a/src/gismo_data/model/user.py +++ b/src/gismo_data/model/user.py @@ -39,7 +39,7 @@ class User(TableABC): `DiscordId` INT(30) NOT NULL, `XP` INT(30) NOT NULL DEFAULT 0, `ServerId` INT(30), - FOREIGN KEY (`UserId`) REFERENCES Server(`ServerId`), + FOREIGN KEY (`UserId`) REFERENCES Servers(`ServerId`), PRIMARY KEY(`UserId`) ); """) From 1d4a6c3e3b84cd6461171b1bdf85a7203612ef87 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 15:18:07 +0100 Subject: [PATCH 06/13] Improved db context logging --- src/gismo_data/db_context.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gismo_data/db_context.py b/src/gismo_data/db_context.py index b40a8f1..77ea0b1 100644 --- a/src/gismo_data/db_context.py +++ b/src/gismo_data/db_context.py @@ -15,7 +15,13 @@ class DBContext(DatabaseContext): def connect(self, database_settings: DatabaseSettings): try: self._logger.debug(__name__, "Connecting to database") - super(DBContext, self).connect(database_settings) + self._db.connect(database_settings) + for table in self._tables: + self._logger.debug(__name__, f"Create table if not exists: {table}") + self._logger.trace(__name__, f'Send SQL command: {table.get_create_string()}') + self._db.cursor.execute(table.get_create_string()) + + self.save_changes() self._logger.info(__name__, "Connected to database") except Exception as e: self._logger.fatal(__name__, "Connecting to database failed", e) From 20aedba23d2383d5c116e4d0cea5495929500d43 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 15:41:10 +0100 Subject: [PATCH 07/13] Improved data repository --- src/gismo_data/abc/server_repository_abc.py | 9 ++++ src/gismo_data/abc/user_repository_abc.py | 9 ++++ src/gismo_data/model/server.py | 13 ++++++ src/gismo_data/model/user.py | 42 +++++++++++++------ .../service/server_repository_service.py | 16 +++++++ .../service/user_repository_service.py | 22 +++++++++- 6 files changed, 97 insertions(+), 14 deletions(-) diff --git a/src/gismo_data/abc/server_repository_abc.py b/src/gismo_data/abc/server_repository_abc.py index 966e020..a9106f4 100644 --- a/src/gismo_data/abc/server_repository_abc.py +++ b/src/gismo_data/abc/server_repository_abc.py @@ -18,3 +18,12 @@ class ServerRepositoryABC(ABC): @abstractmethod def get_server_by_discord_id(self, discord_id: int) -> Server: pass + + @abstractmethod + def add_server(self, server: Server) -> int: pass + + @abstractmethod + def update_server(self, server: Server): pass + + @abstractmethod + def delete_server(self, server: Server): pass \ No newline at end of file diff --git a/src/gismo_data/abc/user_repository_abc.py b/src/gismo_data/abc/user_repository_abc.py index b135e29..7952f42 100644 --- a/src/gismo_data/abc/user_repository_abc.py +++ b/src/gismo_data/abc/user_repository_abc.py @@ -18,3 +18,12 @@ class UserRepositoryABC(ABC): @abstractmethod def get_user_by_discord_id(self, discord_id: int) -> User: pass + + @abstractmethod + def add_user(self, user: User) -> int: pass + + @abstractmethod + def update_user(self, user: User): pass + + @abstractmethod + def delete_user(self, user: User): pass diff --git a/src/gismo_data/model/server.py b/src/gismo_data/model/server.py index a1b25f7..ea6626f 100644 --- a/src/gismo_data/model/server.py +++ b/src/gismo_data/model/server.py @@ -49,14 +49,27 @@ class Server(TableABC): @property def insert_string(self) -> str: return str(f""" + INSERT INTO `Servers` ( + `DiscordServerId`, `CreatedAt`, `LastModifiedAt` + ) VALUES ( + {self._discord_server_id}, + '{self._created_at}', + '{self._modified_at}' + ); """) @property def udpate_string(self) -> str: return str(f""" + UPDATE `Servers` + SET `DiscordServerId` = {self._discord_server_id}, + `LastModifiedAt` = '{self._modified_at}' + WHERE `Id` = {self._id}; """) @property def delete_string(self) -> str: return str(f""" + DELETE FROM `Servers` + WHERE `Id` = {self._id}; """) diff --git a/src/gismo_data/model/user.py b/src/gismo_data/model/user.py index 2e1e904..da75bae 100644 --- a/src/gismo_data/model/user.py +++ b/src/gismo_data/model/user.py @@ -3,6 +3,7 @@ from cpl_core.database import TableABC from gismo_data.model.server import Server + class User(TableABC): def __init__(self, dc_id: int, xp: int, server: Optional[Server], id=0): @@ -14,49 +15,51 @@ class User(TableABC): @property def user_id(self) -> int: return self._user_id - + @property def discord_id(self) -> int: return self._discord_id - + @property def xp(self) -> int: return self._xp - + @xp.setter def xp(self, value: int): self._xp = value - + @property def server(self) -> Optional[Server]: return self._server - + @staticmethod def get_create_string() -> str: return str(f""" CREATE TABLE IF NOT EXISTS `Users` ( - `UserId` INT(30) NOT NULL AUTO_INCREMENT, - `DiscordId` INT(30) NOT NULL, - `XP` INT(30) NOT NULL DEFAULT 0, - `ServerId` INT(30), + `UserId` BIGINT NOT NULL AUTO_INCREMENT, + `DiscordId` BIGINT NOT NULL, + `XP` BIGINT NOT NULL DEFAULT 0, + `ServerId` BIGINT, + `CreatedAt` DATETIME(6), + `LastModifiedAt` DATETIME(6), FOREIGN KEY (`UserId`) REFERENCES Servers(`ServerId`), PRIMARY KEY(`UserId`) ); """) - + @staticmethod def get_select_all_string() -> str: return str(f""" SELECT * FROM `Users`; """) - + @staticmethod def get_select_by_id_string(id: int) -> str: return str(f""" SELECT * FROM `Users` WHERE `UserId` = {id}; """) - + @staticmethod def get_select_by_discord_id_string(id: int) -> str: return str(f""" @@ -67,14 +70,29 @@ class User(TableABC): @property def insert_string(self) -> str: return str(f""" + INSERT INTO `Users` ( + `DiscordId`, `XP`, `ServerId`, `CreatedAt`, `LastModifiedAt` + ) VALUES ( + {self._discord_id}, + {self._xp}, + {self._server.server_id}, + '{self._created_at}', + '{self._modified_at}' + ); """) @property def udpate_string(self) -> str: return str(f""" + UPDATE `Users` + SET `XP` = {self._xp}, + `LastModifiedAt` = '{self._modified_at}' + WHERE `Id` = {self._id}; """) @property def delete_string(self) -> str: return str(f""" + DELETE FROM `Users` + WHERE `Id` = {self._id}; """) diff --git a/src/gismo_data/service/server_repository_service.py b/src/gismo_data/service/server_repository_service.py index cee862d..9cf26d8 100644 --- a/src/gismo_data/service/server_repository_service.py +++ b/src/gismo_data/service/server_repository_service.py @@ -13,6 +13,7 @@ class ServerRepositoryService(ServerRepositoryABC): def get_servers(self) -> List[Server]: servers = List(Server) + self._logger.trace(__name__, f'Send SQL command: {Server.get_select_all_string()}') results = self._context.select(Server.get_select_all_string()) for result in results: servers.append(Server( @@ -23,6 +24,7 @@ class ServerRepositoryService(ServerRepositoryABC): return servers def get_server_by_id(self, id: int) -> Server: + self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_id_string(id)}') result = self._context.select(Server.get_select_by_id_string(id)) return Server( result[1], @@ -30,8 +32,22 @@ class ServerRepositoryService(ServerRepositoryABC): ) def get_server_by_discord_id(self, discord_id: int) -> Server: + self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}') result = self._context.select(Server.get_select_by_discord_id_string(discord_id)) return Server( result[1], id=result[0] ) + + def add_server(self, server: Server) -> int: + self._logger.trace(__name__, f'Send SQL command: {server.insert_string}') + self._context.cursor.execute(server.insert_string) + return int(self._context.select("SELECT LAST_INSERT_ID();")[0]) + + def update_server(self, server: Server): + self._logger.trace(__name__, f'Send SQL command: {server.udpate_string}') + self._context.cursor.execute(server.udpate_string) + + def delete_server(self, server: Server): + self._logger.trace(__name__, f'Send SQL command: {server.delete_string}') + self._context.cursor.execute(server.delete_string) diff --git a/src/gismo_data/service/user_repository_service.py b/src/gismo_data/service/user_repository_service.py index c4e64f0..1e94084 100644 --- a/src/gismo_data/service/user_repository_service.py +++ b/src/gismo_data/service/user_repository_service.py @@ -1,14 +1,16 @@ from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC from cpl_query.extension import List -from gismo_data.abc.server_repository_abc import ServerRepositoryABC +from gismo_data.abc.server_repository_abc import ServerRepositoryABC from gismo_data.abc.user_repository_abc import UserRepositoryABC from gismo_data.model.user import User class UserRepositoryService(UserRepositoryABC): - def __init__(self, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + self._logger = logger self._context = db_context self._servers = servers @@ -17,6 +19,7 @@ class UserRepositoryService(UserRepositoryABC): def get_users(self) -> List[User]: users = List(User) + self._logger.trace(__name__, f'Send SQL command: {User.get_select_all_string()}') results = self._context.select(User.get_select_all_string()) for result in results: users.append(User( @@ -29,6 +32,7 @@ class UserRepositoryService(UserRepositoryABC): return users def get_user_by_id(self, id: int) -> User: + self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_id_string(id)}') result = self._context.select(User.get_select_by_id_string(id)) return User( result[1], @@ -38,6 +42,7 @@ class UserRepositoryService(UserRepositoryABC): ) def get_user_by_discord_id(self, discord_id: int) -> User: + self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}') result = self._context.select(User.get_select_by_discord_id_string(discord_id)) return User( result[1], @@ -45,3 +50,16 @@ class UserRepositoryService(UserRepositoryABC): self._servers.get_server_by_id(result[3]), id=result[0] ) + + def add_user(self, user: User) -> int: + self._logger.trace(__name__, f'Send SQL command: {user.insert_strin}') + self._context.cursor.execute(user.insert_string) + return int(self._context.select("SELECT LAST_INSERT_ID();")[0]) + + def update_user(self, user: User): + self._logger.trace(__name__, f'Send SQL command: {user.udpate_string}') + self._context.cursor.execute(user.udpate_string) + + def delete_user(self, user: User): + self._logger.trace(__name__, f'Send SQL command: {user.delete_string}') + self._context.cursor.execute(user.delete_string) From 7bcd632b5977449cdff9110dd67796bfaf0ef0a3 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 15:55:17 +0100 Subject: [PATCH 08/13] Added find by dc id to repos --- src/gismo_data/abc/server_repository_abc.py | 4 ++++ src/gismo_data/abc/user_repository_abc.py | 4 ++++ .../service/server_repository_service.py | 17 ++++++++++++++++- .../service/user_repository_service.py | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/gismo_data/abc/server_repository_abc.py b/src/gismo_data/abc/server_repository_abc.py index a9106f4..2c082f1 100644 --- a/src/gismo_data/abc/server_repository_abc.py +++ b/src/gismo_data/abc/server_repository_abc.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +from typing import Optional from cpl_query.extension import List @@ -19,6 +20,9 @@ class ServerRepositoryABC(ABC): @abstractmethod def get_server_by_discord_id(self, discord_id: int) -> Server: pass + @abstractmethod + def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]: pass + @abstractmethod def add_server(self, server: Server) -> int: pass diff --git a/src/gismo_data/abc/user_repository_abc.py b/src/gismo_data/abc/user_repository_abc.py index 7952f42..aa40998 100644 --- a/src/gismo_data/abc/user_repository_abc.py +++ b/src/gismo_data/abc/user_repository_abc.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +from typing import Optional from cpl_query.extension import List @@ -19,6 +20,9 @@ class UserRepositoryABC(ABC): @abstractmethod def get_user_by_discord_id(self, discord_id: int) -> User: pass + @abstractmethod + def find_user_by_discord_id(self, discord_id: int) -> Optional[User]: pass + @abstractmethod def add_user(self, user: User) -> int: pass diff --git a/src/gismo_data/service/server_repository_service.py b/src/gismo_data/service/server_repository_service.py index 9cf26d8..09ed488 100644 --- a/src/gismo_data/service/server_repository_service.py +++ b/src/gismo_data/service/server_repository_service.py @@ -1,12 +1,16 @@ +from typing import Optional from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC from cpl_query.extension import List + from gismo_data.abc.server_repository_abc import ServerRepositoryABC from gismo_data.model.server import Server class ServerRepositoryService(ServerRepositoryABC): - def __init__(self, db_context: DatabaseContextABC): + def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC): + self._logger = logger self._context = db_context ServerRepositoryABC.__init__(self) @@ -38,6 +42,17 @@ class ServerRepositoryService(ServerRepositoryABC): result[1], id=result[0] ) + + def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]: + self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}') + result = self._context.select(Server.get_select_by_discord_id_string(discord_id)) + if len(result) == 0: + return None + + return Server( + result[1], + id=result[0] + ) def add_server(self, server: Server) -> int: self._logger.trace(__name__, f'Send SQL command: {server.insert_string}') diff --git a/src/gismo_data/service/user_repository_service.py b/src/gismo_data/service/user_repository_service.py index 1e94084..6212c82 100644 --- a/src/gismo_data/service/user_repository_service.py +++ b/src/gismo_data/service/user_repository_service.py @@ -1,3 +1,4 @@ +from typing import Optional from cpl_core.database.context import DatabaseContextABC from cpl_core.logging import LoggerABC from cpl_query.extension import List @@ -50,6 +51,19 @@ class UserRepositoryService(UserRepositoryABC): self._servers.get_server_by_id(result[3]), id=result[0] ) + + def find_user_by_discord_id(self, discord_id: int) -> Optional[User]: + self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}') + result = self._context.select(User.get_select_by_discord_id_string(discord_id)) + if len(result) == 0: + return None + + return User( + result[1], + result[2], + self._servers.get_server_by_id(result[3]), + id=result[0] + ) def add_user(self, user: User) -> int: self._logger.trace(__name__, f'Send SQL command: {user.insert_strin}') From 1a5767edf0c79c9c918e25a1def8bbcf089a7a4e Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 15:56:35 +0100 Subject: [PATCH 09/13] Improved find --- src/gismo_data/service/server_repository_service.py | 2 +- src/gismo_data/service/user_repository_service.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gismo_data/service/server_repository_service.py b/src/gismo_data/service/server_repository_service.py index 09ed488..8187820 100644 --- a/src/gismo_data/service/server_repository_service.py +++ b/src/gismo_data/service/server_repository_service.py @@ -46,7 +46,7 @@ class ServerRepositoryService(ServerRepositoryABC): def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]: self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}') result = self._context.select(Server.get_select_by_discord_id_string(discord_id)) - if len(result) == 0: + if len(result) == 0 or result is None: return None return Server( diff --git a/src/gismo_data/service/user_repository_service.py b/src/gismo_data/service/user_repository_service.py index 6212c82..4d94e70 100644 --- a/src/gismo_data/service/user_repository_service.py +++ b/src/gismo_data/service/user_repository_service.py @@ -55,7 +55,7 @@ class UserRepositoryService(UserRepositoryABC): def find_user_by_discord_id(self, discord_id: int) -> Optional[User]: self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}') result = self._context.select(User.get_select_by_discord_id_string(discord_id)) - if len(result) == 0: + if len(result) == 0 or result is None: return None return User( From 9c7b00e2595c552509e976170c161120b3ce27ab Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 16:00:04 +0100 Subject: [PATCH 10/13] Fixed None check --- src/gismo_data/service/server_repository_service.py | 2 +- src/gismo_data/service/user_repository_service.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gismo_data/service/server_repository_service.py b/src/gismo_data/service/server_repository_service.py index 8187820..719fac8 100644 --- a/src/gismo_data/service/server_repository_service.py +++ b/src/gismo_data/service/server_repository_service.py @@ -46,7 +46,7 @@ class ServerRepositoryService(ServerRepositoryABC): def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]: self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}') result = self._context.select(Server.get_select_by_discord_id_string(discord_id)) - if len(result) == 0 or result is None: + if result is None or len(result) == 0: return None return Server( diff --git a/src/gismo_data/service/user_repository_service.py b/src/gismo_data/service/user_repository_service.py index 4d94e70..93b7460 100644 --- a/src/gismo_data/service/user_repository_service.py +++ b/src/gismo_data/service/user_repository_service.py @@ -55,7 +55,7 @@ class UserRepositoryService(UserRepositoryABC): def find_user_by_discord_id(self, discord_id: int) -> Optional[User]: self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}') result = self._context.select(User.get_select_by_discord_id_string(discord_id)) - if len(result) == 0 or result is None: + if result is None or len(result) == 0: return None return User( From 0bb5024c6aa300d9d76c069f49578fd7c7d459e6 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 17:22:37 +0100 Subject: [PATCH 11/13] Added intents --- src/gismo_core/service/bot_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gismo_core/service/bot_service.py b/src/gismo_core/service/bot_service.py index becdab4..2e8fa95 100644 --- a/src/gismo_core/service/bot_service.py +++ b/src/gismo_core/service/bot_service.py @@ -36,7 +36,7 @@ class BotService(BotServiceABC, commands.Bot): self._bot_settings: BotSettings = bot_settings # setup super - commands.Bot.__init__(self, command_prefix=bot_settings.prefix, help_command=None) + commands.Bot.__init__(self, command_prefix=bot_settings.prefix, help_command=None, intents=discord.Intents().all()) async def start_async(self): self._logger.trace(__name__, 'Try to connect to discord') From 93269908bc11a0d1c14f95f1df5c5052fa0f65d0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 30 Nov 2021 17:59:44 +0100 Subject: [PATCH 12/13] Improved database connection --- cpl-workspace.json | 3 +- src/gismo/main.py | 5 +- src/gismo/startup.py | 2 + src/gismo_data/abc/server_repository_abc.py | 2 +- src/gismo_data/abc/user_repository_abc.py | 2 +- src/gismo_data/db_context.py | 4 +- src/gismo_data/model/server.py | 14 +- src/gismo_data/model/user.py | 10 +- .../service/server_repository_service.py | 9 +- .../service/user_repository_service.py | 12 +- src/modules/database/__init__.py | 1 + src/modules/database/database.json | 43 +++++++ src/modules/database/database.py | 120 ++++++++++++++++++ src/modules/database/database_extension.py | 17 +++ 14 files changed, 225 insertions(+), 19 deletions(-) create mode 100644 src/modules/database/__init__.py create mode 100644 src/modules/database/database.json create mode 100644 src/modules/database/database.py create mode 100644 src/modules/database/database_extension.py diff --git a/cpl-workspace.json b/cpl-workspace.json index 72237cd..b0db2c0 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -9,7 +9,8 @@ "modules-core": "src/modules_core/modules-core.json", "boot-log": "src/modules/boot_log/boot-log.json", "level-generator": "tools/level_generator/level-generator.json", - "ontime-calculator": "tools/ontime_calculator/ontime-calculator.json" + "ontime-calculator": "tools/ontime_calculator/ontime-calculator.json", + "database": "src/modules/database/database.json" }, "Scripts": { "build-start": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../gismo; echo 'gismo:'; cpl build; cd ../../dist/gismo/build/gismo; bash gismo", diff --git a/src/gismo/main.py b/src/gismo/main.py index 4717405..87df32e 100644 --- a/src/gismo/main.py +++ b/src/gismo/main.py @@ -6,6 +6,7 @@ from cpl_core.application import ApplicationBuilder from gismo.application import Gismo from gismo.startup import Startup from modules.boot_log.boot_log_extension import BootLogExtension +from modules.database.database_extension import DatabaseExtension class Main: @@ -15,6 +16,7 @@ class Main: async def main(self): app_builder = ApplicationBuilder(Gismo) + app_builder.use_extension(DatabaseExtension) app_builder.use_extension(BootLogExtension) app_builder.use_startup(Startup) self._gismo: Gismo = await app_builder.build_async() @@ -31,7 +33,6 @@ if __name__ == '__main__': ml.run_until_complete(main.main()) except KeyboardInterrupt: ml.run_until_complete(main.stop()) - # (( # ( `) @@ -41,4 +42,4 @@ if __name__ == '__main__': # / ~/ # / ) ) ~ edraft # ___// | / -# `--' \_~-, \ No newline at end of file +# `--' \_~-, diff --git a/src/gismo/startup.py b/src/gismo/startup.py index a09983e..f359a18 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -19,6 +19,7 @@ from gismo_data.db_context import DBContext from gismo_data.service.server_repository_service import ServerRepositoryService from gismo_data.service.user_repository_service import UserRepositoryService from modules.boot_log.boot_log import BootLog +from modules.database.database import Database from modules_core.abc.module_abc import ModuleABC from modules_core.abc.module_service_abc import ModuleServiceABC from modules_core.service.module_service import ModuleService @@ -57,6 +58,7 @@ class Startup(StartupABC): services.add_transient(ServerRepositoryABC, ServerRepositoryService) services.add_transient(UserRepositoryABC, UserRepositoryService) + services.add_transient(ModuleABC, Database) services.add_transient(ModuleABC, BootLog) provider: ServiceProviderABC = services.build_service_provider() diff --git a/src/gismo_data/abc/server_repository_abc.py b/src/gismo_data/abc/server_repository_abc.py index 2c082f1..e8bfd38 100644 --- a/src/gismo_data/abc/server_repository_abc.py +++ b/src/gismo_data/abc/server_repository_abc.py @@ -24,7 +24,7 @@ class ServerRepositoryABC(ABC): def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]: pass @abstractmethod - def add_server(self, server: Server) -> int: pass + def add_server(self, server: Server): pass @abstractmethod def update_server(self, server: Server): pass diff --git a/src/gismo_data/abc/user_repository_abc.py b/src/gismo_data/abc/user_repository_abc.py index aa40998..c198753 100644 --- a/src/gismo_data/abc/user_repository_abc.py +++ b/src/gismo_data/abc/user_repository_abc.py @@ -24,7 +24,7 @@ class UserRepositoryABC(ABC): def find_user_by_discord_id(self, discord_id: int) -> Optional[User]: pass @abstractmethod - def add_user(self, user: User) -> int: pass + def add_user(self, user: User): pass @abstractmethod def update_user(self, user: User): pass diff --git a/src/gismo_data/db_context.py b/src/gismo_data/db_context.py index 77ea0b1..aae38ca 100644 --- a/src/gismo_data/db_context.py +++ b/src/gismo_data/db_context.py @@ -29,10 +29,10 @@ class DBContext(DatabaseContext): def save_changes(self): try: self._logger.trace(__name__, "Save changes") - super(DatabaseContext, self).save_changes + super(DBContext, self).save_changes() self._logger.debug(__name__, "Saved changes") except Exception as e: self._logger.error(__name__, "Saving changes failed", e) def select(self, statement: str) -> list[tuple]: - return super(DatabaseContext, self).select(statement) \ No newline at end of file + return super(DBContext, self).select(statement) \ No newline at end of file diff --git a/src/gismo_data/model/server.py b/src/gismo_data/model/server.py index ea6626f..207bc35 100644 --- a/src/gismo_data/model/server.py +++ b/src/gismo_data/model/server.py @@ -1,13 +1,19 @@ +from datetime import datetime from typing import Optional + from cpl_core.database import TableABC class Server(TableABC): - def __init__(self, dc_id: int, id=0): + def __init__(self, dc_id: int, created_at: datetime=None, modified_at: datetime=None, id=0): self._server_id = id self._discord_server_id = dc_id + 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 server_id(self) -> int: return self._server_id @@ -20,8 +26,10 @@ class Server(TableABC): def get_create_string() -> str: return str(f""" CREATE TABLE IF NOT EXISTS `Servers` ( - `ServerId` INT(30) NOT NULL AUTO_INCREMENT, - `DiscordServerId` INT(30) NOT NULL, + `ServerId` BIGINT NOT NULL AUTO_INCREMENT, + `DiscordServerId` BIGINT NOT NULL, + `CreatedAt` DATETIME(6), + `LastModifiedAt` DATETIME(6), PRIMARY KEY(`ServerId`) ); """) diff --git a/src/gismo_data/model/user.py b/src/gismo_data/model/user.py index da75bae..3bbc27a 100644 --- a/src/gismo_data/model/user.py +++ b/src/gismo_data/model/user.py @@ -1,3 +1,4 @@ +from datetime import datetime from typing import Optional from cpl_core.database import TableABC @@ -6,11 +7,15 @@ from gismo_data.model.server import Server class User(TableABC): - def __init__(self, dc_id: int, xp: int, server: Optional[Server], id=0): + def __init__(self, dc_id: int, xp: int, server: Optional[Server], created_at: datetime = None, modified_at: datetime = None, id=0): self._user_id = id self._discord_id = dc_id self._xp = xp 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 user_id(self) -> int: @@ -26,6 +31,7 @@ class User(TableABC): @xp.setter def xp(self, value: int): + self._modified_at = datetime.now().isoformat() self._xp = value @property @@ -42,7 +48,7 @@ class User(TableABC): `ServerId` BIGINT, `CreatedAt` DATETIME(6), `LastModifiedAt` DATETIME(6), - FOREIGN KEY (`UserId`) REFERENCES Servers(`ServerId`), + FOREIGN KEY (`ServerId`) REFERENCES Servers(`ServerId`), PRIMARY KEY(`UserId`) ); """) diff --git a/src/gismo_data/service/server_repository_service.py b/src/gismo_data/service/server_repository_service.py index 719fac8..cac5685 100644 --- a/src/gismo_data/service/server_repository_service.py +++ b/src/gismo_data/service/server_repository_service.py @@ -29,7 +29,7 @@ class ServerRepositoryService(ServerRepositoryABC): def get_server_by_id(self, id: int) -> Server: self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_id_string(id)}') - result = self._context.select(Server.get_select_by_id_string(id)) + result = self._context.select(Server.get_select_by_id_string(id))[0] return Server( result[1], id=result[0] @@ -49,15 +49,18 @@ class ServerRepositoryService(ServerRepositoryABC): if result is None or len(result) == 0: return None + result = result[0] + return Server( result[1], + result[2], + result[3], id=result[0] ) - def add_server(self, server: Server) -> int: + def add_server(self, server: Server): self._logger.trace(__name__, f'Send SQL command: {server.insert_string}') self._context.cursor.execute(server.insert_string) - return int(self._context.select("SELECT LAST_INSERT_ID();")[0]) def update_server(self, server: Server): self._logger.trace(__name__, f'Send SQL command: {server.udpate_string}') diff --git a/src/gismo_data/service/user_repository_service.py b/src/gismo_data/service/user_repository_service.py index 93b7460..6854313 100644 --- a/src/gismo_data/service/user_repository_service.py +++ b/src/gismo_data/service/user_repository_service.py @@ -23,6 +23,7 @@ class UserRepositoryService(UserRepositoryABC): self._logger.trace(__name__, f'Send SQL command: {User.get_select_all_string()}') results = self._context.select(User.get_select_all_string()) for result in results: + self._logger.trace(__name__, f'Get user with id {result[0]}') users.append(User( result[1], result[2], @@ -44,7 +45,7 @@ class UserRepositoryService(UserRepositoryABC): def get_user_by_discord_id(self, discord_id: int) -> User: self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}') - result = self._context.select(User.get_select_by_discord_id_string(discord_id)) + result = self._context.select(User.get_select_by_discord_id_string(discord_id))[0] return User( result[1], result[2], @@ -58,17 +59,20 @@ class UserRepositoryService(UserRepositoryABC): if result is None or len(result) == 0: return None + result = result[0] + return User( result[1], result[2], + result[3], + result[4], self._servers.get_server_by_id(result[3]), id=result[0] ) - def add_user(self, user: User) -> int: - self._logger.trace(__name__, f'Send SQL command: {user.insert_strin}') + def add_user(self, user: User): + self._logger.trace(__name__, f'Send SQL command: {user.insert_string}') self._context.cursor.execute(user.insert_string) - return int(self._context.select("SELECT LAST_INSERT_ID();")[0]) def update_user(self, user: User): self._logger.trace(__name__, f'Send SQL command: {user.udpate_string}') diff --git a/src/modules/database/__init__.py b/src/modules/database/__init__.py new file mode 100644 index 0000000..ad5eca3 --- /dev/null +++ b/src/modules/database/__init__.py @@ -0,0 +1 @@ +# imports: diff --git a/src/modules/database/database.json b/src/modules/database/database.json new file mode 100644 index 0000000..dfd40a3 --- /dev/null +++ b/src/modules/database/database.json @@ -0,0 +1,43 @@ +{ + "ProjectSettings": { + "Name": "modules/database", + "Version": { + "Major": "0", + "Minor": "0", + "Micro": "0" + }, + "Author": "", + "AuthorEmail": "", + "Description": "", + "LongDescription": "", + "URL": "", + "CopyrightDate": "", + "CopyrightName": "", + "LicenseName": "", + "LicenseDescription": "", + "Dependencies": [ + "sh_cpl-core>=2021.11.0.post1" + ], + "PythonVersion": ">=3.9.2", + "PythonPath": { + "linux": "" + }, + "Classifiers": [] + }, + "BuildSettings": { + "ProjectType": "library", + "SourcePath": "", + "OutputPath": "../../dist", + "Main": "modules/database.main", + "EntryPoint": "modules/database", + "IncludePackageData": false, + "Included": [], + "Excluded": [ + "*/__pycache__", + "*/logs", + "*/tests" + ], + "PackageData": {}, + "ProjectReferences": [] + } +} \ No newline at end of file diff --git a/src/modules/database/database.py b/src/modules/database/database.py new file mode 100644 index 0000000..7dd1569 --- /dev/null +++ b/src/modules/database/database.py @@ -0,0 +1,120 @@ +import asyncio +from datetime import datetime +import time + +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC + +from gismo_core.abc.bot_service_abc import BotServiceABC +from gismo_core.abc.message_service_abc import MessageServiceABC +from gismo_core.configuration.server_settings import ServerSettings +from gismo_data.abc.user_repository_abc import UserRepositoryABC +from gismo_data.model.server import Server +from gismo_data.model.user import User +from gismo_data.service.user_repository_service import ServerRepositoryABC +from modules_core.abc.events.on_ready_abc import OnReadyABC +from modules_core.abc.module_abc import ModuleABC + + +class Database(ModuleABC, OnReadyABC): + + def __init__( + self, + config: ConfigurationABC, + logger: LoggerABC, + bot: BotServiceABC, + db_context: DatabaseContextABC, + server_repo: ServerRepositoryABC, + user_repo: UserRepositoryABC + ): + self._config = config + + self._logger = logger + self._bot = bot + self._db_context = db_context + self._servers = server_repo + self._users = user_repo + + ModuleABC.__init__(self) + self._priorities[OnReadyABC] = 0 + self._logger.trace(__name__, f'Module {type(self)} loaded') + + def _validate_init_time(self): + try: + start_time = self._config.get_configuration('Database_StartTime') + init_time = round((datetime.now() - start_time).total_seconds(), 2) + self._config.add_configuration('Database_InitTime', init_time) + self._logger.debug(__name__, f'Database Init time: {init_time}s') + # print warning if initialisation took too long + if init_time >= 30: + self._logger.warn( + __name__, 'It takes long time to start the bot!') + + # print error if initialisation took way too long + elif init_time >= 90: + self._logger.error( + __name__, 'It takes very long time to start the bot!!!') + except Exception as e:# + self._logger.error(__name__, 'Database init time calculation failed', e) + return + + def _check_servers(self): + for g in self._bot.guilds: + g: discord.Guild = g + try: + server = self._servers.find_server_by_discord_id(g.id) + if server is not None: + return + + self._logger.warn(__name__, f'Server not found in database: {g.id}') + self._logger.debug(__name__, f'Add server: {g.id}') + self._servers.add_server(Server(g.id)) + self._db_context.save_changes() + + self._logger.debug(__name__, f'Added server: {g.id}') + except Exception as e: + self._logger.error(__name__, f'Cannot get server', e) + + results = self._servers.get_servers() + if results is None or len(results) == 0: + self._logger.error(__name__, f'Table Servers is empty!') + + def _check_users(self): + for g in self._bot.guilds: + g: discord.Guild = g + + try: + server = self._servers.find_server_by_discord_id(g.id) + if server is None: + self._logger.fatal(__name__, f'Server not found in database: {g.id}') + break + + for u in g.members: + u: discord.Member = u + user = self._users.find_user_by_discord_id(u.id) + if user is not None: + break + + 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, server)) + self._db_context.save_changes() + + self._logger.debug(__name__, f'Added User: {u.id}') + except Exception as e: + self._logger.error(__name__, f'Cannot get User', e) + + results = self._users.get_users() + if results is None or len(results) == 0: + self._logger.error(__name__, f'Table Users is empty!') + + async def on_ready(self): + self._logger.debug(__name__, f'Module {type(self)} started') + + self._check_servers() + self._check_users() + + self._validate_init_time() + self._logger.trace(__name__, f'Module {type(self)} stopped') \ No newline at end of file diff --git a/src/modules/database/database_extension.py b/src/modules/database/database_extension.py new file mode 100644 index 0000000..2fee14a --- /dev/null +++ b/src/modules/database/database_extension.py @@ -0,0 +1,17 @@ +from datetime import datetime + +from cpl_core.application.application_extension_abc import ApplicationExtensionABC +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceProviderABC +from cpl_core.logging import LoggerABC + + +class DatabaseExtension(ApplicationExtensionABC): + + def __init__(self): + pass + + async def run(self, config: ConfigurationABC, services: ServiceProviderABC): + logger: LoggerABC = services.get_service(LoggerABC) + logger.debug(__name__, 'Database extension started') + config.add_configuration('Database_StartTime', datetime.now()) From 074fa1ed4634b6442bb05ad8eeeca4fa136505aa Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 1 Dec 2021 17:53:36 +0100 Subject: [PATCH 13/13] Removed configs --- .gitignore | 1 + src/gismo/appsettings.coBIANYXra.json | 5 ---- src/gismo/appsettings.development.json | 28 ---------------------- src/gismo/appsettings.edrafts-lapi.json | 22 ----------------- src/gismo/appsettings.edrafts-pc.json | 32 ------------------------- src/gismo/appsettings.production.json | 28 ---------------------- src/gismo/appsettings.staging.json | 28 ---------------------- 7 files changed, 1 insertion(+), 143 deletions(-) delete mode 100644 src/gismo/appsettings.coBIANYXra.json delete mode 100644 src/gismo/appsettings.development.json delete mode 100644 src/gismo/appsettings.edrafts-lapi.json delete mode 100644 src/gismo/appsettings.edrafts-pc.json delete mode 100644 src/gismo/appsettings.production.json delete mode 100644 src/gismo/appsettings.staging.json diff --git a/.gitignore b/.gitignore index 6a660d8..457f297 100644 --- a/.gitignore +++ b/.gitignore @@ -140,4 +140,5 @@ cython_debug/ # custom vs code PythonImportHelper-v2-Completion.json +appsettings.*.json diff --git a/src/gismo/appsettings.coBIANYXra.json b/src/gismo/appsettings.coBIANYXra.json deleted file mode 100644 index eec0a76..0000000 --- a/src/gismo/appsettings.coBIANYXra.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Discord": { - "Token": "OTExNjM5NjE2MTAzMjUyMDM4.YZkUjQ.MCqPkOTIMdvMYrmt47lfrZ0inhg" - } -} diff --git a/src/gismo/appsettings.development.json b/src/gismo/appsettings.development.json deleted file mode 100644 index 7b125c1..0000000 --- a/src/gismo/appsettings.development.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "TimeFormatSettings": { - "DateFormat": "%Y-%m-%d", - "TimeFormat": "%H:%M:%S", - "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", - "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" - }, - "LoggingSettings": { - "Path": "logs/", - "Filename": "log_dev.log", - "ConsoleLogLevel": "DEBUG", - "FileLogLevel": "DEBUG" - }, - "Discord": { - "Token": "OTA5ODc4NDcyNzExNzU3ODQ1.YZKsXA.BXBszIF3z3wHpoe9s3pKfO3Yd5c" - }, - "Bot": { - "Prefix": "!gd", - "Servers": [ - { - "Id": "910199451145076828", - "LoginMessageChannelId": "910199452915093588", - "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert", - "MessageDeleteTimer": 2 - } - ] - } -} \ No newline at end of file diff --git a/src/gismo/appsettings.edrafts-lapi.json b/src/gismo/appsettings.edrafts-lapi.json deleted file mode 100644 index 1a0300b..0000000 --- a/src/gismo/appsettings.edrafts-lapi.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "LoggingSettings": { - "Path": "logs/", - "Filename": "log_dev.log", - "ConsoleLogLevel": "TRACE", - "FileLogLevel": "TRACE" - }, - "Discord": { - "Token": "OTExNTc0NDQyMzMxNzM0MDI2.YZjX2w.9yhsrTfrmkoDUqRJVzV5FVEwF3U" - }, - "Bot": { - "Prefix": "!gde", - "Servers": [ - { - "Id": "910199451145076828", - "LoginMessageChannelId": "910199452915093588", - "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert", - "MessageDeleteTimer": 2 - } - ] - } -} \ No newline at end of file diff --git a/src/gismo/appsettings.edrafts-pc.json b/src/gismo/appsettings.edrafts-pc.json deleted file mode 100644 index ef10539..0000000 --- a/src/gismo/appsettings.edrafts-pc.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "LoggingSettings": { - "Path": "logs/", - "Filename": "log_dev.log", - "ConsoleLogLevel": "TRACE", - "FileLogLevel": "TRACE" - }, - "DatabaseSettings": { - "Host": "localhost", - "User": "sh_gismo", - "Password": "c2hfZ2lzbW8=", - "Database": "sh_gismo_dev", - "Charset": "utf8mb4", - "UseUnicode": "true", - "Buffered": "true", - "AuthPlugin": "mysql_native_password" - }, - "Discord": { - "Token": "OTExNTc0NDQyMzMxNzM0MDI2.YZjX2w.9yhsrTfrmkoDUqRJVzV5FVEwF3U" - }, - "Bot": { - "Prefix": "!gde", - "Servers": [ - { - "Id": "910199451145076828", - "LoginMessageChannelId": "910199452915093588", - "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert", - "MessageDeleteTimer": 2 - } - ] - } -} \ No newline at end of file diff --git a/src/gismo/appsettings.production.json b/src/gismo/appsettings.production.json deleted file mode 100644 index 8ddbe25..0000000 --- a/src/gismo/appsettings.production.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "TimeFormatSettings": { - "DateFormat": "%Y-%m-%d", - "TimeFormat": "%H:%M:%S", - "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", - "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" - }, - "LoggingSettings": { - "Path": "logs/", - "Filename": "log_$start_time.log", - "ConsoleLogLevel": "ERROR", - "FileLogLevel": "WARN" - }, - "Discord": { - "Token": "OTA5ODc3NDg3MjEzODk5ODQ3.YZKrcQ.qwfDWBFdkOzxZZT10jUWG5fY2RA" - }, - "Bot": { - "Prefix": "!g", - "Servers": [ - { - "Id": "511824600884051979", - "LoginMessageChannelId": "521260270757347328", - "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert", - "MessageDeleteTimer": 2 - } - ] - } -} \ No newline at end of file diff --git a/src/gismo/appsettings.staging.json b/src/gismo/appsettings.staging.json deleted file mode 100644 index 31aaa85..0000000 --- a/src/gismo/appsettings.staging.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "TimeFormatSettings": { - "DateFormat": "%Y-%m-%d", - "TimeFormat": "%H:%M:%S", - "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", - "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" - }, - "LoggingSettings": { - "Path": "logs/", - "Filename": "log_staging_$start_time.log", - "ConsoleLogLevel": "DEBUG", - "FileLogLevel": "DEBUG" - }, - "Discord": { - "Token": "OTEwMjAxNjA1NDkwNjEwMjA3.YZPZTQ.kvMUuDUH_-qsllgkch8LYmXcKlo" - }, - "Bot": { - "Prefix": "!gt", - "Servers": [ - { - "Id": "511824600884051979", - "LoginMessageChannelId": "521260270757347328", - "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert", - "MessageDeleteTimer": 2 - } - ] - } -} \ No newline at end of file