From 4cd41c4b26da18f045d59a958e71829411a8ecca Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 21 Jul 2022 10:09:27 +0200 Subject: [PATCH 01/19] Set version and build project --- src/bot/__init__.py | 4 ++-- src/bot/bot.json | 6 +++--- src/bot_core/__init__.py | 4 ++-- src/bot_core/abc/__init__.py | 4 ++-- src/bot_core/configuration/__init__.py | 4 ++-- src/bot_core/pipes/__init__.py | 4 ++-- src/bot_core/service/__init__.py | 4 ++-- src/bot_data/__init__.py | 4 ++-- src/bot_data/abc/__init__.py | 4 ++-- src/bot_data/migration/__init__.py | 4 ++-- src/bot_data/model/__init__.py | 4 ++-- src/bot_data/service/__init__.py | 4 ++-- src/modules/admin/__init__.py | 4 ++-- src/modules/admin/command/__init__.py | 4 ++-- src/modules/base/__init__.py | 4 ++-- src/modules/base/abc/__init__.py | 4 ++-- src/modules/base/command/__init__.py | 4 ++-- src/modules/base/configuration/__init__.py | 4 ++-- src/modules/base/events/__init__.py | 4 ++-- src/modules/base/service/__init__.py | 4 ++-- src/modules/boot_log/__init__.py | 4 ++-- src/modules/boot_log/configuration/__init__.py | 4 ++-- src/modules/database/__init__.py | 4 ++-- src/modules/moderator/__init__.py | 4 ++-- src/modules/moderator/command/__init__.py | 4 ++-- src/modules/permission/__init__.py | 4 ++-- src/modules/permission/abc/__init__.py | 4 ++-- src/modules/permission/configuration/__init__.py | 4 ++-- src/modules/permission/events/__init__.py | 4 ++-- src/modules/permission/service/__init__.py | 4 ++-- 30 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/bot/__init__.py b/src/bot/__init__.py index 4624edde..e28eb092 100644 --- a/src/bot/__init__.py +++ b/src/bot/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot/bot.json b/src/bot/bot.json index 45a0d2b3..e744e3b3 100644 --- a/src/bot/bot.json +++ b/src/bot/bot.json @@ -2,9 +2,9 @@ "ProjectSettings": { "Name": "bot", "Version": { - "Major": "1", - "Minor": "0", - "Micro": "0.dev3" + "Major": "0", + "Minor": "1", + "Micro": "14" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/bot_core/__init__.py b/src/bot_core/__init__.py index 3f2c7bbe..04df7d2e 100644 --- a/src/bot_core/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_core/abc/__init__.py b/src/bot_core/abc/__init__.py index d9aecd72..469d543f 100644 --- a/src/bot_core/abc/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_core/configuration/__init__.py b/src/bot_core/configuration/__init__.py index a7bc5ad3..fe1b32c3 100644 --- a/src/bot_core/configuration/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_core/pipes/__init__.py b/src/bot_core/pipes/__init__.py index bf9acf00..08d99b3d 100644 --- a/src/bot_core/pipes/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_core/service/__init__.py b/src/bot_core/service/__init__.py index 08716a87..0b9970fd 100644 --- a/src/bot_core/service/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_data/__init__.py b/src/bot_data/__init__.py index 86962872..ada79234 100644 --- a/src/bot_data/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_data/abc/__init__.py b/src/bot_data/abc/__init__.py index 49d0500f..b555931a 100644 --- a/src/bot_data/abc/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_data/migration/__init__.py b/src/bot_data/migration/__init__.py index 99b6544e..7c59b5bc 100644 --- a/src/bot_data/migration/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_data/model/__init__.py b/src/bot_data/model/__init__.py index 53632478..2ae9de94 100644 --- a/src/bot_data/model/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/bot_data/service/__init__.py b/src/bot_data/service/__init__.py index 9f22307b..37813919 100644 --- a/src/bot_data/service/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/admin/__init__.py b/src/modules/admin/__init__.py index c50baf6c..99a9b9f9 100644 --- a/src/modules/admin/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/admin/command/__init__.py b/src/modules/admin/command/__init__.py index a0177640..6e758476 100644 --- a/src/modules/admin/command/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/base/__init__.py b/src/modules/base/__init__.py index c858a445..f843d189 100644 --- a/src/modules/base/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/base/abc/__init__.py b/src/modules/base/abc/__init__.py index 9257224a..7a9d5ca9 100644 --- a/src/modules/base/abc/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/base/command/__init__.py b/src/modules/base/command/__init__.py index 38fde0da..18fcb380 100644 --- a/src/modules/base/command/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/base/configuration/__init__.py b/src/modules/base/configuration/__init__.py index e0cd17aa..11a799ad 100644 --- a/src/modules/base/configuration/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/base/events/__init__.py b/src/modules/base/events/__init__.py index ea617632..a6eae56a 100644 --- a/src/modules/base/events/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/base/service/__init__.py b/src/modules/base/service/__init__.py index 2524e658..448a2cf2 100644 --- a/src/modules/base/service/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/boot_log/__init__.py b/src/modules/boot_log/__init__.py index 36d89a83..be817848 100644 --- a/src/modules/boot_log/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/boot_log/configuration/__init__.py b/src/modules/boot_log/configuration/__init__.py index b34945fb..766c534b 100644 --- a/src/modules/boot_log/configuration/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/database/__init__.py b/src/modules/database/__init__.py index 5e264dd8..3f729c4c 100644 --- a/src/modules/database/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/moderator/__init__.py b/src/modules/moderator/__init__.py index 0f79339b..ffc4f675 100644 --- a/src/modules/moderator/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/moderator/command/__init__.py b/src/modules/moderator/command/__init__.py index a24186f4..023daf5f 100644 --- a/src/modules/moderator/command/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/permission/__init__.py b/src/modules/permission/__init__.py index df287f2d..8b59ce1c 100644 --- a/src/modules/permission/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/permission/abc/__init__.py b/src/modules/permission/abc/__init__.py index 22bf468b..01cd49b4 100644 --- a/src/modules/permission/abc/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/permission/configuration/__init__.py b/src/modules/permission/configuration/__init__.py index 93c6bedb..f0482d9f 100644 --- a/src/modules/permission/configuration/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/permission/events/__init__.py b/src/modules/permission/events/__init__.py index f10c80cc..4935e287 100644 --- a/src/modules/permission/events/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') diff --git a/src/modules/permission/service/__init__.py b/src/modules/permission/service/__init__.py index 61f25267..a30dfa9c 100644 --- a/src/modules/permission/service/__init__.py +++ b/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__ = '1.0.0.dev3' +__version__ = '0.1.14' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='1', minor='0', micro='0.dev3') +version_info = VersionInfo(major='0', minor='1', micro='14') -- 2.45.2 From 709767c3a081585a664ed52e4da47831dfdc315f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 30 Sep 2022 17:03:44 +0200 Subject: [PATCH 02/19] First fixes #38 --- src/bot/bot.json | 4 +- .../config/appsettings.edrafts-pc-ubuntu.json | 59 +++++++++++++++++++ src/bot/main.py | 2 + .../user_joined_voice_channel_service.py | 2 +- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/bot/config/appsettings.edrafts-pc-ubuntu.json diff --git a/src/bot/bot.json b/src/bot/bot.json index e744e3b3..0fa1408b 100644 --- a/src/bot/bot.json +++ b/src/bot/bot.json @@ -17,8 +17,8 @@ "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ "cpl-core>=2022.7.0.post4", - "cpl-translation==2022.7.0.post2", - "cpl-query==2022.7.0", + "cpl-translation==2022.10rc2", + "cpl-query==2022.10rc2", "cpl-discord==2022.7.0.post4" ], "DevDependencies": [ diff --git a/src/bot/config/appsettings.edrafts-pc-ubuntu.json b/src/bot/config/appsettings.edrafts-pc-ubuntu.json new file mode 100644 index 00000000..8c26c3ea --- /dev/null +++ b/src/bot/config/appsettings.edrafts-pc-ubuntu.json @@ -0,0 +1,59 @@ +{ + "LoggingSettings": { + "Path": "logs/", + "Filename": "log_dev.log", + "ConsoleLogLevel": "DEBUG", + "FileLogLevel": "TRACE" + }, + "DatabaseSettings": { + "Host": "localhost", + "User": "kd_kdb", + "Password": "VGpZcihrb0N2T2MyZUlURQ==", + "Database": "keksdose_bot_dev", + "Charset": "utf8mb4", + "UseUnicode": "true", + "Buffered": "true", + "AuthPlugin": "mysql_native_password" + }, + "DiscordBot": { + "Token": "OTk4MTYwNDI3Njg5MTgxMjM3.GI7h67.BqD6Lu1Tz0MuG8iktYrcLnHi1pNozyMiWFGTKI", + "Prefix": "!ke " + }, + "Bot": { + "910199451145076828": { + "MessageDeleteTimer": 2 + }, + "Technicians": [ + 240160344557879316 + ], + "DeployFilesPath": "../../deploy" + }, + "Base": { + "910199451145076828": { + "MaxVoiceStateHours": 24, + "XpPerMessage": 2, + "XpPerOntimeHour": 4, + "AFKChannelIds": [ + 910199452915093593, + 910199452915093594 + ], + "AFKCommandChannelId": 910199452915093594, + "HelpCommandReferenceUrl": "https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle" + } + }, + "BootLog": { + "910199451145076828": { + "LoginMessageChannelId": "910199452915093588" + } + }, + "Permission": { + "910199451145076828": { + "AdminRoleIds": [ + 925072155203477584 + ], + "ModeratorRoleIds": [ + 925072209884635167 + ] + } + } +} diff --git a/src/bot/main.py b/src/bot/main.py index c2e53cf0..0bfb5a82 100644 --- a/src/bot/main.py +++ b/src/bot/main.py @@ -28,6 +28,8 @@ class Program: await self.app.run_async() async def stop(self): + if self.app is None: + return await self.app.stop_async() diff --git a/src/bot_data/service/user_joined_voice_channel_service.py b/src/bot_data/service/user_joined_voice_channel_service.py index bbcb3c99..05e98244 100644 --- a/src/bot_data/service/user_joined_voice_channel_service.py +++ b/src/bot_data/service/user_joined_voice_channel_service.py @@ -2,7 +2,7 @@ from typing import Optional from cpl_core.database.context import DatabaseContextABC from cpl_core.logging import LoggerABC -from cpl_query.extension import List, IterableABC +from cpl_query.extension import List from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel -- 2.45.2 From b936e569aa0995d9ac64342362baede45cb81ce2 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 30 Sep 2022 17:24:02 +0200 Subject: [PATCH 03/19] Build new version and fixed deps #38 --- src/bot/__init__.py | 4 ++-- src/bot/bot.json | 14 +++++++------- src/bot_core/__init__.py | 4 ++-- src/bot_core/abc/__init__.py | 4 ++-- src/bot_core/bot-core.json | 6 +++--- src/bot_core/configuration/__init__.py | 4 ++-- src/bot_core/pipes/__init__.py | 4 ++-- src/bot_core/service/__init__.py | 4 ++-- src/bot_data/__init__.py | 4 ++-- src/bot_data/abc/__init__.py | 4 ++-- src/bot_data/bot-data.json | 6 +++--- src/bot_data/migration/__init__.py | 4 ++-- src/bot_data/model/__init__.py | 4 ++-- src/bot_data/service/__init__.py | 4 ++-- src/modules/admin/__init__.py | 4 ++-- src/modules/admin/admin.json | 4 ++-- src/modules/admin/command/__init__.py | 4 ++-- src/modules/base/__init__.py | 4 ++-- src/modules/base/abc/__init__.py | 4 ++-- src/modules/base/base.json | 4 ++-- src/modules/base/command/__init__.py | 4 ++-- src/modules/base/configuration/__init__.py | 4 ++-- src/modules/base/events/__init__.py | 4 ++-- src/modules/base/service/__init__.py | 4 ++-- src/modules/boot_log/__init__.py | 4 ++-- src/modules/boot_log/boot-log.json | 4 ++-- src/modules/boot_log/configuration/__init__.py | 4 ++-- src/modules/database/__init__.py | 4 ++-- src/modules/database/database.json | 4 ++-- src/modules/database/database_on_ready_event.py | 10 +++++++--- src/modules/moderator/__init__.py | 4 ++-- src/modules/moderator/command/__init__.py | 4 ++-- src/modules/moderator/moderator.json | 4 ++-- src/modules/permission/__init__.py | 4 ++-- src/modules/permission/abc/__init__.py | 4 ++-- src/modules/permission/configuration/__init__.py | 4 ++-- src/modules/permission/events/__init__.py | 4 ++-- src/modules/permission/permission.json | 4 ++-- src/modules/permission/service/__init__.py | 4 ++-- 39 files changed, 90 insertions(+), 86 deletions(-) diff --git a/src/bot/__init__.py b/src/bot/__init__.py index e28eb092..30520581 100644 --- a/src/bot/__init__.py +++ b/src/bot/__init__.py @@ -15,7 +15,7 @@ __title__ = 'bot' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 sh-edraft.de' -__version__ = '0.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot/bot.json b/src/bot/bot.json index 0fa1408b..1ebf34f1 100644 --- a/src/bot/bot.json +++ b/src/bot/bot.json @@ -3,8 +3,8 @@ "Name": "bot", "Version": { "Major": "0", - "Minor": "1", - "Micro": "14" + "Minor": "2", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,13 +16,13 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.7.0.post4", - "cpl-translation==2022.10rc2", - "cpl-query==2022.10rc2", - "cpl-discord==2022.7.0.post4" + "cpl-core>=2022.10.0", + "cpl-translation>=2022.10.0", + "cpl-query>=2022.10.0", + "cpl-discord>=2022.10.0" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post2" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/bot_core/__init__.py b/src/bot_core/__init__.py index 04df7d2e..6ba98ff0 100644 --- a/src/bot_core/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_core/abc/__init__.py b/src/bot_core/abc/__init__.py index 469d543f..aac72ca3 100644 --- a/src/bot_core/abc/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_core/bot-core.json b/src/bot_core/bot-core.json index 93f908da..6720bf0f 100644 --- a/src/bot_core/bot-core.json +++ b/src/bot_core/bot-core.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "0", - "Micro": "0.dev1" + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,10 +16,10 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.7.0" + "cpl-core>=2022.10.0" ], "DevDependencies": [ - "cpl-cli>=2022.7.0" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/bot_core/configuration/__init__.py b/src/bot_core/configuration/__init__.py index fe1b32c3..5c540e04 100644 --- a/src/bot_core/configuration/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_core/pipes/__init__.py b/src/bot_core/pipes/__init__.py index 08d99b3d..381e147f 100644 --- a/src/bot_core/pipes/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_core/service/__init__.py b/src/bot_core/service/__init__.py index 0b9970fd..1775598a 100644 --- a/src/bot_core/service/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_data/__init__.py b/src/bot_data/__init__.py index ada79234..526ef397 100644 --- a/src/bot_data/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_data/abc/__init__.py b/src/bot_data/abc/__init__.py index b555931a..6d4ca870 100644 --- a/src/bot_data/abc/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_data/bot-data.json b/src/bot_data/bot-data.json index 0a328b86..e92af7de 100644 --- a/src/bot_data/bot-data.json +++ b/src/bot_data/bot-data.json @@ -4,7 +4,7 @@ "Version": { "Major": "1", "Minor": "0", - "Micro": "0.dev1" + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,10 +16,10 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.7.0" + "cpl-core>=2022.10.0" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post1" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/bot_data/migration/__init__.py b/src/bot_data/migration/__init__.py index 7c59b5bc..40311e46 100644 --- a/src/bot_data/migration/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_data/model/__init__.py b/src/bot_data/model/__init__.py index 2ae9de94..35cd1af1 100644 --- a/src/bot_data/model/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/bot_data/service/__init__.py b/src/bot_data/service/__init__.py index 37813919..f268cc0a 100644 --- a/src/bot_data/service/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/admin/__init__.py b/src/modules/admin/__init__.py index 99a9b9f9..daf704dd 100644 --- a/src/modules/admin/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/admin/admin.json b/src/modules/admin/admin.json index 6c2ac50b..446e16f3 100644 --- a/src/modules/admin/admin.json +++ b/src/modules/admin/admin.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.7.0.post5" + "cpl-core>=2022.10.0.post5" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post2" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/modules/admin/command/__init__.py b/src/modules/admin/command/__init__.py index 6e758476..6ebd80ad 100644 --- a/src/modules/admin/command/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/base/__init__.py b/src/modules/base/__init__.py index f843d189..b89988ff 100644 --- a/src/modules/base/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/base/abc/__init__.py b/src/modules/base/abc/__init__.py index 7a9d5ca9..ac238cec 100644 --- a/src/modules/base/abc/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/base/base.json b/src/modules/base/base.json index 47c6c442..4371622c 100644 --- a/src/modules/base/base.json +++ b/src/modules/base/base.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.7.0.post2" + "cpl-core>=2022.10.0.post2" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post2" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/modules/base/command/__init__.py b/src/modules/base/command/__init__.py index 18fcb380..c38e8b4e 100644 --- a/src/modules/base/command/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/base/configuration/__init__.py b/src/modules/base/configuration/__init__.py index 11a799ad..973a4814 100644 --- a/src/modules/base/configuration/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/base/events/__init__.py b/src/modules/base/events/__init__.py index a6eae56a..5d993630 100644 --- a/src/modules/base/events/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/base/service/__init__.py b/src/modules/base/service/__init__.py index 448a2cf2..24e4a38c 100644 --- a/src/modules/base/service/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +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 be817848..4cb82f60 100644 --- a/src/modules/boot_log/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/boot_log/boot-log.json b/src/modules/boot_log/boot-log.json index a60ba335..bf1e0b5b 100644 --- a/src/modules/boot_log/boot-log.json +++ b/src/modules/boot_log/boot-log.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.7.0.post2" + "cpl-core>=2022.10.0.post2" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post2" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/modules/boot_log/configuration/__init__.py b/src/modules/boot_log/configuration/__init__.py index 766c534b..307f52fb 100644 --- a/src/modules/boot_log/configuration/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/database/__init__.py b/src/modules/database/__init__.py index 3f729c4c..5ffb50d2 100644 --- a/src/modules/database/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/database/database.json b/src/modules/database/database.json index 1107ef1c..efcaea3f 100644 --- a/src/modules/database/database.json +++ b/src/modules/database/database.json @@ -16,10 +16,10 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.7.0.post2" + "cpl-core>=2022.10.0.post2" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post2" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/modules/database/database_on_ready_event.py b/src/modules/database/database_on_ready_event.py index dba4ba46..fab4dc0a 100644 --- a/src/modules/database/database_on_ready_event.py +++ b/src/modules/database/database_on_ready_event.py @@ -8,6 +8,7 @@ from cpl_core.logging import LoggerABC from cpl_discord.events import OnReadyABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC @@ -20,6 +21,7 @@ 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.user_repository_service import ServerRepositoryABC +from modules.base.configuration.base_server_settings import BaseServerSettings class DatabaseOnReadyEvent(OnReadyABC): @@ -35,7 +37,8 @@ class DatabaseOnReadyEvent(OnReadyABC): client_repo: ClientRepositoryABC, known_users: KnownUserRepositoryABC, user_joins: UserJoinedServerRepositoryABC, - user_joins_vc: UserJoinedVoiceChannelRepositoryABC + user_joins_vc: UserJoinedVoiceChannelRepositoryABC, + dtp: DateTimeOffsetPipe ): self._config = config @@ -48,6 +51,7 @@ class DatabaseOnReadyEvent(OnReadyABC): self._known_users = known_users self._user_joins = user_joins self._user_joins_vc = user_joins_vc + self._dtp = dtp OnReadyABC.__init__(self) self._logger.info(__name__, f'Module {type(self)} loaded') @@ -213,7 +217,7 @@ class DatabaseOnReadyEvent(OnReadyABC): m: discord.Member = u self._logger.warn(__name__, f'Active UserJoinedServer not found in database: {guild.id}:{u.id}@{m.joined_at}') self._logger.debug(__name__, f'Add UserJoinedServer: {guild.id}:{u.id}@{m.joined_at}') - self._user_joins.add_user_joined_server(UserJoinedServer(user, m.joined_at, None)) + self._user_joins.add_user_joined_server(UserJoinedServer(user, self._dtp.transform(m.joined_at), None)) self._db_context.save_changes() self._logger.debug(__name__, f'Added UserJoinedServer: {u.id}') @@ -267,7 +271,7 @@ class DatabaseOnReadyEvent(OnReadyABC): for join in joins: self._logger.warn(__name__, f'Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}') join.leaved_on = datetime.now() - settings: BaseSettings = self._config.get_configuration(f'BaseServerSettings_{guild.id}') + settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{guild.id}') if ((join.leaved_on - join.joined_on).total_seconds() / 60 / 60) > settings.max_voice_state_hours: join.leaved_on = join.joined_on + timedelta(hours=settings.max_voice_state_hours) diff --git a/src/modules/moderator/__init__.py b/src/modules/moderator/__init__.py index ffc4f675..613869fb 100644 --- a/src/modules/moderator/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/moderator/command/__init__.py b/src/modules/moderator/command/__init__.py index 023daf5f..17bf6f16 100644 --- a/src/modules/moderator/command/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/moderator/moderator.json b/src/modules/moderator/moderator.json index d4e025be..45dca24c 100644 --- a/src/modules/moderator/moderator.json +++ b/src/modules/moderator/moderator.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.7.0.post5" + "cpl-core>=2022.10.0.post5" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post2" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/modules/permission/__init__.py b/src/modules/permission/__init__.py index 8b59ce1c..58467172 100644 --- a/src/modules/permission/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/permission/abc/__init__.py b/src/modules/permission/abc/__init__.py index 01cd49b4..c78ae287 100644 --- a/src/modules/permission/abc/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/permission/configuration/__init__.py b/src/modules/permission/configuration/__init__.py index f0482d9f..aab3d9e0 100644 --- a/src/modules/permission/configuration/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/permission/events/__init__.py b/src/modules/permission/events/__init__.py index 4935e287..3cad9c9d 100644 --- a/src/modules/permission/events/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') diff --git a/src/modules/permission/permission.json b/src/modules/permission/permission.json index 324f1ec1..f5c96087 100644 --- a/src/modules/permission/permission.json +++ b/src/modules/permission/permission.json @@ -16,10 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.7.0.post2" + "cpl-core>=2022.10.0.post2" ], "DevDependencies": [ - "cpl-cli>=2022.7.0.post2" + "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/src/modules/permission/service/__init__.py b/src/modules/permission/service/__init__.py index a30dfa9c..d3071613 100644 --- a/src/modules/permission/service/__init__.py +++ b/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.1.14' +__version__ = '0.2.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='1', micro='14') +version_info = VersionInfo(major='0', minor='2', micro='0') -- 2.45.2 From 51fec48cdaef257deaff0125046178a2d95077d1 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 1 Oct 2022 23:12:35 +0200 Subject: [PATCH 04/19] Added docker support --- cpl-workspace.json | 6 +- docker-compose.yml | 25 +++++ dockerfile | 16 +++ src/bot/config/appsettings.production.json | 11 ++ src/bot/startup_discord_extension.py | 2 - src/modules/admin/command/deploy_command.py | 106 -------------------- 6 files changed, 57 insertions(+), 109 deletions(-) create mode 100644 docker-compose.yml create mode 100644 dockerfile delete mode 100644 src/modules/admin/command/deploy_command.py diff --git a/cpl-workspace.json b/cpl-workspace.json index e2da15e5..098991ab 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -15,7 +15,11 @@ "Scripts": { "prod": "export KDB_ENVIRONMENT=production; export KDB_NAME=KDB-Prod; cpl start;", "stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;", - "dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;" + "dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;", + + "build-docker": "cpl b; docker-compose down; docker build -t kdb .", + "compose": "docker-compose up -d", + "docker": "cpl build-docker; cpl compose;" } } } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..07fc8d34 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3.9" + +services: + kdb_1: + image: kdb + container_name: kdb_1 + depends_on: + - kdb_db_1 + environment: + KDB_TOKEN: "" + KDB_PREFIX: "!k " + restart: unless-stopped + + kdb_db_1: + image: mysql:latest + container_name: kdb_db_1 + command: mysqld --default-authentication-plugin=mysql_native_password + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: "kd_kdb" + MYSQL_USER: "kd_kdb" + MYSQL_PASSWORD: "kd_kdb" + MYSQL_DATABASE: "kd_kdb" + ports: + - "3307:3306" \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..9767ceb4 --- /dev/null +++ b/dockerfile @@ -0,0 +1,16 @@ +# syntax=docker/dockerfile:1 +FROM python:3.10 + +WORKDIR /app +COPY ./dist/bot/build/ . + +RUN pip install cpl-core --extra-index-url https://pip.sh-edraft.de +RUN pip install cpl-discord --extra-index-url https://pip.sh-edraft.de +RUN pip install cpl-query --extra-index-url https://pip.sh-edraft.de +RUN pip install cpl-translation --extra-index-url https://pip.sh-edraft.de + +ENV KDB_TOKEN="" +ENV KDB_PREFIX="!kdb " +ENV KDB_ENVIRONMENT="production" + +CMD [ "bash", "/app/bot/bot"] diff --git a/src/bot/config/appsettings.production.json b/src/bot/config/appsettings.production.json index c6259daa..91872272 100644 --- a/src/bot/config/appsettings.production.json +++ b/src/bot/config/appsettings.production.json @@ -17,6 +17,17 @@ "de" ] }, + "DatabaseSettings": { + "Host": "192.168.0.40", + "User": "kd_kdb", + "Password": "a2Rfa2Ri", + "Database": "kd_kdb", + "Port": "3307", + "Charset": "utf8mb4", + "UseUnicode": "true", + "Buffered": "true", + "AuthPlugin": "mysql_native_password" + }, "Bot": { "650366049023295514": { "MessageDeleteTimer": 2 diff --git a/src/bot/startup_discord_extension.py b/src/bot/startup_discord_extension.py index 7a389e4e..4d20e684 100644 --- a/src/bot/startup_discord_extension.py +++ b/src/bot/startup_discord_extension.py @@ -5,7 +5,6 @@ from cpl_core.environment import ApplicationEnvironmentABC from cpl_discord import get_discord_collection from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum -from modules.admin.command.deploy_command import DeployCommand from modules.admin.command.restart_command import RestartCommand from modules.admin.command.shutdown_command import ShutdownCommand from modules.base.command.afk_command import AFKCommand @@ -40,7 +39,6 @@ class StartupDiscordExtension(StartupExtensionABC): # admin dc.add_command(RestartCommand) dc.add_command(ShutdownCommand) - dc.add_command(DeployCommand) # moderator dc.add_command(PurgeCommand) # simple diff --git a/src/modules/admin/command/deploy_command.py b/src/modules/admin/command/deploy_command.py deleted file mode 100644 index 948ecc90..00000000 --- a/src/modules/admin/command/deploy_command.py +++ /dev/null @@ -1,106 +0,0 @@ -import os -import shutil -import zipfile -from io import BytesIO - -import requests -from cpl_core.configuration import ConfigurationABC -from cpl_core.environment import ApplicationEnvironmentABC -from cpl_core.logging import LoggerABC -from cpl_discord.command import DiscordCommandABC -from cpl_discord.service import DiscordBotServiceABC -from cpl_translation import TranslatePipe -from discord.ext import commands -from discord.ext.commands import Context - -from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC -from bot_core.abc.message_service_abc import MessageServiceABC -from bot_core.configuration.bot_settings import BotSettings - - -class DeployCommand(DiscordCommandABC): - - def __init__( - self, - logger: LoggerABC, - config: ConfigurationABC, - message_service: MessageServiceABC, - bot: DiscordBotServiceABC, - client_utils: ClientUtilsServiceABC, - translate: TranslatePipe, - bot_settings: BotSettings, - env: ApplicationEnvironmentABC - ): - DiscordCommandABC.__init__(self) - - self._logger = logger - self._config = config - self._message_service = message_service - self._bot = bot - self._client_utils = client_utils - self._t = translate - self._bot_settings = bot_settings - self._env = env - - self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - - @commands.command() - @commands.dm_only() - async def deploy(self, ctx: Context, old_version: str): - self._logger.debug(__name__, f'Received command deploy {ctx}') - - if ctx.author.id not in self._bot_settings.technicians: - await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message')) - self._logger.trace(__name__, f'Finished deploy command') - return - - blacklist = ['venv', 'start', 'latest'] - - if old_version in blacklist: - raise Exception(self._t.transform('common.errors.bad_argument')) - - if len(ctx.message.attachments) > 1: - raise IndexError(self._t.transform('common.errors.too_many_arguments')) - - if len(ctx.message.attachments) < 1: - raise IndexError(self._t.transform('common.errors.missing_required_argument')) - - try: - attachment_url = ctx.message.attachments[0].url - file_request = requests.get(attachment_url) - except Exception as e: - self._logger.error(__name__, f'An error occurred downloading the zip file', e) - await self._message_service.send_ctx_msg(ctx, self._t.transform('common.command_error')) - return - - try: - self._logger.debug(__name__, f'Deploying files to {self._bot_settings.deploy_file_path}/latest') - deploy_path = f'{self._bot_settings.deploy_file_path}/latest' - deploy_old_path = f'{self._bot_settings.deploy_file_path}/{old_version}' - - if os.path.exists(deploy_path): - self._logger.debug(__name__, f'Moving files of {self._bot_settings.deploy_file_path}/latest to {self._bot_settings.deploy_file_path}/{old_version}') - shutil.move(deploy_path, deploy_old_path) - os.makedirs(deploy_path) - - file = zipfile.ZipFile(BytesIO(file_request.content)) - file.extractall(deploy_path) - except Exception as e: - self._logger.error(__name__, f'An error occurred extracting the zip file', e) - await self._message_service.send_ctx_msg(ctx, self._t.transform('common.command_error'), without_tracking=True) - return - - try: - shutil.copy(f'{deploy_old_path}/bot/config/appsettings.{self._env.host_name}.json', f'{deploy_path}/bot/config/appsettings.{self._env.host_name}.json') - except Exception as e: - self._logger.error(__name__, f'An error occurred copying config file', e) - await self._message_service.send_ctx_msg(ctx, self._t.transform('common.command_error'), without_tracking=True) - return - - await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.deploy_message'), without_tracking=True) - - self._config.add_configuration('IS_RESTART', 'true') - await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.restart_message'), without_tracking=True) - await self._bot.stop_async() - - self._logger.trace(__name__, f'Finished deploy command') -- 2.45.2 From a4dc66396e6df1a7583e76237afd11bd4f7298a9 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 01:11:54 +0200 Subject: [PATCH 05/19] Migrated restart_command #42 --- src/bot_core/service/message_service.py | 3 +-- src/modules/admin/command/restart_command.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bot_core/service/message_service.py b/src/bot_core/service/message_service.py index f7696c63..1052edc6 100644 --- a/src/bot_core/service/message_service.py +++ b/src/bot_core/service/message_service.py @@ -104,8 +104,7 @@ class MessageService(MessageServiceABC): await asyncio.sleep(wait_before_delete) if is_persistent: - await self.delete_message(ctx.message, without_tracking) return if ctx.guild is not None: - await self.delete_messages(List(discord.Message, [msg, ctx.message]), ctx.guild.id) + await self.delete_message(msg) diff --git a/src/modules/admin/command/restart_command.py b/src/modules/admin/command/restart_command.py index e8de4f5b..d04308fa 100644 --- a/src/modules/admin/command/restart_command.py +++ b/src/modules/admin/command/restart_command.py @@ -35,7 +35,7 @@ class RestartCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() @commands.guild_only() async def restart(self, ctx: Context): self._logger.debug(__name__, f'Received command restart {ctx}') -- 2.45.2 From a939c741cbc987560f98b304de6fdcb919743089 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 01:52:32 +0200 Subject: [PATCH 06/19] Added logic to wait before handling command & migrated shutdown command #42 --- src/bot/translation/de.json | 3 ++- src/bot_core/abc/client_utils_service_abc.py | 5 ++++ src/bot_core/configuration/bot_settings.py | 8 ++++--- src/bot_core/service/client_utils_service.py | 23 ++++++++++++++++++- src/bot_core/service/message_service.py | 3 ++- src/modules/admin/command/restart_command.py | 3 +++ src/modules/admin/command/shutdown_command.py | 5 +++- .../boot_log/boot_log_on_ready_event.py | 3 ++- .../permission/service/permission_service.py | 4 ++-- 9 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/bot/translation/de.json b/src/bot/translation/de.json index 34beb4c2..655d5d67 100644 --- a/src/bot/translation/de.json +++ b/src/bot/translation/de.json @@ -37,7 +37,8 @@ "extension_already_loaded": "Fehler: Erweiterung wurde bereits geladen!", "extension_not_loaded": "Fehler: Erweiterung wurde nicht geladen!", "no_entry_point_error": "Fehler: Kein Eintrittspunkt!", - "extension_failed": "Fehler: Erweiterung ist fehlgeschlagen!" + "extension_failed": "Fehler: Erweiterung ist fehlgeschlagen!", + "bot_not_ready_yet": "Ey Alter! Gedulde dich doch mal! ..." } }, "modules": { diff --git a/src/bot_core/abc/client_utils_service_abc.py b/src/bot_core/abc/client_utils_service_abc.py index 5abf2ed1..570e0431 100644 --- a/src/bot_core/abc/client_utils_service_abc.py +++ b/src/bot_core/abc/client_utils_service_abc.py @@ -1,5 +1,7 @@ from abc import ABC, abstractmethod +from discord.ext.commands import Context + class ClientUtilsServiceABC(ABC): @@ -14,3 +16,6 @@ class ClientUtilsServiceABC(ABC): @abstractmethod def get_client(self, dc_ic: int, guild_id: int): pass + + @abstractmethod + async def check_if_bot_is_ready_yet_and_respond(self, ctx: Context) -> bool: pass diff --git a/src/bot_core/configuration/bot_settings.py b/src/bot_core/configuration/bot_settings.py index 4c0656b2..21036f49 100644 --- a/src/bot_core/configuration/bot_settings.py +++ b/src/bot_core/configuration/bot_settings.py @@ -12,16 +12,18 @@ class BotSettings(ConfigurationModelABC): def __init__(self): ConfigurationModelABC.__init__(self) - self._servers: List[ServerSettings] = List() - self._technicians: list[int] = [] + self._servers: List[ServerSettings] = List(ServerSettings) + self._technicians: List[int] = List(int) self._deploy_file_path = './' + self._wait_for_restart = 2 + self._wait_for_shutdown = 2 @property def servers(self) -> List[ServerSettings]: return self._servers @property - def technicians(self) -> list[int]: + def technicians(self) -> List[int]: return self._technicians @property diff --git a/src/bot_core/service/client_utils_service.py b/src/bot_core/service/client_utils_service.py index b608d49d..1a0d9d79 100644 --- a/src/bot_core/service/client_utils_service.py +++ b/src/bot_core/service/client_utils_service.py @@ -1,8 +1,13 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC from cpl_discord.service import DiscordBotServiceABC +from cpl_translation import TranslatePipe +from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC +from bot_core.abc.message_service_abc import MessageServiceABC from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC @@ -11,16 +16,24 @@ class ClientUtilsService(ClientUtilsServiceABC): def __init__( self, + config: ConfigurationABC, + logger: LoggerABC, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, clients: ClientRepositoryABC, - db: DatabaseContextABC + message_service: MessageServiceABC, + db: DatabaseContextABC, + t: TranslatePipe ): ClientUtilsServiceABC.__init__(self) + self._config = config + self._logger = logger self._bot = bot self._servers = servers self._clients = clients + self._message_service = message_service self._db = db + self._t = t def received_command(self, guild_id: int): server = self._servers.get_server_by_discord_id(guild_id) @@ -40,3 +53,11 @@ class ClientUtilsService(ClientUtilsServiceABC): server = self._servers.get_server_by_discord_id(guild_id) client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id) return client + + async def check_if_bot_is_ready_yet_and_respond(self, ctx: Context) -> bool: + if self._config.get_configuration('IS_READY') == 'true': + return True + + self._logger.debug(__name__, f'Bot is not ready yet {self._t.transform("common.errors.bot_not_ready_yet")}') + await self._message_service.send_ctx_msg(ctx, self._t.transform('common.errors.bot_not_ready_yet'), without_tracking=True) + return False diff --git a/src/bot_core/service/message_service.py b/src/bot_core/service/message_service.py index 1052edc6..3eaf7b0a 100644 --- a/src/bot_core/service/message_service.py +++ b/src/bot_core/service/message_service.py @@ -39,6 +39,7 @@ class MessageService(MessageServiceABC): guild_id = message.guild.id try: await message.delete() + await asyncio.sleep(server_st.message_delete_timer) except Exception as e: self._logger.error(__name__, f'Deleting message failed', e) else: @@ -107,4 +108,4 @@ class MessageService(MessageServiceABC): return if ctx.guild is not None: - await self.delete_message(msg) + await self.delete_message(msg, without_tracking) diff --git a/src/modules/admin/command/restart_command.py b/src/modules/admin/command/restart_command.py index d04308fa..7deda69b 100644 --- a/src/modules/admin/command/restart_command.py +++ b/src/modules/admin/command/restart_command.py @@ -39,6 +39,9 @@ class RestartCommand(DiscordCommandABC): @commands.guild_only() async def restart(self, ctx: Context): self._logger.debug(__name__, f'Received command restart {ctx}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return + self._client_utils.received_command(ctx.guild.id) if not self._permissions.is_member_moderator(ctx.author): diff --git a/src/modules/admin/command/shutdown_command.py b/src/modules/admin/command/shutdown_command.py index f4e68499..0eeeff34 100644 --- a/src/modules/admin/command/shutdown_command.py +++ b/src/modules/admin/command/shutdown_command.py @@ -35,10 +35,13 @@ class ShutdownCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() @commands.guild_only() async def shutdown(self, ctx: Context): self._logger.debug(__name__, f'Received command shutdown {ctx}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return + self._client_utils.received_command(ctx.guild.id) if not self._permissions.is_member_moderator(ctx.author): diff --git a/src/modules/boot_log/boot_log_on_ready_event.py b/src/modules/boot_log/boot_log_on_ready_event.py index 403f4628..d76a4f37 100644 --- a/src/modules/boot_log/boot_log_on_ready_event.py +++ b/src/modules/boot_log/boot_log_on_ready_event.py @@ -72,6 +72,7 @@ class BootLogOnReadyEvent(OnReadyABC): ), self._t.transform('modules.boot_log.login_message').format(init_time) ) - self._logger.info(__name__, 'Bot is ready') + self._config.add_configuration('IS_READY', 'true') + self._logger.info(__name__, 'Bot is ready') self._logger.trace(__name__, f'Module {type(self)} stopped') diff --git a/src/modules/permission/service/permission_service.py b/src/modules/permission/service/permission_service.py index f9caa63a..f6376ccc 100644 --- a/src/modules/permission/service/permission_service.py +++ b/src/modules/permission/service/permission_service.py @@ -106,7 +106,7 @@ class PermissionService(PermissionServiceABC): return self._moderators[g_id] def is_member_admin(self, member: discord.Member) -> bool: - return member in self._admins[member.guild.id] + return member.guild.id in self._admins and member in self._admins[member.guild.id] def is_member_moderator(self, member: discord.Member) -> bool: - return member in self._moderators[member.guild.id] or self.is_member_admin(member) + return member.guild.id in self._moderators and member in self._moderators[member.guild.id] or self.is_member_admin(member) -- 2.45.2 From 0dbf33a39f4fcf885e70e5916aa0e872f6a690fa Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 02:00:21 +0200 Subject: [PATCH 07/19] Migrated purge command --- src/modules/moderator/command/purge_command.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/moderator/command/purge_command.py b/src/modules/moderator/command/purge_command.py index 07ecd4bf..950ae823 100644 --- a/src/modules/moderator/command/purge_command.py +++ b/src/modules/moderator/command/purge_command.py @@ -35,12 +35,14 @@ class PurgeCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() @commands.guild_only() async def purge(self, ctx: Context): self._logger.debug(__name__, f'Received command purge {ctx}') - self._client_utils.received_command(ctx.guild.id) + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return + self._client_utils.received_command(ctx.guild.id) server_settings: ServerSettings = self._config.get_configuration(f'ServerSettings_{ctx.guild.id}') if not self._permissions.is_member_moderator(ctx.author): -- 2.45.2 From 7496a17cfa9e574a029712ccf1f14abfc96af20c Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 02:05:47 +0200 Subject: [PATCH 08/19] Migrated all other commands --- src/modules/base/command/afk_command.py | 4 +++- src/modules/base/command/help_command.py | 4 +++- src/modules/base/command/info_command.py | 4 +++- src/modules/base/command/ping_command.py | 4 +++- src/modules/base/command/user_info_command.py | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/modules/base/command/afk_command.py b/src/modules/base/command/afk_command.py index 10eb6af1..7e9fb698 100644 --- a/src/modules/base/command/afk_command.py +++ b/src/modules/base/command/afk_command.py @@ -34,10 +34,12 @@ class AFKCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() @commands.guild_only() async def afk(self, ctx: Context): self._logger.debug(__name__, f'Received command afk {ctx}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return self._client_utils.received_command(ctx.guild.id) settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}') diff --git a/src/modules/base/command/help_command.py b/src/modules/base/command/help_command.py index 4bf97471..9bbd7957 100644 --- a/src/modules/base/command/help_command.py +++ b/src/modules/base/command/help_command.py @@ -30,10 +30,12 @@ class HelpCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() @commands.guild_only() async def help(self, ctx: Context, persistent_flag: str = None): self._logger.debug(__name__, f'Received command help {ctx}:{persistent_flag}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return self._client_utils.received_command(ctx.guild.id) settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}') is_persistent = persistent_flag == '--stay' diff --git a/src/modules/base/command/info_command.py b/src/modules/base/command/info_command.py index d3c7de65..83560783 100644 --- a/src/modules/base/command/info_command.py +++ b/src/modules/base/command/info_command.py @@ -36,10 +36,12 @@ class InfoCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() @commands.guild_only() async def info(self, ctx: Context, *, wait: int = None): self._logger.debug(__name__, f'Received command info {ctx},{wait}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return self._client_utils.received_command(ctx.guild.id) client = self._client_utils.get_client(self._bot.user.id, ctx.guild.id) diff --git a/src/modules/base/command/ping_command.py b/src/modules/base/command/ping_command.py index f8a796ef..439b5a15 100644 --- a/src/modules/base/command/ping_command.py +++ b/src/modules/base/command/ping_command.py @@ -29,10 +29,12 @@ class PingCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() @commands.guild_only() async def ping(self, ctx: Context): self._logger.debug(__name__, f'Received command ping {ctx}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return self._client_utils.received_command(ctx.guild.id) await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.pong')) self._logger.trace(__name__, f'Finished ping command') diff --git a/src/modules/base/command/user_info_command.py b/src/modules/base/command/user_info_command.py index d9d646ba..200bfe66 100644 --- a/src/modules/base/command/user_info_command.py +++ b/src/modules/base/command/user_info_command.py @@ -50,10 +50,12 @@ class UserInfoCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command(name='user-info') + @commands.hybrid_command(name='user-info') @commands.guild_only() async def user_info(self, ctx: Context, member: Optional[discord.Member] = None, *, wait: int = None): self._logger.debug(__name__, f'Received command user-info {ctx}:{member},{wait}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return self._client_utils.received_command(ctx.guild.id) if not self._permissions.is_member_moderator(ctx.author): -- 2.45.2 From 8b55db172aebb0c854165224c9e8701a69840a18 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 02:07:05 +0200 Subject: [PATCH 09/19] Updated info command --- src/modules/base/command/info_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/base/command/info_command.py b/src/modules/base/command/info_command.py index 83560783..1ef1085a 100644 --- a/src/modules/base/command/info_command.py +++ b/src/modules/base/command/info_command.py @@ -60,7 +60,7 @@ class InfoCommand(DiscordCommandABC): embed.add_field(name=self._t.transform('modules.base.info.fields.deleted_message_count'), value=client.deleted_message_count, inline=False) embed.add_field(name=self._t.transform('modules.base.info.fields.received_command_count'), value=client.received_command_count) embed.add_field(name=self._t.transform('modules.base.info.fields.moved_users_count'), value=client.moved_users_count) - modules = ['Base', 'BootLog', 'Database', 'Permission'] + modules = ['Admin', 'Base', 'BootLog', 'Database', 'Moderator', 'Permission'] embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False) await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait) -- 2.45.2 From ac238b360a2e3b62346bbb4db99fa0dd6e3237b4 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 02:34:27 +0200 Subject: [PATCH 10/19] Added feature-flags --- src/bot/config/appsettings.development.json | 8 +++ .../config/appsettings.edrafts-pc-ubuntu.json | 8 +++ src/bot/config/appsettings.production.json | 8 +++ src/bot/config/appsettings.staging.json | 8 +++ src/bot/startup.py | 9 ++- src/bot/startup_discord_extension.py | 53 +++++++++------ .../configuration/feature_flags_settings.py | 65 +++++++++++++++++++ 7 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 src/bot_core/configuration/feature_flags_settings.py diff --git a/src/bot/config/appsettings.development.json b/src/bot/config/appsettings.development.json index 53ed5d70..d75fdfea 100644 --- a/src/bot/config/appsettings.development.json +++ b/src/bot/config/appsettings.development.json @@ -17,6 +17,14 @@ "de" ] }, + "FeatureFlag": { + "AdminModule": true, + "BaseModule": true, + "BootLogModule": true, + "DatabaseModule": true, + "ModeratorModule": true, + "PermissionModule": true + }, "DiscordBot": { "Token": "OTk4MTU5NjczODkzMDYwNzM4.GN3QyA.yvWO6L7Eu36gXQ7ARDs0Jg2J1VqIDnHLou5lT4", "Prefix": "!kd " diff --git a/src/bot/config/appsettings.edrafts-pc-ubuntu.json b/src/bot/config/appsettings.edrafts-pc-ubuntu.json index 8c26c3ea..6523b2d9 100644 --- a/src/bot/config/appsettings.edrafts-pc-ubuntu.json +++ b/src/bot/config/appsettings.edrafts-pc-ubuntu.json @@ -19,6 +19,14 @@ "Token": "OTk4MTYwNDI3Njg5MTgxMjM3.GI7h67.BqD6Lu1Tz0MuG8iktYrcLnHi1pNozyMiWFGTKI", "Prefix": "!ke " }, + "FeatureFlag": { + "AdminModule": true, + "BaseModule": true, + "BootLogModule": true, + "DatabaseModule": true, + "ModeratorModule": true, + "PermissionModule": true + }, "Bot": { "910199451145076828": { "MessageDeleteTimer": 2 diff --git a/src/bot/config/appsettings.production.json b/src/bot/config/appsettings.production.json index 91872272..1f2dd507 100644 --- a/src/bot/config/appsettings.production.json +++ b/src/bot/config/appsettings.production.json @@ -28,6 +28,14 @@ "Buffered": "true", "AuthPlugin": "mysql_native_password" }, + "FeatureFlag": { + "AdminModule": true, + "BaseModule": true, + "BootLogModule": true, + "DatabaseModule": true, + "ModeratorModule": true, + "PermissionModule": true + }, "Bot": { "650366049023295514": { "MessageDeleteTimer": 2 diff --git a/src/bot/config/appsettings.staging.json b/src/bot/config/appsettings.staging.json index b69da3dd..3ddd1c3f 100644 --- a/src/bot/config/appsettings.staging.json +++ b/src/bot/config/appsettings.staging.json @@ -17,6 +17,14 @@ "de" ] }, + "FeatureFlag": { + "AdminModule": true, + "BaseModule": true, + "BootLogModule": true, + "DatabaseModule": true, + "ModeratorModule": true, + "PermissionModule": true + }, "Bot": { "910199451145076828": { "MessageDeleteTimer": 4 diff --git a/src/bot/startup.py b/src/bot/startup.py index db5fd508..4f936340 100644 --- a/src/bot/startup.py +++ b/src/bot/startup.py @@ -10,6 +10,7 @@ from cpl_core.environment import ApplicationEnvironment from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_core.service.client_utils_service import ClientUtilsService from bot_core.service.message_service import MessageService @@ -39,6 +40,7 @@ class Startup(StartupABC): self._start_time = datetime.now() self._config: Optional[ConfigurationABC] = None + self._feature_flags: Optional[FeatureFlagsSettings] = None def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: environment.set_working_directory(os.path.dirname(os.path.realpath(__file__))) @@ -52,6 +54,7 @@ class Startup(StartupABC): configuration.add_configuration('Startup_StartTime', str(self._start_time)) self._config = configuration + self._feature_flags = configuration.get_configuration(FeatureFlagsSettings) return configuration def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: @@ -61,7 +64,8 @@ class Startup(StartupABC): services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) # general services - services.add_transient(BaseHelperABC, BaseHelperService) + if self._feature_flags.base_module: + services.add_transient(BaseHelperABC, BaseHelperService) services.add_transient(MessageServiceABC, MessageService) services.add_transient(ClientUtilsServiceABC, ClientUtilsService) @@ -69,7 +73,8 @@ class Startup(StartupABC): services.add_transient(DateTimeOffsetPipe) # module services - services.add_singleton(PermissionServiceABC, PermissionService) + if self._feature_flags.permission_module: + services.add_singleton(PermissionServiceABC, PermissionService) # data services services.add_transient(ServerRepositoryABC, ServerRepositoryService) diff --git a/src/bot/startup_discord_extension.py b/src/bot/startup_discord_extension.py index 4d20e684..8e7b93ec 100644 --- a/src/bot/startup_discord_extension.py +++ b/src/bot/startup_discord_extension.py @@ -1,3 +1,5 @@ +from typing import Optional + from cpl_core.application import StartupExtensionABC from cpl_core.configuration import ConfigurationABC from cpl_core.dependency_injection import ServiceCollectionABC @@ -5,6 +7,7 @@ from cpl_core.environment import ApplicationEnvironmentABC from cpl_discord import get_discord_collection from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from modules.admin.command.restart_command import RestartCommand from modules.admin.command.shutdown_command import ShutdownCommand from modules.base.command.afk_command import AFKCommand @@ -27,40 +30,52 @@ from modules.permission.events.permission_on_ready_event import PermissionOnRead class StartupDiscordExtension(StartupExtensionABC): def __init__(self): - pass + self._feature_flags: Optional[FeatureFlagsSettings] = None def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): - pass + self._feature_flags = config.get_configuration(FeatureFlagsSettings) def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services.add_discord() dc = get_discord_collection(services) """ commands """ # admin - dc.add_command(RestartCommand) - dc.add_command(ShutdownCommand) + if self._feature_flags.admin_module: + dc.add_command(RestartCommand) + dc.add_command(ShutdownCommand) # moderator - dc.add_command(PurgeCommand) + if self._feature_flags.moderator_module: + dc.add_command(PurgeCommand) # simple - dc.add_command(AFKCommand) - dc.add_command(HelpCommand) - dc.add_command(InfoCommand) - dc.add_command(PingCommand) - dc.add_command(UserInfoCommand) + if self._feature_flags.base_module: + dc.add_command(AFKCommand) + dc.add_command(HelpCommand) + dc.add_command(InfoCommand) + dc.add_command(PingCommand) + dc.add_command(UserInfoCommand) """ events """ # on_command_error - dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) + if self._feature_flags.base_module: + dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) # on_member_join - dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) + if self._feature_flags.base_module: + dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) # on_member_remove - dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent) + if self._feature_flags.base_module: + dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent) # on_member_update - dc.add_event(DiscordEventTypesEnum.on_member_update.value, PermissionOnMemberUpdateEvent) + if self._feature_flags.permission_module: + dc.add_event(DiscordEventTypesEnum.on_member_update.value, PermissionOnMemberUpdateEvent) # on_message - dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) + if self._feature_flags.base_module: + dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) # on_voice_state_update - dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) + if self._feature_flags.base_module: + dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) # on_ready - dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent) - dc.add_event(DiscordEventTypesEnum.on_ready.value, PermissionOnReadyEvent) - dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) # has to be last + if self._feature_flags.database_module: + dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent) + if self._feature_flags.permission_module: + dc.add_event(DiscordEventTypesEnum.on_ready.value, PermissionOnReadyEvent) + if self._feature_flags.boot_log_module: + dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) # has to be last diff --git a/src/bot_core/configuration/feature_flags_settings.py b/src/bot_core/configuration/feature_flags_settings.py new file mode 100644 index 00000000..8d280744 --- /dev/null +++ b/src/bot_core/configuration/feature_flags_settings.py @@ -0,0 +1,65 @@ +import traceback +from typing import Optional + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class FeatureFlagsSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._admin_module = False # 02.10.2022 #48 + self._base_module = True # 02.10.2022 #48 + self._boot_log_module = True # 02.10.2022 #48 + self._database_module = True # 02.10.2022 #48 + self._moderator_module = False # 02.10.2022 #48 + self._permission_module = True # 02.10.2022 #48 + + @property + def admin_module(self) -> bool: + return self._admin_module + + @property + def base_module(self) -> bool: + return self._base_module + + @property + def boot_log_module(self) -> bool: + return self._boot_log_module + + @property + def database_module(self) -> bool: + return self._database_module + + @property + def moderator_module(self) -> bool: + return self._moderator_module + + @property + def permission_module(self) -> bool: + return self._permission_module + + def from_dict(self, settings: dict): + try: + if 'AdminModule' in settings: + self._admin_module = settings['AdminModule'] + + if 'BaseModule' in settings: + self._base_module = settings['BaseModule'] + + if 'BootLogModule' in settings: + self._boot_log_module = settings['BootLogModule'] + + if 'DatabaseModule' in settings: + self._database_module = settings['DatabaseModule'] + + if 'ModeratorModule' in settings: + self._moderator_module = settings['ModeratorModule'] + + if 'PermissionModule' in settings: + self._permission_module = settings['PermissionModule'] + 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()}') -- 2.45.2 From 890cb6f6b5487b2d0786365131a957a3c10b62c7 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 02:54:08 +0200 Subject: [PATCH 11/19] Added feature-flags #48 --- src/bot/config/appsettings.development.json | 2 +- .../config/appsettings.edrafts-pc-ubuntu.json | 2 +- src/bot/config/appsettings.production.json | 2 +- src/bot/config/appsettings.staging.json | 2 +- src/bot/main.py | 14 ++++++---- src/bot/startup.py | 14 ---------- src/bot/startup_settings_extension.py | 28 +++++++++++++++++++ src/modules/boot_log/boot_log_extension.py | 5 ++++ src/modules/database/database_extension.py | 4 +++ 9 files changed, 49 insertions(+), 24 deletions(-) create mode 100644 src/bot/startup_settings_extension.py diff --git a/src/bot/config/appsettings.development.json b/src/bot/config/appsettings.development.json index d75fdfea..44dbc166 100644 --- a/src/bot/config/appsettings.development.json +++ b/src/bot/config/appsettings.development.json @@ -17,7 +17,7 @@ "de" ] }, - "FeatureFlag": { + "FeatureFlags": { "AdminModule": true, "BaseModule": true, "BootLogModule": true, diff --git a/src/bot/config/appsettings.edrafts-pc-ubuntu.json b/src/bot/config/appsettings.edrafts-pc-ubuntu.json index 6523b2d9..20585cb5 100644 --- a/src/bot/config/appsettings.edrafts-pc-ubuntu.json +++ b/src/bot/config/appsettings.edrafts-pc-ubuntu.json @@ -19,7 +19,7 @@ "Token": "OTk4MTYwNDI3Njg5MTgxMjM3.GI7h67.BqD6Lu1Tz0MuG8iktYrcLnHi1pNozyMiWFGTKI", "Prefix": "!ke " }, - "FeatureFlag": { + "FeatureFlags": { "AdminModule": true, "BaseModule": true, "BootLogModule": true, diff --git a/src/bot/config/appsettings.production.json b/src/bot/config/appsettings.production.json index 1f2dd507..515c60af 100644 --- a/src/bot/config/appsettings.production.json +++ b/src/bot/config/appsettings.production.json @@ -28,7 +28,7 @@ "Buffered": "true", "AuthPlugin": "mysql_native_password" }, - "FeatureFlag": { + "FeatureFlags": { "AdminModule": true, "BaseModule": true, "BootLogModule": true, diff --git a/src/bot/config/appsettings.staging.json b/src/bot/config/appsettings.staging.json index 3ddd1c3f..605fe7fc 100644 --- a/src/bot/config/appsettings.staging.json +++ b/src/bot/config/appsettings.staging.json @@ -17,7 +17,7 @@ "de" ] }, - "FeatureFlag": { + "FeatureFlags": { "AdminModule": true, "BaseModule": true, "BootLogModule": true, diff --git a/src/bot/main.py b/src/bot/main.py index 0bfb5a82..29c81fc1 100644 --- a/src/bot/main.py +++ b/src/bot/main.py @@ -8,6 +8,7 @@ from bot.application import Application from bot.startup import Startup from bot.startup_discord_extension import StartupDiscordExtension from bot.startup_migration_extension import StartupMigrationExtension +from bot.startup_settings_extension import StartupSettingsExtension from modules.boot_log.boot_log_extension import BootLogExtension from modules.database.database_extension import DatabaseExtension @@ -18,12 +19,13 @@ class Program: self.app: Optional[Application] = None async def start(self): - app_builder = ApplicationBuilder(Application) - app_builder.use_extension(StartupDiscordExtension) - app_builder.use_extension(StartupMigrationExtension) - app_builder.use_extension(BootLogExtension) - app_builder.use_extension(DatabaseExtension) - app_builder.use_startup(Startup) + app_builder = ApplicationBuilder(Application) \ + .use_extension(StartupSettingsExtension) \ + .use_extension(StartupDiscordExtension) \ + .use_extension(StartupMigrationExtension) \ + .use_extension(BootLogExtension) \ + .use_extension(DatabaseExtension) \ + .use_startup(Startup) self.app: Application = await app_builder.build_async() await self.app.run_async() diff --git a/src/bot/startup.py b/src/bot/startup.py index 4f936340..689c9819 100644 --- a/src/bot/startup.py +++ b/src/bot/startup.py @@ -1,5 +1,3 @@ -import os -from datetime import datetime from typing import Optional from cpl_core.application import StartupABC @@ -37,22 +35,10 @@ class Startup(StartupABC): def __init__(self): StartupABC.__init__(self) - self._start_time = datetime.now() - self._config: Optional[ConfigurationABC] = None self._feature_flags: Optional[FeatureFlagsSettings] = None def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: - environment.set_working_directory(os.path.dirname(os.path.realpath(__file__))) - configuration.add_environment_variables('KDB_') - configuration.add_environment_variables('DISCORD_') - - configuration.add_json_file(f'config/appsettings.json', optional=False) - configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True) - configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True) - - configuration.add_configuration('Startup_StartTime', str(self._start_time)) - self._config = configuration self._feature_flags = configuration.get_configuration(FeatureFlagsSettings) return configuration diff --git a/src/bot/startup_settings_extension.py b/src/bot/startup_settings_extension.py new file mode 100644 index 00000000..8c27e69b --- /dev/null +++ b/src/bot/startup_settings_extension.py @@ -0,0 +1,28 @@ +import os +from datetime import datetime + +from cpl_core.application import StartupExtensionABC +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceCollectionABC +from cpl_core.environment import ApplicationEnvironmentABC + + +class StartupSettingsExtension(StartupExtensionABC): + + def __init__(self): + self._start_time = datetime.now() + + def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironmentABC): + # this shit has to be done here because we need settings in subsequent startup extensions + environment.set_working_directory(os.path.dirname(os.path.realpath(__file__))) + configuration.add_environment_variables('KDB_') + configuration.add_environment_variables('DISCORD_') + + configuration.add_json_file(f'config/appsettings.json', optional=False) + configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True) + configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True) + + configuration.add_configuration('Startup_StartTime', str(self._start_time)) + + def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): + pass diff --git a/src/modules/boot_log/boot_log_extension.py b/src/modules/boot_log/boot_log_extension.py index 8bb36c7e..42db4b8e 100644 --- a/src/modules/boot_log/boot_log_extension.py +++ b/src/modules/boot_log/boot_log_extension.py @@ -5,6 +5,8 @@ from cpl_core.configuration import ConfigurationABC from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings + class BootLogExtension(ApplicationExtensionABC): @@ -12,6 +14,9 @@ class BootLogExtension(ApplicationExtensionABC): pass async def run(self, config: ConfigurationABC, services: ServiceProviderABC): + feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings) + if not feature_flags.boot_log_module: + return logger: LoggerABC = services.get_service(LoggerABC) logger.debug(__name__, 'BootLog extension started') config.add_configuration('Bot_StartTime', str(datetime.now())) diff --git a/src/modules/database/database_extension.py b/src/modules/database/database_extension.py index edcca9b9..883752bb 100644 --- a/src/modules/database/database_extension.py +++ b/src/modules/database/database_extension.py @@ -5,6 +5,7 @@ from cpl_core.configuration import ConfigurationABC from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_data.service.migration_service import MigrationService @@ -14,6 +15,9 @@ class DatabaseExtension(ApplicationExtensionABC): pass async def run(self, config: ConfigurationABC, services: ServiceProviderABC): + feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings) + if not feature_flags.database_module: + return logger: LoggerABC = services.get_service(LoggerABC) logger.debug(__name__, 'Database extension started') config.add_configuration('Database_StartTime', str(datetime.now())) -- 2.45.2 From 12cd5c904562234903cac38dfb85eba11f7b1b97 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 12:14:44 +0200 Subject: [PATCH 12/19] Added custom logging support #45 --- src/bot/application.py | 30 +++++++--- .../config/appsettings.edrafts-pc-ubuntu.json | 16 ++++- src/bot/startup.py | 29 +++++++-- src/bot/startup_discord_extension.py | 47 ++++++++------- src/bot_core/abc/custom_file_logger_abc.py | 60 +++++++++++++++++++ .../configuration/bot_logging_settings.py | 33 ++++++++++ .../configuration/file_logging_settings.py | 24 ++++++++ src/bot_core/logging/__init__.py | 1 + src/bot_core/logging/command_logger.py | 11 ++++ src/bot_core/logging/event_logger.py | 11 ++++ src/modules/admin/command/restart_command.py | 4 +- src/modules/admin/command/shutdown_command.py | 4 +- src/modules/base/command/afk_command.py | 4 +- src/modules/base/command/help_command.py | 4 +- src/modules/base/command/info_command.py | 4 +- src/modules/base/command/ping_command.py | 4 +- src/modules/base/command/user_info_command.py | 4 +- .../configuration/base_server_settings.py | 7 ++- .../base/events/base_on_command_event.py | 41 +++++++++++++ .../moderator/command/purge_command.py | 4 +- 20 files changed, 286 insertions(+), 56 deletions(-) create mode 100644 src/bot_core/abc/custom_file_logger_abc.py create mode 100644 src/bot_core/configuration/bot_logging_settings.py create mode 100644 src/bot_core/configuration/file_logging_settings.py create mode 100644 src/bot_core/logging/__init__.py create mode 100644 src/bot_core/logging/command_logger.py create mode 100644 src/bot_core/logging/event_logger.py create mode 100644 src/modules/base/events/base_on_command_event.py diff --git a/src/bot/application.py b/src/bot/application.py index f2088027..4b80eb9b 100644 --- a/src/bot/application.py +++ b/src/bot/application.py @@ -1,4 +1,4 @@ -from typing import Optional, Type +from typing import Optional, Type, Callable from cpl_core.configuration import ConfigurationABC, ConfigurationModelABC from cpl_core.console import Console @@ -9,8 +9,11 @@ from cpl_discord.configuration import DiscordBotSettings from cpl_discord.service import DiscordBotServiceABC, DiscordBotService from cpl_translation import TranslatePipe, TranslationServiceABC, TranslationSettings +from bot_core.configuration.bot_logging_settings import BotLoggingSettings from bot_core.configuration.bot_settings import BotSettings from bot_core.configuration.server_settings import ServerSettings +from bot_core.logging.command_logger import CommandLogger +from bot_core.logging.event_logger import EventLogger from modules.base.configuration.base_server_settings import BaseServerSettings from modules.base.configuration.base_settings import BaseSettings from modules.boot_log.configuration.boot_log_server_settings import BootLogServerSettings @@ -24,6 +27,10 @@ class Application(DiscordBotApplicationABC): def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): DiscordBotApplicationABC.__init__(self, config, services) + self._services = services + self._cmd_logger: Optional[LoggerABC] = None + self._event_logger: Optional[LoggerABC] = None + # cpl-core self._logger: LoggerABC = services.get_service(LoggerABC) # cpl-discord @@ -33,27 +40,32 @@ class Application(DiscordBotApplicationABC): self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC) self._translate: TranslatePipe = services.get_service(TranslatePipe) - def _configure_settings_with_servers(self, settings: Type, server_settings: Type): + def _configure_settings_with_sub_settings(self, settings: Type, list_atr: Callable, atr: Callable): settings: Optional[settings] = self._configuration.get_configuration(settings) if settings is None: return - for server in settings.servers: - self._logger.trace(__name__, f'Saved config: {type(server).__name__}_{server.id}') - self._configuration.add_configuration(f'{type(server).__name__}_{server.id}', server) + for sub_settings in list_atr(settings): + self._logger.trace(__name__, f'Saved config: {type(sub_settings).__name__}_{atr(sub_settings)}') + self._configuration.add_configuration(f'{type(sub_settings).__name__}_{atr(sub_settings)}', sub_settings) async def configure(self): self._translation.load_by_settings(self._configuration.get_configuration(TranslationSettings)) - self._configure_settings_with_servers(BotSettings, ServerSettings) - self._configure_settings_with_servers(BaseSettings, BaseServerSettings) - self._configure_settings_with_servers(BootLogSettings, BootLogServerSettings) - self._configure_settings_with_servers(PermissionSettings, PermissionServerSettings) + self._configure_settings_with_sub_settings(BotSettings, lambda x: x.servers, lambda x: x.id) + self._configure_settings_with_sub_settings(BaseSettings, lambda x: x.servers, lambda x: x.id) + self._configure_settings_with_sub_settings(BootLogSettings, lambda x: x.servers, lambda x: x.id) + self._configure_settings_with_sub_settings(PermissionSettings, lambda x: x.servers, lambda x: x.id) + self._configure_settings_with_sub_settings(BotLoggingSettings, lambda x: x.files, lambda x: x.key) + # custom loggers need to be loaded AFTER config is loaded correctly + self._cmd_logger: LoggerABC = self._services.get_service(CommandLogger) + self._event_logger: LoggerABC = self._services.get_service(EventLogger) async def main(self): try: self._logger.debug(__name__, f'Starting...\n') self._logger.trace(__name__, f'Try to start {DiscordBotService.__name__}') await self._bot.start_async() + await self._bot.stop_async() except Exception as e: self._logger.error(__name__, 'Start failed', e) diff --git a/src/bot/config/appsettings.edrafts-pc-ubuntu.json b/src/bot/config/appsettings.edrafts-pc-ubuntu.json index 20585cb5..d4138b2d 100644 --- a/src/bot/config/appsettings.edrafts-pc-ubuntu.json +++ b/src/bot/config/appsettings.edrafts-pc-ubuntu.json @@ -1,10 +1,24 @@ { "LoggingSettings": { "Path": "logs/", - "Filename": "log_dev.log", + "Filename": "dev.log", "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" }, + "BotLoggingSettings": { + "Command": { + "Path": "logs/", + "Filename": "commands.log", + "ConsoleLogLevel": "DEBUG", + "FileLogLevel": "TRACE" + }, + "Event": { + "Path": "logs/", + "Filename": "event.log", + "ConsoleLogLevel": "DEBUG", + "FileLogLevel": "TRACE" + } + }, "DatabaseSettings": { "Host": "localhost", "User": "kd_kdb", diff --git a/src/bot/startup.py b/src/bot/startup.py index 689c9819..3063c7b3 100644 --- a/src/bot/startup.py +++ b/src/bot/startup.py @@ -1,3 +1,5 @@ +import os +from datetime import datetime from typing import Optional from cpl_core.application import StartupABC @@ -5,10 +7,13 @@ from cpl_core.configuration import ConfigurationABC from cpl_core.database import DatabaseSettings from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.environment import ApplicationEnvironment +from cpl_core.logging import LoggerABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.logging.command_logger import CommandLogger +from bot_core.logging.event_logger import EventLogger from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_core.service.client_utils_service import ClientUtilsService from bot_core.service.message_service import MessageService @@ -35,23 +40,36 @@ class Startup(StartupABC): def __init__(self): StartupABC.__init__(self) + self._start_time = datetime.now() + self._config: Optional[ConfigurationABC] = None - self._feature_flags: Optional[FeatureFlagsSettings] = None def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: + environment.set_working_directory(os.path.dirname(os.path.realpath(__file__))) + configuration.add_environment_variables('KDB_') + configuration.add_environment_variables('DISCORD_') + + configuration.add_json_file(f'config/appsettings.json', optional=False) + configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True) + configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True) + + configuration.add_configuration('Startup_StartTime', str(self._start_time)) + self._config = configuration - self._feature_flags = configuration.get_configuration(FeatureFlagsSettings) return configuration def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: services.add_logging() + # custom logging + services.add_singleton(LoggerABC, CommandLogger) + services.add_singleton(LoggerABC, EventLogger) + services.add_translation() services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) # general services - if self._feature_flags.base_module: - services.add_transient(BaseHelperABC, BaseHelperService) + services.add_transient(BaseHelperABC, BaseHelperService) services.add_transient(MessageServiceABC, MessageService) services.add_transient(ClientUtilsServiceABC, ClientUtilsService) @@ -59,8 +77,7 @@ class Startup(StartupABC): services.add_transient(DateTimeOffsetPipe) # module services - if self._feature_flags.permission_module: - services.add_singleton(PermissionServiceABC, PermissionService) + services.add_singleton(PermissionServiceABC, PermissionService) # data services services.add_transient(ServerRepositoryABC, ServerRepositoryService) diff --git a/src/bot/startup_discord_extension.py b/src/bot/startup_discord_extension.py index 8e7b93ec..dbf3281d 100644 --- a/src/bot/startup_discord_extension.py +++ b/src/bot/startup_discord_extension.py @@ -15,6 +15,7 @@ from modules.base.command.help_command import HelpCommand from modules.base.command.info_command import InfoCommand from modules.base.command.ping_command import PingCommand from modules.base.events.base_on_command_error_event import BaseOnCommandErrorEvent +from modules.base.events.base_on_command_event import BaseOnCommandEvent from modules.moderator.command.purge_command import PurgeCommand from modules.base.command.user_info_command import UserInfoCommand from modules.base.events.base_on_member_join_event import BaseOnMemberJoinEvent @@ -38,44 +39,46 @@ class StartupDiscordExtension(StartupExtensionABC): def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services.add_discord() dc = get_discord_collection(services) - """ commands """ - # admin + """modules""" if self._feature_flags.admin_module: + """ commands """ dc.add_command(RestartCommand) dc.add_command(ShutdownCommand) - # moderator - if self._feature_flags.moderator_module: - dc.add_command(PurgeCommand) - # simple + """ events """ + if self._feature_flags.base_module: + """ commands """ dc.add_command(AFKCommand) dc.add_command(HelpCommand) dc.add_command(InfoCommand) dc.add_command(PingCommand) dc.add_command(UserInfoCommand) - """ events """ - # on_command_error - if self._feature_flags.base_module: + """ events """ + dc.add_event(DiscordEventTypesEnum.on_command.value, BaseOnCommandEvent) dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) - # on_member_join - if self._feature_flags.base_module: dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) - # on_member_remove - if self._feature_flags.base_module: dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent) - # on_member_update - if self._feature_flags.permission_module: - dc.add_event(DiscordEventTypesEnum.on_member_update.value, PermissionOnMemberUpdateEvent) - # on_message - if self._feature_flags.base_module: dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) - # on_voice_state_update - if self._feature_flags.base_module: dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) - # on_ready + if self._feature_flags.database_module: + """ commands """ + """ events """ dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent) + + if self._feature_flags.moderator_module: + """ commands """ + dc.add_command(PurgeCommand) + """ events """ + if self._feature_flags.permission_module: + """ commands """ + """ events """ dc.add_event(DiscordEventTypesEnum.on_ready.value, PermissionOnReadyEvent) + dc.add_event(DiscordEventTypesEnum.on_member_update.value, PermissionOnMemberUpdateEvent) + + # has to be last! if self._feature_flags.boot_log_module: - dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) # has to be last + """ commands """ + """ events """ + dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) diff --git a/src/bot_core/abc/custom_file_logger_abc.py b/src/bot_core/abc/custom_file_logger_abc.py new file mode 100644 index 00000000..f5e9ca5e --- /dev/null +++ b/src/bot_core/abc/custom_file_logger_abc.py @@ -0,0 +1,60 @@ +from abc import ABC, abstractmethod + +from cpl_core.configuration import ConfigurationABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_core.logging import LoggingSettings, Logger, LoggingLevelEnum, LoggerABC +from cpl_core.time import TimeFormatSettings + +from bot_core.configuration.file_logging_settings import FileLoggingSettings + + +class CustomFileLoggerABC(Logger, ABC): + + @abstractmethod + def __init__(self, key: str, config: ConfigurationABC, time_format: TimeFormatSettings, env: ApplicationEnvironmentABC): + self._key = key + settings: LoggingSettings = config.get_configuration(f'{FileLoggingSettings.__name__}_{key}') + Logger.__init__(self, settings, time_format, env) + self._begin_log() + + def _begin_log(self): + console_level = self._console.value + self._console = LoggingLevelEnum.OFF + self.info(__name__, f'Starting...\n') + self._console = LoggingLevelEnum(console_level) + + def _get_string(self, name_list_as_str: str, level: LoggingLevelEnum, message: str) -> str: + names = name_list_as_str.split(' ') + log_level = level.name + string = f'<{self._get_datetime_now()}> [ {log_level} ] ' + for name in names: + string += f'[ {name} ] ' + string += f': {message}' + return string + + def header(self, string: str): + super().header(string) + + def trace(self, name: str, message: str): + name = f'{name} {self._key}' + super().trace(name, message) + + def debug(self, name: str, message: str): + name = f'{name} {self._key}' + super().debug(name, message) + + def info(self, name: str, message: str): + name = f'{name} {self._key}' + super().info(name, message) + + def warn(self, name: str, message: str): + name = f'{name} {self._key}' + super().warn(name, message) + + def error(self, name: str, message: str, ex: Exception = None): + name = f'{name} {self._key}' + super().error(name, message, ex) + + def fatal(self, name: str, message: str, ex: Exception = None): + name = f'{name} {self._key}' + super().fatal(name, message, ex) diff --git a/src/bot_core/configuration/bot_logging_settings.py b/src/bot_core/configuration/bot_logging_settings.py new file mode 100644 index 00000000..37ecd6ed --- /dev/null +++ b/src/bot_core/configuration/bot_logging_settings.py @@ -0,0 +1,33 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console, ForegroundColorEnum +from cpl_query.extension import List + +from bot_core.configuration.file_logging_settings import FileLoggingSettings + + +class BotLoggingSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + self._files: List[FileLoggingSettings] = List(FileLoggingSettings) + + @property + def files(self) -> List[FileLoggingSettings]: + return self._files + + def from_dict(self, settings: dict): + try: + files = List(FileLoggingSettings) + for s in settings: + st = FileLoggingSettings() + settings[s]['Key'] = s + st.from_dict(settings[s]) + files.append(st) + self._files = files + except Exception as e: + Console.set_foreground_color(ForegroundColorEnum.red) + Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings') + Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') + Console.set_foreground_color(ForegroundColorEnum.default) diff --git a/src/bot_core/configuration/file_logging_settings.py b/src/bot_core/configuration/file_logging_settings.py new file mode 100644 index 00000000..50f3ddb0 --- /dev/null +++ b/src/bot_core/configuration/file_logging_settings.py @@ -0,0 +1,24 @@ +import traceback + +from cpl_core.console import Console +from cpl_core.logging import LoggingSettings + + +class FileLoggingSettings(LoggingSettings): + + def __init__(self): + LoggingSettings.__init__(self) + + self._key = '' + + @property + def key(self) -> str: + return self._key + + def from_dict(self, settings: dict): + try: + self._key = settings['Key'] + super().from_dict(settings) + 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/src/bot_core/logging/__init__.py b/src/bot_core/logging/__init__.py new file mode 100644 index 00000000..425ab6c1 --- /dev/null +++ b/src/bot_core/logging/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/bot_core/logging/command_logger.py b/src/bot_core/logging/command_logger.py new file mode 100644 index 00000000..16d6f15b --- /dev/null +++ b/src/bot_core/logging/command_logger.py @@ -0,0 +1,11 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_core.time import TimeFormatSettings + +from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC + + +class CommandLogger(CustomFileLoggerABC): + + def __init__(self, config: ConfigurationABC, time_format: TimeFormatSettings, env: ApplicationEnvironmentABC): + CustomFileLoggerABC.__init__(self, 'Command', config, time_format, env) diff --git a/src/bot_core/logging/event_logger.py b/src/bot_core/logging/event_logger.py new file mode 100644 index 00000000..7c7ff931 --- /dev/null +++ b/src/bot_core/logging/event_logger.py @@ -0,0 +1,11 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_core.time import TimeFormatSettings + +from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC + + +class EventLogger(CustomFileLoggerABC): + + def __init__(self, config: ConfigurationABC, time_format: TimeFormatSettings, env: ApplicationEnvironmentABC): + CustomFileLoggerABC.__init__(self, 'Event', config, time_format, env) diff --git a/src/modules/admin/command/restart_command.py b/src/modules/admin/command/restart_command.py index e8de4f5b..62a1b517 100644 --- a/src/modules/admin/command/restart_command.py +++ b/src/modules/admin/command/restart_command.py @@ -1,5 +1,4 @@ from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe @@ -8,6 +7,7 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -15,7 +15,7 @@ class RestartCommand(DiscordCommandABC): def __init__( self, - logger: LoggerABC, + logger: CommandLogger, config: ConfigurationABC, message_service: MessageServiceABC, bot: DiscordBotServiceABC, diff --git a/src/modules/admin/command/shutdown_command.py b/src/modules/admin/command/shutdown_command.py index f4e68499..1a44e836 100644 --- a/src/modules/admin/command/shutdown_command.py +++ b/src/modules/admin/command/shutdown_command.py @@ -1,5 +1,4 @@ from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe @@ -8,6 +7,7 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -15,7 +15,7 @@ class ShutdownCommand(DiscordCommandABC): def __init__( self, - logger: LoggerABC, + logger: CommandLogger, config: ConfigurationABC, message_service: MessageServiceABC, bot: DiscordBotServiceABC, diff --git a/src/modules/base/command/afk_command.py b/src/modules/base/command/afk_command.py index 10eb6af1..42edc5e9 100644 --- a/src/modules/base/command/afk_command.py +++ b/src/modules/base/command/afk_command.py @@ -1,5 +1,4 @@ from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe @@ -9,6 +8,7 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger from modules.base.configuration.base_server_settings import BaseServerSettings @@ -16,7 +16,7 @@ class AFKCommand(DiscordCommandABC): def __init__( self, - logger: LoggerABC, + logger: CommandLogger, config: ConfigurationABC, message_service: MessageServiceABC, bot: DiscordBotServiceABC, diff --git a/src/modules/base/command/help_command.py b/src/modules/base/command/help_command.py index 4bf97471..c1f69d3a 100644 --- a/src/modules/base/command/help_command.py +++ b/src/modules/base/command/help_command.py @@ -1,5 +1,4 @@ from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from discord.ext import commands @@ -7,6 +6,7 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger from modules.base.configuration.base_server_settings import BaseServerSettings @@ -15,7 +15,7 @@ class HelpCommand(DiscordCommandABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: CommandLogger, message_service: MessageServiceABC, bot: DiscordBotServiceABC, client_utils: ClientUtilsServiceABC diff --git a/src/modules/base/command/info_command.py b/src/modules/base/command/info_command.py index d3c7de65..55d2b950 100644 --- a/src/modules/base/command/info_command.py +++ b/src/modules/base/command/info_command.py @@ -2,7 +2,6 @@ from datetime import datetime import discord from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe @@ -12,6 +11,7 @@ from discord.ext.commands import Context import bot from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger class InfoCommand(DiscordCommandABC): @@ -19,7 +19,7 @@ class InfoCommand(DiscordCommandABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: CommandLogger, message_service: MessageServiceABC, bot: DiscordBotServiceABC, client_utils: ClientUtilsServiceABC, diff --git a/src/modules/base/command/ping_command.py b/src/modules/base/command/ping_command.py index f8a796ef..9402bcd4 100644 --- a/src/modules/base/command/ping_command.py +++ b/src/modules/base/command/ping_command.py @@ -1,4 +1,3 @@ -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe @@ -7,13 +6,14 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger class PingCommand(DiscordCommandABC): def __init__( self, - logger: LoggerABC, + logger: CommandLogger, message_service: MessageServiceABC, bot: DiscordBotServiceABC, client_utils: ClientUtilsServiceABC, diff --git a/src/modules/base/command/user_info_command.py b/src/modules/base/command/user_info_command.py index d9d646ba..139c8180 100644 --- a/src/modules/base/command/user_info_command.py +++ b/src/modules/base/command/user_info_command.py @@ -2,7 +2,6 @@ from typing import Optional import discord from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe @@ -11,6 +10,7 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC @@ -23,7 +23,7 @@ class UserInfoCommand(DiscordCommandABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: CommandLogger, message_service: MessageServiceABC, bot: DiscordBotServiceABC, client_utils: ClientUtilsServiceABC, diff --git a/src/modules/base/configuration/base_server_settings.py b/src/modules/base/configuration/base_server_settings.py index 14bba3eb..d2875f54 100644 --- a/src/modules/base/configuration/base_server_settings.py +++ b/src/modules/base/configuration/base_server_settings.py @@ -2,6 +2,7 @@ import traceback from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.console import Console +from cpl_query.extension import List class BaseServerSettings(ConfigurationModelABC): @@ -13,7 +14,9 @@ class BaseServerSettings(ConfigurationModelABC): self._max_voice_state_hours: int = 0 self._xp_per_message: int = 0 self._xp_per_ontime_hour: int = 0 - self._afk_channel_ids: list[int] = [] + self._afk_channel_ids: List[int] = List(int) + self._afk_command_channel_id: int = 0 + self._help_command_reference_url: str = '' @property def id(self) -> int: @@ -32,7 +35,7 @@ class BaseServerSettings(ConfigurationModelABC): return self._xp_per_ontime_hour @property - def afk_channel_ids(self) -> list[int]: + def afk_channel_ids(self) -> List[int]: return self._afk_channel_ids @property diff --git a/src/modules/base/events/base_on_command_event.py b/src/modules/base/events/base_on_command_event.py new file mode 100644 index 00000000..7b6d6bfd --- /dev/null +++ b/src/modules/base/events/base_on_command_event.py @@ -0,0 +1,41 @@ +import datetime +import traceback +import uuid + +from cpl_core.time import TimeFormatSettings +from cpl_discord.events import OnCommandABC +from cpl_discord.service import DiscordBotServiceABC +from cpl_translation import TranslatePipe +from discord.ext import commands +from discord.ext.commands import Context, CommandError + +from cpl_core.logging import LoggerABC +from cpl_discord.events.on_command_error_abc import OnCommandErrorABC + +from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.configuration.bot_settings import BotSettings +from bot_core.logging.command_logger import CommandLogger + + +class BaseOnCommandEvent(OnCommandABC): + + def __init__( + self, + logger: CommandLogger, + bot: DiscordBotServiceABC, + messenger: MessageServiceABC, + bot_settings: BotSettings, + time_format_settings: TimeFormatSettings, + translate: TranslatePipe + ): + OnCommandABC.__init__(self) + self._logger = logger + self._bot = bot + self._messenger = messenger + self._bot_settings = bot_settings + self._time_format_settings = time_format_settings + self._t = translate + + async def on_command(self, ctx: Context): + self._logger.warn(__name__, f'Received command afk {ctx}') + pass diff --git a/src/modules/moderator/command/purge_command.py b/src/modules/moderator/command/purge_command.py index 07ecd4bf..9e951052 100644 --- a/src/modules/moderator/command/purge_command.py +++ b/src/modules/moderator/command/purge_command.py @@ -1,7 +1,6 @@ import asyncio from cpl_core.configuration import ConfigurationABC -from cpl_core.logging import LoggerABC from cpl_discord.command import DiscordCommandABC from cpl_translation import TranslatePipe from discord.ext import commands @@ -10,6 +9,7 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.server_settings import ServerSettings +from bot_core.logging.command_logger import CommandLogger from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -17,7 +17,7 @@ class PurgeCommand(DiscordCommandABC): def __init__( self, - logger: LoggerABC, + logger: CommandLogger, config: ConfigurationABC, message_service: MessageServiceABC, permissions: PermissionServiceABC, -- 2.45.2 From e2749f6a816cb57c79d686d2358c60713372929d Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 13:13:23 +0200 Subject: [PATCH 13/19] Improved logging --- src/bot/application.py | 27 ++----------------- .../config/appsettings.edrafts-pc-ubuntu.json | 12 ++++++--- src/bot/startup.py | 25 ++++++++--------- src/bot/startup_settings_extension.py | 24 +++++++++++++++++ src/bot_core/abc/custom_file_logger_abc.py | 6 ++--- src/bot_core/helper/__init__.py | 0 src/bot_core/helper/log_message_helper.py | 9 +++++++ src/bot_core/logging/database_logger.py | 11 ++++++++ .../{event_logger.py => message_logger.py} | 4 +-- src/bot_core/service/message_service.py | 7 ++--- src/bot_data/db_context.py | 5 ++-- src/bot_data/migration/initial_migration.py | 5 ++-- .../service/client_repository_service.py | 5 ++-- .../service/known_user_repository_service.py | 11 ++++---- src/bot_data/service/migration_service.py | 4 +-- .../service/server_repository_service.py | 5 ++-- .../user_joined_server_repository_service.py | 6 ++--- .../user_joined_voice_channel_service.py | 8 +++--- .../service/user_repository_service.py | 5 ++-- .../base/events/base_on_command_event.py | 12 ++------- .../base/events/base_on_message_event.py | 6 +++-- .../boot_log/boot_log_on_ready_event.py | 4 +-- src/modules/database/database_extension.py | 3 ++- .../database/database_on_ready_event.py | 8 +++--- 24 files changed, 118 insertions(+), 94 deletions(-) create mode 100644 src/bot_core/helper/__init__.py create mode 100644 src/bot_core/helper/log_message_helper.py create mode 100644 src/bot_core/logging/database_logger.py rename src/bot_core/logging/{event_logger.py => message_logger.py} (73%) diff --git a/src/bot/application.py b/src/bot/application.py index 4b80eb9b..7af5db79 100644 --- a/src/bot/application.py +++ b/src/bot/application.py @@ -1,6 +1,6 @@ from typing import Optional, Type, Callable -from cpl_core.configuration import ConfigurationABC, ConfigurationModelABC +from cpl_core.configuration import ConfigurationABC from cpl_core.console import Console from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC @@ -11,14 +11,10 @@ from cpl_translation import TranslatePipe, TranslationServiceABC, TranslationSet from bot_core.configuration.bot_logging_settings import BotLoggingSettings from bot_core.configuration.bot_settings import BotSettings -from bot_core.configuration.server_settings import ServerSettings from bot_core.logging.command_logger import CommandLogger -from bot_core.logging.event_logger import EventLogger -from modules.base.configuration.base_server_settings import BaseServerSettings +from bot_core.logging.database_logger import DatabaseLogger from modules.base.configuration.base_settings import BaseSettings -from modules.boot_log.configuration.boot_log_server_settings import BootLogServerSettings from modules.boot_log.configuration.boot_log_settings import BootLogSettings -from modules.permission.configuration.permission_server_settings import PermissionServerSettings from modules.permission.configuration.permission_settings import PermissionSettings @@ -28,8 +24,6 @@ class Application(DiscordBotApplicationABC): DiscordBotApplicationABC.__init__(self, config, services) self._services = services - self._cmd_logger: Optional[LoggerABC] = None - self._event_logger: Optional[LoggerABC] = None # cpl-core self._logger: LoggerABC = services.get_service(LoggerABC) @@ -40,25 +34,8 @@ class Application(DiscordBotApplicationABC): self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC) self._translate: TranslatePipe = services.get_service(TranslatePipe) - def _configure_settings_with_sub_settings(self, settings: Type, list_atr: Callable, atr: Callable): - settings: Optional[settings] = self._configuration.get_configuration(settings) - if settings is None: - return - - for sub_settings in list_atr(settings): - self._logger.trace(__name__, f'Saved config: {type(sub_settings).__name__}_{atr(sub_settings)}') - self._configuration.add_configuration(f'{type(sub_settings).__name__}_{atr(sub_settings)}', sub_settings) - async def configure(self): self._translation.load_by_settings(self._configuration.get_configuration(TranslationSettings)) - self._configure_settings_with_sub_settings(BotSettings, lambda x: x.servers, lambda x: x.id) - self._configure_settings_with_sub_settings(BaseSettings, lambda x: x.servers, lambda x: x.id) - self._configure_settings_with_sub_settings(BootLogSettings, lambda x: x.servers, lambda x: x.id) - self._configure_settings_with_sub_settings(PermissionSettings, lambda x: x.servers, lambda x: x.id) - self._configure_settings_with_sub_settings(BotLoggingSettings, lambda x: x.files, lambda x: x.key) - # custom loggers need to be loaded AFTER config is loaded correctly - self._cmd_logger: LoggerABC = self._services.get_service(CommandLogger) - self._event_logger: LoggerABC = self._services.get_service(EventLogger) async def main(self): try: diff --git a/src/bot/config/appsettings.edrafts-pc-ubuntu.json b/src/bot/config/appsettings.edrafts-pc-ubuntu.json index d4138b2d..7afbf20d 100644 --- a/src/bot/config/appsettings.edrafts-pc-ubuntu.json +++ b/src/bot/config/appsettings.edrafts-pc-ubuntu.json @@ -1,7 +1,7 @@ { "LoggingSettings": { "Path": "logs/", - "Filename": "dev.log", + "Filename": "bot.log", "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" }, @@ -12,9 +12,15 @@ "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" }, - "Event": { + "Database": { "Path": "logs/", - "Filename": "event.log", + "Filename": "database.log", + "ConsoleLogLevel": "DEBUG", + "FileLogLevel": "TRACE" + }, + "Message": { + "Path": "logs/", + "Filename": "message.log", "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" } diff --git a/src/bot/startup.py b/src/bot/startup.py index 3063c7b3..177d3a9e 100644 --- a/src/bot/startup.py +++ b/src/bot/startup.py @@ -10,10 +10,11 @@ from cpl_core.environment import ApplicationEnvironment from cpl_core.logging import LoggerABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC +from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC from bot_core.abc.message_service_abc import MessageServiceABC -from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.logging.command_logger import CommandLogger -from bot_core.logging.event_logger import EventLogger +from bot_core.logging.database_logger import DatabaseLogger +from bot_core.logging.message_logger import MessageLogger from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_core.service.client_utils_service import ClientUtilsService from bot_core.service.message_service import MessageService @@ -45,16 +46,6 @@ class Startup(StartupABC): self._config: Optional[ConfigurationABC] = None def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: - environment.set_working_directory(os.path.dirname(os.path.realpath(__file__))) - configuration.add_environment_variables('KDB_') - configuration.add_environment_variables('DISCORD_') - - configuration.add_json_file(f'config/appsettings.json', optional=False) - configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True) - configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True) - - configuration.add_configuration('Startup_StartTime', str(self._start_time)) - self._config = configuration return configuration @@ -62,7 +53,8 @@ class Startup(StartupABC): services.add_logging() # custom logging services.add_singleton(LoggerABC, CommandLogger) - services.add_singleton(LoggerABC, EventLogger) + services.add_singleton(LoggerABC, DatabaseLogger) + services.add_singleton(LoggerABC, MessageLogger) services.add_translation() @@ -87,4 +79,9 @@ class Startup(StartupABC): services.add_transient(UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService) services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService) - return services.build_service_provider() + provider = services.build_service_provider() + # instantiate custom logger + for c in CustomFileLoggerABC.__subclasses__(): + i: LoggerABC = provider.get_service(c) + + return provider diff --git a/src/bot/startup_settings_extension.py b/src/bot/startup_settings_extension.py index 8c27e69b..0a9b8091 100644 --- a/src/bot/startup_settings_extension.py +++ b/src/bot/startup_settings_extension.py @@ -1,10 +1,20 @@ import os from datetime import datetime +from typing import Callable, Type, Optional from cpl_core.application import StartupExtensionABC from cpl_core.configuration import ConfigurationABC from cpl_core.dependency_injection import ServiceCollectionABC from cpl_core.environment import ApplicationEnvironmentABC +from cpl_core.logging import LoggerABC + +from bot_core.configuration.bot_logging_settings import BotLoggingSettings +from bot_core.configuration.bot_settings import BotSettings +from bot_core.logging.command_logger import CommandLogger +from bot_core.logging.database_logger import DatabaseLogger +from modules.base.configuration.base_settings import BaseSettings +from modules.boot_log.configuration.boot_log_settings import BootLogSettings +from modules.permission.configuration.permission_settings import PermissionSettings class StartupSettingsExtension(StartupExtensionABC): @@ -23,6 +33,20 @@ class StartupSettingsExtension(StartupExtensionABC): configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True) configuration.add_configuration('Startup_StartTime', str(self._start_time)) + 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, 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) def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): pass + + @staticmethod + def _configure_settings_with_sub_settings(config: ConfigurationABC, settings: Type, list_atr: Callable, atr: Callable): + settings: Optional[settings] = config.get_configuration(settings) + if settings is None: + return + + for sub_settings in list_atr(settings): + config.add_configuration(f'{type(sub_settings).__name__}_{atr(sub_settings)}', sub_settings) diff --git a/src/bot_core/abc/custom_file_logger_abc.py b/src/bot_core/abc/custom_file_logger_abc.py index f5e9ca5e..c7354f65 100644 --- a/src/bot_core/abc/custom_file_logger_abc.py +++ b/src/bot_core/abc/custom_file_logger_abc.py @@ -20,15 +20,15 @@ class CustomFileLoggerABC(Logger, ABC): def _begin_log(self): console_level = self._console.value self._console = LoggingLevelEnum.OFF - self.info(__name__, f'Starting...\n') + self.info(__name__, f'Starting...') self._console = LoggingLevelEnum(console_level) def _get_string(self, name_list_as_str: str, level: LoggingLevelEnum, message: str) -> str: names = name_list_as_str.split(' ') log_level = level.name - string = f'<{self._get_datetime_now()}> [ {log_level} ] ' + string = f'<{self._get_datetime_now()}> [ {log_level} ]' for name in names: - string += f'[ {name} ] ' + string += f' [ {name} ]' string += f': {message}' return string diff --git a/src/bot_core/helper/__init__.py b/src/bot_core/helper/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/bot_core/helper/log_message_helper.py b/src/bot_core/helper/log_message_helper.py new file mode 100644 index 00000000..403bf688 --- /dev/null +++ b/src/bot_core/helper/log_message_helper.py @@ -0,0 +1,9 @@ +import discord + + +class LogMessageHelper: + + @staticmethod + def get_log_string(message: discord.Message): + content = message.content.replace("\n", "\n\t") + return f'{message.author} @ {message.channel} -> \n\t{content}' diff --git a/src/bot_core/logging/database_logger.py b/src/bot_core/logging/database_logger.py new file mode 100644 index 00000000..dfc1f637 --- /dev/null +++ b/src/bot_core/logging/database_logger.py @@ -0,0 +1,11 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_core.time import TimeFormatSettings + +from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC + + +class DatabaseLogger(CustomFileLoggerABC): + + def __init__(self, config: ConfigurationABC, time_format: TimeFormatSettings, env: ApplicationEnvironmentABC): + CustomFileLoggerABC.__init__(self, 'Database', config, time_format, env) diff --git a/src/bot_core/logging/event_logger.py b/src/bot_core/logging/message_logger.py similarity index 73% rename from src/bot_core/logging/event_logger.py rename to src/bot_core/logging/message_logger.py index 7c7ff931..78ce56e1 100644 --- a/src/bot_core/logging/event_logger.py +++ b/src/bot_core/logging/message_logger.py @@ -5,7 +5,7 @@ from cpl_core.time import TimeFormatSettings from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC -class EventLogger(CustomFileLoggerABC): +class MessageLogger(CustomFileLoggerABC): def __init__(self, config: ConfigurationABC, time_format: TimeFormatSettings, env: ApplicationEnvironmentABC): - CustomFileLoggerABC.__init__(self, 'Event', config, time_format, env) + CustomFileLoggerABC.__init__(self, 'Message', config, time_format, env) diff --git a/src/bot_core/service/message_service.py b/src/bot_core/service/message_service.py index f7696c63..d1b8f5f0 100644 --- a/src/bot_core/service/message_service.py +++ b/src/bot_core/service/message_service.py @@ -4,19 +4,20 @@ from typing import Union import discord from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.database.context.database_context_abc import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_discord.service import DiscordBotServiceABC from cpl_query.extension import List from discord.ext.commands import Context from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.server_settings import ServerSettings +from bot_core.helper.log_message_helper import LogMessageHelper +from bot_core.logging.message_logger import MessageLogger from bot_data.abc.client_repository_abc import ClientRepositoryABC class MessageService(MessageServiceABC): - def __init__(self, config: ConfigurationABC, logger: LoggerABC, bot: DiscordBotServiceABC, clients: ClientRepositoryABC, db: DatabaseContextABC): + def __init__(self, config: ConfigurationABC, logger: MessageLogger, bot: DiscordBotServiceABC, clients: ClientRepositoryABC, db: DatabaseContextABC): self._config = config self._logger = logger self._bot = bot @@ -35,7 +36,7 @@ class MessageService(MessageServiceABC): server_st: ServerSettings = self._config.get_configuration(f'ServerSettings_{message.guild.id}') if not mass_delete: await asyncio.sleep(server_st.message_delete_timer) - self._logger.debug(__name__, f'Try to delete message:\n\t{message}\n\t{message.content}') + self._logger.debug(__name__, f'Try to delete message: {LogMessageHelper.get_log_string(message)}') guild_id = message.guild.id try: await message.delete() diff --git a/src/bot_data/db_context.py b/src/bot_data/db_context.py index 8ad5414c..fb0df290 100644 --- a/src/bot_data/db_context.py +++ b/src/bot_data/db_context.py @@ -1,11 +1,12 @@ from cpl_core.database import DatabaseSettings from cpl_core.database.context import DatabaseContext -from cpl_core.logging import LoggerABC + +from bot_core.logging.database_logger import DatabaseLogger class DBContext(DatabaseContext): - def __init__(self, logger: LoggerABC): + def __init__(self, logger: DatabaseLogger): self._logger = logger diff --git a/src/bot_data/migration/initial_migration.py b/src/bot_data/migration/initial_migration.py index fa6a251d..76dd481d 100644 --- a/src/bot_data/migration/initial_migration.py +++ b/src/bot_data/migration/initial_migration.py @@ -1,12 +1,11 @@ -from cpl_core.logging import LoggerABC - +from bot_core.logging.database_logger import DatabaseLogger from bot_data.abc.migration_abc import MigrationABC from bot_data.db_context import DBContext class InitialMigration(MigrationABC): - def __init__(self, logger: LoggerABC, db: DBContext): + def __init__(self, logger: DatabaseLogger, db: DBContext): self._logger = logger self._db = db self._cursor = db.cursor diff --git a/src/bot_data/service/client_repository_service.py b/src/bot_data/service/client_repository_service.py index 7756f13c..ba875a25 100644 --- a/src/bot_data/service/client_repository_service.py +++ b/src/bot_data/service/client_repository_service.py @@ -1,8 +1,9 @@ from typing import Optional + from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_query.extension import List +from bot_core.logging.database_logger import DatabaseLogger from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.client import Client @@ -10,7 +11,7 @@ from bot_data.model.client import Client class ClientRepositoryService(ClientRepositoryABC): - def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC): self._logger = logger self._context = db_context diff --git a/src/bot_data/service/known_user_repository_service.py b/src/bot_data/service/known_user_repository_service.py index 80bdf134..fc112179 100644 --- a/src/bot_data/service/known_user_repository_service.py +++ b/src/bot_data/service/known_user_repository_service.py @@ -1,16 +1,17 @@ from typing import Optional -from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC -from cpl_query.extension import List -from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC +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.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.known_user import KnownUser class KnownUserRepositoryService(KnownUserRepositoryABC): - def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC): self._logger = logger self._context = db_context diff --git a/src/bot_data/service/migration_service.py b/src/bot_data/service/migration_service.py index a0e8ed15..fef42f21 100644 --- a/src/bot_data/service/migration_service.py +++ b/src/bot_data/service/migration_service.py @@ -2,15 +2,15 @@ from typing import Type from cpl_core.database.context import DatabaseContextABC from cpl_core.dependency_injection import ServiceProviderABC -from cpl_core.logging import LoggerABC +from bot_core.logging.database_logger import DatabaseLogger from bot_data.abc.migration_abc import MigrationABC from bot_data.model.migration_history import MigrationHistory class MigrationService: - def __init__(self, logger: LoggerABC, services: ServiceProviderABC, db: DatabaseContextABC): + def __init__(self, logger: DatabaseLogger, services: ServiceProviderABC, db: DatabaseContextABC): self._logger = logger self._services = services diff --git a/src/bot_data/service/server_repository_service.py b/src/bot_data/service/server_repository_service.py index ff585f49..728d2bc6 100644 --- a/src/bot_data/service/server_repository_service.py +++ b/src/bot_data/service/server_repository_service.py @@ -1,15 +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 bot_core.logging.database_logger import DatabaseLogger from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.server import Server class ServerRepositoryService(ServerRepositoryABC): - def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC): + def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC): self._logger = logger self._context = db_context diff --git a/src/bot_data/service/user_joined_server_repository_service.py b/src/bot_data/service/user_joined_server_repository_service.py index c42bf76b..29f4e50b 100644 --- a/src/bot_data/service/user_joined_server_repository_service.py +++ b/src/bot_data/service/user_joined_server_repository_service.py @@ -1,18 +1,18 @@ from typing import Optional from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_query.extension import List + +from bot_core.logging.database_logger import DatabaseLogger from bot_data.abc.user_joined_server_repository_abc import \ UserJoinedServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC -from bot_data.model.user import User from bot_data.model.user_joined_server import UserJoinedServer class UserJoinedServerRepositoryService(UserJoinedServerRepositoryABC): - def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC, users: UserRepositoryABC): + def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, users: UserRepositoryABC): self._logger = logger self._context = db_context diff --git a/src/bot_data/service/user_joined_voice_channel_service.py b/src/bot_data/service/user_joined_voice_channel_service.py index 05e98244..d6b1b596 100644 --- a/src/bot_data/service/user_joined_voice_channel_service.py +++ b/src/bot_data/service/user_joined_voice_channel_service.py @@ -1,17 +1,17 @@ from typing import Optional from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_query.extension import List + +from bot_core.logging.database_logger import DatabaseLogger +from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.user_joined_voice_channel import UserJoinedVoiceChannel -from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC - class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryABC): - def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC, users: UserRepositoryABC): + def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, users: UserRepositoryABC): self._logger = logger self._context = db_context diff --git a/src/bot_data/service/user_repository_service.py b/src/bot_data/service/user_repository_service.py index f95db48a..f2543e5d 100644 --- a/src/bot_data/service/user_repository_service.py +++ b/src/bot_data/service/user_repository_service.py @@ -1,8 +1,9 @@ from typing import Optional + from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC 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.user_repository_abc import UserRepositoryABC from bot_data.model.user import User @@ -10,7 +11,7 @@ from bot_data.model.user import User class UserRepositoryService(UserRepositoryABC): - def __init__(self, logger: LoggerABC, db_context: DatabaseContextABC, servers: ServerRepositoryABC): + def __init__(self, logger: DatabaseLogger, db_context: DatabaseContextABC, servers: ServerRepositoryABC): self._logger = logger self._context = db_context diff --git a/src/modules/base/events/base_on_command_event.py b/src/modules/base/events/base_on_command_event.py index 7b6d6bfd..bbe548e7 100644 --- a/src/modules/base/events/base_on_command_event.py +++ b/src/modules/base/events/base_on_command_event.py @@ -1,16 +1,8 @@ -import datetime -import traceback -import uuid - from cpl_core.time import TimeFormatSettings from cpl_discord.events import OnCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe -from discord.ext import commands -from discord.ext.commands import Context, CommandError - -from cpl_core.logging import LoggerABC -from cpl_discord.events.on_command_error_abc import OnCommandErrorABC +from discord.ext.commands import Context from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.bot_settings import BotSettings @@ -37,5 +29,5 @@ class BaseOnCommandEvent(OnCommandABC): self._t = translate async def on_command(self, ctx: Context): - self._logger.warn(__name__, f'Received command afk {ctx}') + print('\n', ctx.command) pass diff --git a/src/modules/base/events/base_on_message_event.py b/src/modules/base/events/base_on_message_event.py index 7dfdbabb..f5288c50 100644 --- a/src/modules/base/events/base_on_message_event.py +++ b/src/modules/base/events/base_on_message_event.py @@ -2,10 +2,11 @@ from typing import Optional import discord from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_discord.events import OnMessageABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.helper.log_message_helper import LogMessageHelper +from bot_core.logging.message_logger import MessageLogger from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC @@ -18,7 +19,7 @@ class BaseOnMessageEvent(OnMessageABC): def __init__( self, - logger: LoggerABC, + logger: MessageLogger, bhs: BaseHelperABC, db: DatabaseContextABC, bot: DiscordBotServiceABC, @@ -71,6 +72,7 @@ class BaseOnMessageEvent(OnMessageABC): async def on_message(self, message: discord.Message): self._logger.debug(__name__, f'Module {type(self)} started') + self._logger.debug(__name__, f'Received message: {LogMessageHelper.get_log_string(message)}') if message is None or message.guild is None: return self._append_received_message_count(message.guild.id) diff --git a/src/modules/boot_log/boot_log_on_ready_event.py b/src/modules/boot_log/boot_log_on_ready_event.py index 403f4628..06e7b162 100644 --- a/src/modules/boot_log/boot_log_on_ready_event.py +++ b/src/modules/boot_log/boot_log_on_ready_event.py @@ -42,12 +42,12 @@ class BootLogOnReadyEvent(OnReadyABC): # print warning if initialisation took too long if init_time >= 30: self._logger.warn( - __name__, 'It takes long time to start the bot!') + __name__, 'It takes too long 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!!!') + __name__, 'It takes far too long to start the bot!!!') except Exception as e: self._logger.error(__name__, 'Init time calculation failed', e) return diff --git a/src/modules/database/database_extension.py b/src/modules/database/database_extension.py index 883752bb..f5d4a492 100644 --- a/src/modules/database/database_extension.py +++ b/src/modules/database/database_extension.py @@ -6,6 +6,7 @@ from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC 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 @@ -18,7 +19,7 @@ class DatabaseExtension(ApplicationExtensionABC): feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings) if not feature_flags.database_module: return - logger: LoggerABC = services.get_service(LoggerABC) + logger: LoggerABC = services.get_service(DatabaseLogger) logger.debug(__name__, 'Database extension started') config.add_configuration('Database_StartTime', str(datetime.now())) migrations: MigrationService = services.get_service(MigrationService) diff --git a/src/modules/database/database_on_ready_event.py b/src/modules/database/database_on_ready_event.py index fab4dc0a..9176a26c 100644 --- a/src/modules/database/database_on_ready_event.py +++ b/src/modules/database/database_on_ready_event.py @@ -4,10 +4,10 @@ from datetime import datetime, timedelta import discord from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC from cpl_discord.events import OnReadyABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.logging.database_logger import DatabaseLogger from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC @@ -29,7 +29,7 @@ class DatabaseOnReadyEvent(OnReadyABC): def __init__( self, config: ConfigurationABC, - logger: LoggerABC, + logger: DatabaseLogger, bot: DiscordBotServiceABC, db_context: DatabaseContextABC, server_repo: ServerRepositoryABC, @@ -65,12 +65,12 @@ class DatabaseOnReadyEvent(OnReadyABC): # print warning if initialisation took too long if init_time >= 30: self._logger.warn( - __name__, 'It takes long time to start the bot!') + __name__, 'It takes too long to prepare the database!') # 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!!!') + __name__, 'It takes far too long to prepare the database!!!') except Exception as e: # self._logger.error(__name__, 'Database init time calculation failed', e) return -- 2.45.2 From fa50123d3bb47f62c4c37766cdb4d941014763cc Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 13:22:41 +0200 Subject: [PATCH 14/19] Improved logging for migrations #45 --- src/bot_data/service/migration_service.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bot_data/service/migration_service.py b/src/bot_data/service/migration_service.py index fef42f21..fc2d5913 100644 --- a/src/bot_data/service/migration_service.py +++ b/src/bot_data/service/migration_service.py @@ -31,11 +31,10 @@ class MigrationService: # there is a table named "tableName" self._logger.trace(__name__, f"Running SQL Command: {MigrationHistory.get_select_by_id_string(migration_id)}") migration_from_db = self._db.select(MigrationHistory.get_select_by_id_string(migration_id)) - self._logger.trace(__name__, str(migration_from_db)) if migration_from_db is not None and len(migration_from_db) > 0: continue - self._logger.debug(__name__, f"Running Migration {migration}") + self._logger.debug(__name__, f"Running Migration {migration_id}") migration_as_service: MigrationABC = self._services.get_service(migration) migration_as_service.upgrade() self._cursor.execute(MigrationHistory(migration_id).insert_string) -- 2.45.2 From d5a1c15db3c62784d195ec90995b79bb0f10d2e9 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 13:25:29 +0200 Subject: [PATCH 15/19] Prevent multiple stop_async calls --- src/bot/application.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bot/application.py b/src/bot/application.py index 7af5db79..aec07e03 100644 --- a/src/bot/application.py +++ b/src/bot/application.py @@ -34,6 +34,8 @@ class Application(DiscordBotApplicationABC): self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC) self._translate: TranslatePipe = services.get_service(TranslatePipe) + self._is_stopping = False + async def configure(self): self._translation.load_by_settings(self._configuration.get_configuration(TranslationSettings)) @@ -47,6 +49,10 @@ class Application(DiscordBotApplicationABC): self._logger.error(__name__, 'Start failed', e) async def stop_async(self): + if self._is_stopping: + return + + self._is_stopping = True try: self._logger.trace(__name__, f'Try to stop {DiscordBotService.__name__}') await self._bot.close() -- 2.45.2 From 54db70404428bff06156a26cf1044b0fe8bc19b4 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 23:23:26 +0200 Subject: [PATCH 16/19] Improved settings #45 --- docker-compose.yml | 29 +++++++++++++++-- src/bot/config/appsettings.development.json | 22 ++++++++++++- src/bot/config/appsettings.json | 24 ++++++++++++-- src/bot/config/appsettings.production.json | 26 +++++++++++++-- src/bot/config/appsettings.staging.json | 35 +++++++++++++++++++-- 5 files changed, 126 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 07fc8d34..fde8d204 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,16 +1,28 @@ version: "3.9" services: - kdb_1: + kdb_prod_1: image: kdb container_name: kdb_1 depends_on: - kdb_db_1 environment: + KDB_ENVIRONMENT: "production" KDB_TOKEN: "" KDB_PREFIX: "!k " restart: unless-stopped + kdb_staging_1: + image: kdb + container_name: kdb_1 + depends_on: + - kdb_db_1 + environment: + KDB_ENVIRONMENT: "staging" + KDB_TOKEN: "" + KDB_PREFIX: "!kt " + restart: unless-stopped + kdb_db_1: image: mysql:latest container_name: kdb_db_1 @@ -22,4 +34,17 @@ services: MYSQL_PASSWORD: "kd_kdb" MYSQL_DATABASE: "kd_kdb" ports: - - "3307:3306" \ No newline at end of file + - "3307:3306" + + kdb_db_2: + image: mysql:latest + container_name: kdb_db_2 + command: mysqld --default-authentication-plugin=mysql_native_password + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: "kd_kdb" + MYSQL_USER: "kd_kdb" + MYSQL_PASSWORD: "kd_kdb" + MYSQL_DATABASE: "kd_kdb" + ports: + - "3308:3306" \ No newline at end of file diff --git a/src/bot/config/appsettings.development.json b/src/bot/config/appsettings.development.json index 44dbc166..3278dcd7 100644 --- a/src/bot/config/appsettings.development.json +++ b/src/bot/config/appsettings.development.json @@ -7,10 +7,30 @@ }, "LoggingSettings": { "Path": "logs/", - "Filename": "log_dev.log", + "Filename": "bot.log", "ConsoleLogLevel": "DEBUG", "FileLogLevel": "DEBUG" }, + "BotLoggingSettings": { + "Command": { + "Path": "logs/", + "Filename": "commands.log", + "ConsoleLogLevel": "DEBUG", + "FileLogLevel": "DEBUG" + }, + "Database": { + "Path": "logs/", + "Filename": "database.log", + "ConsoleLogLevel": "DEBUG", + "FileLogLevel": "DEBUG" + }, + "Message": { + "Path": "logs/", + "Filename": "message.log", + "ConsoleLogLevel": "DEBUG", + "FileLogLevel": "DEBUG" + } + }, "Translation": { "DefaultLanguage": "de", "Languages": [ diff --git a/src/bot/config/appsettings.json b/src/bot/config/appsettings.json index a02074ce..643f38ab 100644 --- a/src/bot/config/appsettings.json +++ b/src/bot/config/appsettings.json @@ -6,9 +6,29 @@ "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" }, "LoggingSettings": { - "Path": "logs/", - "Filename": "log_$start_time.log", + "Path": "logs/$date_now/", + "Filename": "bot.log", "ConsoleLogLevel": "ERROR", "FileLogLevel": "WARN" + }, + "BotLoggingSettings": { + "Command": { + "Path": "logs/$date_now/", + "Filename": "commands.log", + "ConsoleLogLevel": "ERROR", + "FileLogLevel": "WARN" + }, + "Database": { + "Path": "logs/$date_now/", + "Filename": "database.log", + "ConsoleLogLevel": "ERROR", + "FileLogLevel": "WARN" + }, + "Message": { + "Path": "logs/$date_now/", + "Filename": "message.log", + "ConsoleLogLevel": "ERROR", + "FileLogLevel": "WARN" + } } } \ No newline at end of file diff --git a/src/bot/config/appsettings.production.json b/src/bot/config/appsettings.production.json index 515c60af..493deaba 100644 --- a/src/bot/config/appsettings.production.json +++ b/src/bot/config/appsettings.production.json @@ -6,11 +6,31 @@ "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" }, "LoggingSettings": { - "Path": "logs/", - "Filename": "log_$start_time.log", + "Path": "logs/$date_now/", + "Filename": "bot.log", "ConsoleLogLevel": "ERROR", "FileLogLevel": "INFO" }, + "BotLoggingSettings": { + "Command": { + "Path": "logs/$date_now/", + "Filename": "commands.log", + "ConsoleLogLevel": "ERROR", + "FileLogLevel": "INFO" + }, + "Database": { + "Path": "logs/$date_now/", + "Filename": "database.log", + "ConsoleLogLevel": "ERROR", + "FileLogLevel": "INFO" + }, + "Message": { + "Path": "logs/$date_now/", + "Filename": "message.log", + "ConsoleLogLevel": "ERROR", + "FileLogLevel": "INFO" + } + }, "Translation": { "DefaultLanguage": "de", "Languages": [ @@ -18,7 +38,7 @@ ] }, "DatabaseSettings": { - "Host": "192.168.0.40", + "Host": "localhost", "User": "kd_kdb", "Password": "a2Rfa2Ri", "Database": "kd_kdb", diff --git a/src/bot/config/appsettings.staging.json b/src/bot/config/appsettings.staging.json index 605fe7fc..ce9e6521 100644 --- a/src/bot/config/appsettings.staging.json +++ b/src/bot/config/appsettings.staging.json @@ -6,17 +6,48 @@ "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" }, "LoggingSettings": { - "Path": "logs/", - "Filename": "log_staging_$start_time.log", + "Path": "logs/$date_now/", + "Filename": "bot.log", "ConsoleLogLevel": "INFO", "FileLogLevel": "DEBUG" }, + "BotLoggingSettings": { + "Command": { + "Path": "logs/$date_now/", + "Filename": "commands.log", + "ConsoleLogLevel": "INFO", + "FileLogLevel": "DEBUG" + }, + "Database": { + "Path": "logs/$date_now/", + "Filename": "database.log", + "ConsoleLogLevel": "INFO", + "FileLogLevel": "DEBUG" + }, + "Message": { + "Path": "logs/$date_now/", + "Filename": "message.log", + "ConsoleLogLevel": "INFO", + "FileLogLevel": "DEBUG" + } + }, "Translation": { "DefaultLanguage": "de", "Languages": [ "de" ] }, + "DatabaseSettings": { + "Host": "localhost", + "User": "kd_kdb", + "Password": "a2Rfa2Ri", + "Database": "kd_kdb", + "Port": "3308", + "Charset": "utf8mb4", + "UseUnicode": "true", + "Buffered": "true", + "AuthPlugin": "mysql_native_password" + }, "FeatureFlags": { "AdminModule": true, "BaseModule": true, -- 2.45.2 From cb1ebeeb0c6555224296ecdeaa2454ad9ae18d9f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 2 Oct 2022 23:29:23 +0200 Subject: [PATCH 17/19] Improved on command logging #45 --- .../base/events/base_on_command_event.py | 63 ++++++++++++++++++- .../base/events/base_on_message_event.py | 2 +- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/modules/base/events/base_on_command_event.py b/src/modules/base/events/base_on_command_event.py index bbe548e7..e1c46a20 100644 --- a/src/modules/base/events/base_on_command_event.py +++ b/src/modules/base/events/base_on_command_event.py @@ -1,3 +1,7 @@ +from typing import Optional + +import discord +from cpl_core.database.context import DatabaseContextABC from cpl_core.time import TimeFormatSettings from cpl_discord.events import OnCommandABC from cpl_discord.service import DiscordBotServiceABC @@ -7,6 +11,12 @@ from discord.ext.commands import Context from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.bot_settings import BotSettings from bot_core.logging.command_logger import CommandLogger +from bot_data.abc.client_repository_abc import ClientRepositoryABC +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.model.user import User +from modules.base.abc.base_helper_abc import BaseHelperABC +from modules.base.configuration.base_server_settings import BaseServerSettings class BaseOnCommandEvent(OnCommandABC): @@ -18,7 +28,12 @@ class BaseOnCommandEvent(OnCommandABC): messenger: MessageServiceABC, bot_settings: BotSettings, time_format_settings: TimeFormatSettings, - translate: TranslatePipe + translate: TranslatePipe, + bhs: BaseHelperABC, + db: DatabaseContextABC, + users: UserRepositoryABC, + clients: ClientRepositoryABC, + servers: ServerRepositoryABC, ): OnCommandABC.__init__(self) self._logger = logger @@ -27,7 +42,49 @@ class BaseOnCommandEvent(OnCommandABC): self._bot_settings = bot_settings self._time_format_settings = time_format_settings self._t = translate + self._base_helper = bhs + self._db = db + self._users = users + self._clients = clients + self._servers = servers + + def _append_received_message_count(self, g_id: int): + try: + self._clients.append_received_message_count(self._bot.user.id, g_id, 1) + self._db.save_changes() + except Exception as e: + self._logger.error(__name__, f'Cannot edit client {self._bot.user.id}@{g_id}', e) + + def _handle_message_for_xp(self, message: discord.Message): + dc_user_id = message.author.id + try: + server = self._servers.get_server_by_discord_id(message.guild.id) + except Exception as e: + self._logger.error(__name__, f'Cannot get server {message.guild.id}', e) + return + + user: Optional[User] = None + try: + user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id) + except Exception as e: + self._logger.error(__name__, f'Cannot get user {dc_user_id}', e) + return + + if user is None: + self._logger.error(__name__, f'User not found {dc_user_id}') + return + + settings: BaseServerSettings = self._base_helper.get_config(message.guild.id) + old_xp = user.xp + user.xp += settings.xp_per_message + self._users.update_user(user) + self._db.save_changes() + + self._logger.debug(__name__, f'User {user} sent message. xp: from {old_xp} to {user.xp}') async def on_command(self, ctx: Context): - print('\n', ctx.command) - pass + self._logger.debug(__name__, f'Module {type(self)} started') + self._logger.info(__name__, f'Received command: {ctx.command} from {ctx.channel}') + if ctx is None or ctx.guild is None: + return + self._append_received_message_count(ctx.guild.id) diff --git a/src/modules/base/events/base_on_message_event.py b/src/modules/base/events/base_on_message_event.py index f5288c50..ee8fcdbc 100644 --- a/src/modules/base/events/base_on_message_event.py +++ b/src/modules/base/events/base_on_message_event.py @@ -72,7 +72,7 @@ class BaseOnMessageEvent(OnMessageABC): async def on_message(self, message: discord.Message): self._logger.debug(__name__, f'Module {type(self)} started') - self._logger.debug(__name__, f'Received message: {LogMessageHelper.get_log_string(message)}') + self._logger.info(__name__, f'Received message: {LogMessageHelper.get_log_string(message)}') if message is None or message.guild is None: return self._append_received_message_count(message.guild.id) -- 2.45.2 From b8874a6eab7ad4f007c8de758628dfbd85210970 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 3 Oct 2022 00:28:22 +0200 Subject: [PATCH 18/19] Added module support --- src/bot/main.py | 2 ++ src/bot/startup_discord_extension.py | 28 +++++++++---------- src/bot/startup_module_extension.py | 42 ++++++++++++++++++++++++++++ src/bot_core/abc/module_abc.py | 19 +++++++++++++ src/modules/base/base_module.py | 42 ++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 src/bot/startup_module_extension.py create mode 100644 src/bot_core/abc/module_abc.py create mode 100644 src/modules/base/base_module.py diff --git a/src/bot/main.py b/src/bot/main.py index 29c81fc1..6f8cfd76 100644 --- a/src/bot/main.py +++ b/src/bot/main.py @@ -8,6 +8,7 @@ from bot.application import Application from bot.startup import Startup from bot.startup_discord_extension import StartupDiscordExtension from bot.startup_migration_extension import StartupMigrationExtension +from bot.startup_module_extension import StartupModuleExtension from bot.startup_settings_extension import StartupSettingsExtension from modules.boot_log.boot_log_extension import BootLogExtension from modules.database.database_extension import DatabaseExtension @@ -22,6 +23,7 @@ class Program: app_builder = ApplicationBuilder(Application) \ .use_extension(StartupSettingsExtension) \ .use_extension(StartupDiscordExtension) \ + .use_extension(StartupModuleExtension) \ .use_extension(StartupMigrationExtension) \ .use_extension(BootLogExtension) \ .use_extension(DatabaseExtension) \ diff --git a/src/bot/startup_discord_extension.py b/src/bot/startup_discord_extension.py index dbf3281d..70f610bb 100644 --- a/src/bot/startup_discord_extension.py +++ b/src/bot/startup_discord_extension.py @@ -46,20 +46,20 @@ class StartupDiscordExtension(StartupExtensionABC): dc.add_command(ShutdownCommand) """ events """ - if self._feature_flags.base_module: - """ commands """ - dc.add_command(AFKCommand) - dc.add_command(HelpCommand) - dc.add_command(InfoCommand) - dc.add_command(PingCommand) - dc.add_command(UserInfoCommand) - """ events """ - dc.add_event(DiscordEventTypesEnum.on_command.value, BaseOnCommandEvent) - dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) - dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) - dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent) - dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) - dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) + # if self._feature_flags.base_module: + # """ commands """ + # dc.add_command(AFKCommand) + # dc.add_command(HelpCommand) + # dc.add_command(InfoCommand) + # dc.add_command(PingCommand) + # dc.add_command(UserInfoCommand) + # """ events """ + # dc.add_event(DiscordEventTypesEnum.on_command.value, BaseOnCommandEvent) + # dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) + # dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) + # dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent) + # dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) + # dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) if self._feature_flags.database_module: """ commands """ diff --git a/src/bot/startup_module_extension.py b/src/bot/startup_module_extension.py new file mode 100644 index 00000000..d914039b --- /dev/null +++ b/src/bot/startup_module_extension.py @@ -0,0 +1,42 @@ +from typing import Optional + +from cpl_core.application import StartupExtensionABC +from cpl_core.configuration import ConfigurationABC +from cpl_core.console import Console, ForegroundColorEnum +from cpl_core.dependency_injection import ServiceCollectionABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_discord.service.discord_collection_abc import DiscordCollectionABC +from cpl_query.extension import List + +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from modules.base.base_module import BaseModule + + +class StartupModuleExtension(StartupExtensionABC): + + def __init__(self): + self._config: Optional[ConfigurationABC] = None + self._feature_flags: Optional[FeatureFlagsSettings] = None + + self._modules = List(type, [ + BaseModule + ]) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + self._config = config + self._feature_flags = config.get_configuration(FeatureFlagsSettings) + + def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): + provider = services.build_service_provider() + dc_collection: DiscordCollectionABC = provider.get_service(DiscordCollectionABC) + + for module_type in self._modules: + module = module_type(dc_collection) + if not module.feature_flag(self._feature_flags): + continue + + Console.set_foreground_color(ForegroundColorEnum.green) + Console.write_line(f'[{__name__}] Loaded module: {module_type}') + Console.color_reset() + module.configure_configuration(self._config, env) + module.configure_services(services, env) diff --git a/src/bot_core/abc/module_abc.py b/src/bot_core/abc/module_abc.py new file mode 100644 index 00000000..af52acf0 --- /dev/null +++ b/src/bot_core/abc/module_abc.py @@ -0,0 +1,19 @@ +from abc import abstractmethod +from typing import Callable + +from cpl_core.application import StartupExtensionABC +from cpl_discord.service.discord_collection_abc import DiscordCollectionABC + + +class ModuleABC(StartupExtensionABC): + + @abstractmethod + def __init__(self, dc: DiscordCollectionABC, feature_flag: Callable = None): + StartupExtensionABC.__init__(self) + + self._dc = dc + self._feature_flag = feature_flag + + @property + def feature_flag(self) -> Callable: + return self._feature_flag diff --git a/src/modules/base/base_module.py b/src/modules/base/base_module.py new file mode 100644 index 00000000..08d43748 --- /dev/null +++ b/src/modules/base/base_module.py @@ -0,0 +1,42 @@ +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 modules.base.command.afk_command import AFKCommand +from modules.base.command.help_command import HelpCommand +from modules.base.command.info_command import InfoCommand +from modules.base.command.ping_command import PingCommand +from modules.base.command.user_info_command import UserInfoCommand +from modules.base.events.base_on_command_error_event import BaseOnCommandErrorEvent +from modules.base.events.base_on_command_event import BaseOnCommandEvent +from modules.base.events.base_on_member_join_event import BaseOnMemberJoinEvent +from modules.base.events.base_on_member_remove_event import BaseOnMemberRemoveEvent +from modules.base.events.base_on_message_event import BaseOnMessageEvent +from modules.base.events.base_on_voice_state_update_event import BaseOnVoiceStateUpdateEvent + + +class BaseModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, lambda x: x.base_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC): + # commands + self._dc.add_command(AFKCommand) + self._dc.add_command(HelpCommand) + self._dc.add_command(InfoCommand) + self._dc.add_command(PingCommand) + self._dc.add_command(UserInfoCommand) + # events + self._dc.add_event(DiscordEventTypesEnum.on_command.value, BaseOnCommandEvent) + self._dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) + self._dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) + self._dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent) + self._dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) + self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) -- 2.45.2 From 05fbe7230435c4fd30e912352c86289bba395188 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 3 Oct 2022 01:05:34 +0200 Subject: [PATCH 19/19] Improved module support #52 --- src/bot/main.py | 1 + src/bot/startup.py | 2 +- src/bot/startup_discord_extension.py | 49 ++------------------- src/bot/startup_module_extension.py | 12 ++++- src/modules/admin/admin_module.py | 23 ++++++++++ src/modules/boot_log/boot_log_module.py | 22 +++++++++ src/modules/database/database_module.py | 22 +++++++++ src/modules/moderator/moderator_module.py | 21 +++++++++ src/modules/permission/permission_module.py | 24 ++++++++++ 9 files changed, 128 insertions(+), 48 deletions(-) create mode 100644 src/modules/admin/admin_module.py create mode 100644 src/modules/boot_log/boot_log_module.py create mode 100644 src/modules/database/database_module.py create mode 100644 src/modules/moderator/moderator_module.py create mode 100644 src/modules/permission/permission_module.py diff --git a/src/bot/main.py b/src/bot/main.py index 6f8cfd76..b00c9418 100644 --- a/src/bot/main.py +++ b/src/bot/main.py @@ -20,6 +20,7 @@ class Program: self.app: Optional[Application] = None async def start(self): + # discord extension has to be loaded before modules (modules depends on discord stuff) app_builder = ApplicationBuilder(Application) \ .use_extension(StartupSettingsExtension) \ .use_extension(StartupDiscordExtension) \ diff --git a/src/bot/startup.py b/src/bot/startup.py index 177d3a9e..55df0788 100644 --- a/src/bot/startup.py +++ b/src/bot/startup.py @@ -8,6 +8,7 @@ from cpl_core.database import DatabaseSettings from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.environment import ApplicationEnvironment from cpl_core.logging import LoggerABC +from cpl_discord import get_discord_collection from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC @@ -57,7 +58,6 @@ class Startup(StartupABC): services.add_singleton(LoggerABC, MessageLogger) services.add_translation() - services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) # general services diff --git a/src/bot/startup_discord_extension.py b/src/bot/startup_discord_extension.py index 70f610bb..e0edbfde 100644 --- a/src/bot/startup_discord_extension.py +++ b/src/bot/startup_discord_extension.py @@ -31,54 +31,11 @@ from modules.permission.events.permission_on_ready_event import PermissionOnRead class StartupDiscordExtension(StartupExtensionABC): def __init__(self): - self._feature_flags: Optional[FeatureFlagsSettings] = None + pass def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): - self._feature_flags = config.get_configuration(FeatureFlagsSettings) + pass def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services.add_discord() - dc = get_discord_collection(services) - """modules""" - if self._feature_flags.admin_module: - """ commands """ - dc.add_command(RestartCommand) - dc.add_command(ShutdownCommand) - """ events """ - - # if self._feature_flags.base_module: - # """ commands """ - # dc.add_command(AFKCommand) - # dc.add_command(HelpCommand) - # dc.add_command(InfoCommand) - # dc.add_command(PingCommand) - # dc.add_command(UserInfoCommand) - # """ events """ - # dc.add_event(DiscordEventTypesEnum.on_command.value, BaseOnCommandEvent) - # dc.add_event(DiscordEventTypesEnum.on_command_error.value, BaseOnCommandErrorEvent) - # dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent) - # dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent) - # dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) - # dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) - - if self._feature_flags.database_module: - """ commands """ - """ events """ - dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent) - - if self._feature_flags.moderator_module: - """ commands """ - dc.add_command(PurgeCommand) - """ events """ - - if self._feature_flags.permission_module: - """ commands """ - """ events """ - dc.add_event(DiscordEventTypesEnum.on_ready.value, PermissionOnReadyEvent) - dc.add_event(DiscordEventTypesEnum.on_member_update.value, PermissionOnMemberUpdateEvent) - - # has to be last! - if self._feature_flags.boot_log_module: - """ commands """ - """ events """ - dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) + dcc = get_discord_collection(services) diff --git a/src/bot/startup_module_extension.py b/src/bot/startup_module_extension.py index d914039b..c93ff29c 100644 --- a/src/bot/startup_module_extension.py +++ b/src/bot/startup_module_extension.py @@ -9,7 +9,12 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC from cpl_query.extension import List from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from modules.admin.admin_module import AdminModule 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.moderator.moderator_module import ModeratorModule +from modules.permission.permission_module import PermissionModule class StartupModuleExtension(StartupExtensionABC): @@ -19,7 +24,12 @@ class StartupModuleExtension(StartupExtensionABC): self._feature_flags: Optional[FeatureFlagsSettings] = None self._modules = List(type, [ - BaseModule + AdminModule, + BaseModule, + DatabaseModule, + ModeratorModule, + PermissionModule, + BootLogModule # has to be last! ]) def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): diff --git a/src/modules/admin/admin_module.py b/src/modules/admin/admin_module.py new file mode 100644 index 00000000..ae6c86a8 --- /dev/null +++ b/src/modules/admin/admin_module.py @@ -0,0 +1,23 @@ +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 modules.admin.command.restart_command import RestartCommand +from modules.admin.command.shutdown_command import ShutdownCommand + + +class AdminModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, lambda x: x.admin_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC): + # commands + self._dc.add_command(RestartCommand) + self._dc.add_command(ShutdownCommand) + # events diff --git a/src/modules/boot_log/boot_log_module.py b/src/modules/boot_log/boot_log_module.py new file mode 100644 index 00000000..7f533ce1 --- /dev/null +++ b/src/modules/boot_log/boot_log_module.py @@ -0,0 +1,22 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceCollectionABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum +from cpl_discord.service.discord_collection_abc import DiscordCollectionABC + +from bot_core.abc.module_abc import ModuleABC +from modules.boot_log.boot_log_on_ready_event import BootLogOnReadyEvent + + +class BootLogModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, lambda x: x.boot_log_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC): + # commands + # events + self._dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) diff --git a/src/modules/database/database_module.py b/src/modules/database/database_module.py new file mode 100644 index 00000000..4deedcbf --- /dev/null +++ b/src/modules/database/database_module.py @@ -0,0 +1,22 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceCollectionABC +from cpl_core.environment import ApplicationEnvironmentABC +from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum +from cpl_discord.service.discord_collection_abc import DiscordCollectionABC + +from bot_core.abc.module_abc import ModuleABC +from modules.database.database_on_ready_event import DatabaseOnReadyEvent + + +class DatabaseModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, lambda x: x.database_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC): + # commands + # events + self._dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent) diff --git a/src/modules/moderator/moderator_module.py b/src/modules/moderator/moderator_module.py new file mode 100644 index 00000000..6f0d6013 --- /dev/null +++ b/src/modules/moderator/moderator_module.py @@ -0,0 +1,21 @@ +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 modules.moderator.command.purge_command import PurgeCommand + + +class ModeratorModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, lambda x: x.moderator_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC): + # commands + self._dc.add_command(PurgeCommand) + # events diff --git a/src/modules/permission/permission_module.py b/src/modules/permission/permission_module.py new file mode 100644 index 00000000..a5f0b5a7 --- /dev/null +++ b/src/modules/permission/permission_module.py @@ -0,0 +1,24 @@ +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 modules.permission.events.permission_on_member_update_event import PermissionOnMemberUpdateEvent +from modules.permission.events.permission_on_ready_event import PermissionOnReadyEvent + + +class PermissionModule(ModuleABC): + + def __init__(self, dc: DiscordCollectionABC): + ModuleABC.__init__(self, dc, lambda x: x.permission_module) + + def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): + pass + + def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC): + # commands + # events + self._dc.add_event(DiscordEventTypesEnum.on_ready.value, PermissionOnReadyEvent) + self._dc.add_event(DiscordEventTypesEnum.on_member_update.value, PermissionOnMemberUpdateEvent) -- 2.45.2