diff --git a/src/cpl_core/__init__.py b/src/cpl_core/__init__.py index c6cfa50b..d9881558 100644 --- a/src/cpl_core/__init__.py +++ b/src/cpl_core/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/application/__init__.py b/src/cpl_core/application/__init__.py index c9483801..749f151c 100644 --- a/src/cpl_core/application/__init__.py +++ b/src/cpl_core/application/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.application' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -29,4 +29,4 @@ from .startup_abc import StartupABC from .startup_extension_abc import StartupExtensionABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/configuration/__init__.py b/src/cpl_core/configuration/__init__.py index 351e723a..8bada971 100644 --- a/src/cpl_core/configuration/__init__.py +++ b/src/cpl_core/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -35,4 +35,4 @@ from .validator_abc import ValidatorABC from .variable_argument import VariableArgument VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/console/__init__.py b/src/cpl_core/console/__init__.py index 7173b0ce..f61e384d 100644 --- a/src/cpl_core/console/__init__.py +++ b/src/cpl_core/console/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.console' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -28,4 +28,4 @@ from .foreground_color_enum import ForegroundColorEnum from .spinner_thread import SpinnerThread VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/cpl-core.json b/src/cpl_core/cpl-core.json index 29c2da08..04214452 100644 --- a/src/cpl_core/cpl-core.json +++ b/src/cpl_core/cpl-core.json @@ -3,8 +3,8 @@ "Name": "cpl-core", "Version": { "Major": "2022", - "Minor": "7", - "Micro": "0.post5" + "Minor": "10", + "Micro": "1" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,16 +16,16 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "art==5.6", - "colorama==0.4.4", + "art==5.7", + "colorama==0.4.5", "mysql-connector==2.2.9", - "psutil==5.9.0", + "psutil==5.9.2", "packaging==21.3", "pynput==1.7.6", - "setuptools==62.1.0", - "tabulate==0.8.9", + "setuptools==65.3.0", + "tabulate==0.8.10", "termcolor==1.1.0", - "watchdog==2.1.7", + "watchdog==2.1.9", "wheel==0.37.1" ], "DevDependencies": [ diff --git a/src/cpl_core/database/__init__.py b/src/cpl_core/database/__init__.py index d22440f7..aeecbe44 100644 --- a/src/cpl_core/database/__init__.py +++ b/src/cpl_core/database/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.database' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -26,4 +26,4 @@ from .database_settings import DatabaseSettings from .table_abc import TableABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/database/connection/__init__.py b/src/cpl_core/database/connection/__init__.py index 6a3fda86..41228642 100644 --- a/src/cpl_core/database/connection/__init__.py +++ b/src/cpl_core/database/connection/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -25,4 +25,4 @@ from .database_connection import DatabaseConnection from .database_connection_abc import DatabaseConnectionABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/database/context/__init__.py b/src/cpl_core/database/context/__init__.py index ab5580bf..2d2e1e62 100644 --- a/src/cpl_core/database/context/__init__.py +++ b/src/cpl_core/database/context/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -25,4 +25,4 @@ from .database_context import DatabaseContext from .database_context_abc import DatabaseContextABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/dependency_injection/__init__.py b/src/cpl_core/dependency_injection/__init__.py index 8126e047..bc39bbc7 100644 --- a/src/cpl_core/dependency_injection/__init__.py +++ b/src/cpl_core/dependency_injection/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -31,4 +31,4 @@ from .service_provider import ServiceProvider from .service_provider_abc import ServiceProviderABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/environment/__init__.py b/src/cpl_core/environment/__init__.py index f478ea26..23e98cc6 100644 --- a/src/cpl_core/environment/__init__.py +++ b/src/cpl_core/environment/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -26,4 +26,4 @@ from .environment_name_enum import EnvironmentNameEnum from .application_environment import ApplicationEnvironment VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/logging/__init__.py b/src/cpl_core/logging/__init__.py index 238c0859..cfff821d 100644 --- a/src/cpl_core/logging/__init__.py +++ b/src/cpl_core/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -28,4 +28,4 @@ from .logging_settings import LoggingSettings from .logging_settings_name_enum import LoggingSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/mailing/__init__.py b/src/cpl_core/mailing/__init__.py index 64ef752d..63ff1040 100644 --- a/src/cpl_core/mailing/__init__.py +++ b/src/cpl_core/mailing/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -28,4 +28,4 @@ from .email_client_settings import EMailClientSettings from .email_client_settings_name_enum import EMailClientSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/pipes/__init__.py b/src/cpl_core/pipes/__init__.py index 52bb2ed0..06b0a224 100644 --- a/src/cpl_core/pipes/__init__.py +++ b/src/cpl_core/pipes/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.pipes' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -30,4 +30,4 @@ from .to_camel_case_pipe import ToCamelCasePipe from .to_snake_case_pipe import ToSnakeCasePipe VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/time/__init__.py b/src/cpl_core/time/__init__.py index 80254875..d597cb7b 100644 --- a/src/cpl_core/time/__init__.py +++ b/src/cpl_core/time/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.time' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -25,4 +25,4 @@ from .time_format_settings import TimeFormatSettings from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_core/utils/__init__.py b/src/cpl_core/utils/__init__.py index b20282d1..b4ff316a 100644 --- a/src/cpl_core/utils/__init__.py +++ b/src/cpl_core/utils/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post5' +__version__ = '2022.10.1' from collections import namedtuple @@ -26,4 +26,4 @@ from .string import String from .pip import Pip VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post5') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_discord/__init__.py b/src/cpl_discord/__init__.py index e90a8740..1d2fa1bc 100644 --- a/src/cpl_discord/__init__.py +++ b/src/cpl_discord/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post4' +__version__ = '2022.10.1' from collections import namedtuple @@ -55,4 +55,4 @@ def get_discord_collection(services: 'ServiceCollectionABC') -> 'DiscordCollecti # build-ignore-end VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post4') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_discord/application/__init__.py b/src/cpl_discord/application/__init__.py index 83baa89d..545d8d4a 100644 --- a/src/cpl_discord/application/__init__.py +++ b/src/cpl_discord/application/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord.application' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post4' +__version__ = '2022.10.1' from collections import namedtuple @@ -24,4 +24,4 @@ from collections import namedtuple from .discord_bot_application_abc import DiscordBotApplicationABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post4') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_discord/command/__init__.py b/src/cpl_discord/command/__init__.py index fd981837..50b66688 100644 --- a/src/cpl_discord/command/__init__.py +++ b/src/cpl_discord/command/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord.command' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post4' +__version__ = '2022.10.1' from collections import namedtuple @@ -25,4 +25,4 @@ from .discord_command_abc import DiscordCommandABC from .discord_commands_meta import DiscordCogMeta VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post4') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_discord/configuration/__init__.py b/src/cpl_discord/configuration/__init__.py index 55376cea..661c53de 100644 --- a/src/cpl_discord/configuration/__init__.py +++ b/src/cpl_discord/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post4' +__version__ = '2022.10.1' from collections import namedtuple @@ -24,4 +24,4 @@ from collections import namedtuple from .discord_bot_settings import DiscordBotSettings VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post4') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json index 3ffa8ef4..d82c1478 100644 --- a/src/cpl_discord/cpl-discord.json +++ b/src/cpl_discord/cpl-discord.json @@ -3,8 +3,8 @@ "Name": "cpl-discord", "Version": { "Major": "2022", - "Minor": "7", - "Micro": "0.post4" + "Minor": "10", + "Micro": "1" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -17,7 +17,7 @@ "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ "cpl-core>=2022.7.0.post2", - "discord.py==1.7.3", + "discord.py==2.0.1", "cpl-query==2022.7.0" ], "DevDependencies": [ diff --git a/src/cpl_discord/discord_event_types_enum.py b/src/cpl_discord/discord_event_types_enum.py index 342633a0..7106d29a 100644 --- a/src/cpl_discord/discord_event_types_enum.py +++ b/src/cpl_discord/discord_event_types_enum.py @@ -42,9 +42,6 @@ from cpl_discord.events.on_reaction_clear_abc import OnReactionClearABC from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC from cpl_discord.events.on_reaction_remove_abc import OnReactionRemoveABC from cpl_discord.events.on_ready_abc import OnReadyABC -from cpl_discord.events.on_relationship_add_abc import OnRelationshipAddABC -from cpl_discord.events.on_relationship_remove_abc import OnRelationshipRemoveABC -from cpl_discord.events.on_relationship_update_abc import OnRelationshipUpdateABC from cpl_discord.events.on_resume_abc import OnResumeABC from cpl_discord.events.on_typing_abc import OnTypingABC from cpl_discord.events.on_user_update_abc import OnUserUpdateABC @@ -95,9 +92,6 @@ class DiscordEventTypesEnum(Enum): on_reaction_clear_emoji = OnReactionClearEmojiABC on_reaction_remove = OnReactionRemoveABC on_ready = OnReadyABC - on_relationship_add = OnRelationshipAddABC - on_relationship_remove = OnRelationshipRemoveABC - on_relationship_update = OnRelationshipUpdateABC on_resume = OnResumeABC on_typing = OnTypingABC on_user_update = OnUserUpdateABC diff --git a/src/cpl_discord/events/__init__.py b/src/cpl_discord/events/__init__.py index 84115097..623c7882 100644 --- a/src/cpl_discord/events/__init__.py +++ b/src/cpl_discord/events/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord.events' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post4' +__version__ = '2022.10.1' from collections import namedtuple @@ -62,9 +62,6 @@ from .on_reaction_clear_abc import OnReactionClearABC from .on_reaction_clear_emoji_abc import OnReactionClearEmojiABC from .on_reaction_remove_abc import OnReactionRemoveABC from .on_ready_abc import OnReadyABC -from .on_relationship_add_abc import OnRelationshipAddABC -from .on_relationship_remove_abc import OnRelationshipRemoveABC -from .on_relationship_update_abc import OnRelationshipUpdateABC from .on_resume_abc import OnResumeABC from .on_typing_abc import OnTypingABC from .on_user_update_abc import OnUserUpdateABC @@ -72,4 +69,4 @@ from .on_voice_state_update_abc import OnVoiceStateUpdateABC from .on_webhooks_update_abc import OnWebhooksUpdateABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post4') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_discord/events/on_relationship_add_abc.py b/src/cpl_discord/events/on_relationship_add_abc.py deleted file mode 100644 index 5cba49a0..00000000 --- a/src/cpl_discord/events/on_relationship_add_abc.py +++ /dev/null @@ -1,11 +0,0 @@ -from abc import ABC, abstractmethod -import discord - -class OnRelationshipAddABC(ABC): - - @abstractmethod - def __init__(self): pass - - @abstractmethod - async def on_relationship_add(self, relationship: discord.Relationship): pass - \ No newline at end of file diff --git a/src/cpl_discord/events/on_relationship_remove_abc.py b/src/cpl_discord/events/on_relationship_remove_abc.py deleted file mode 100644 index 4c8907ec..00000000 --- a/src/cpl_discord/events/on_relationship_remove_abc.py +++ /dev/null @@ -1,11 +0,0 @@ -from abc import ABC, abstractmethod -import discord - - -class OnRelationshipRemoveABC(ABC): - - @abstractmethod - def __init__(self): pass - - @abstractmethod - async def on_relationship_remove(self, relationship: discord.Relationship): pass diff --git a/src/cpl_discord/events/on_relationship_update_abc.py b/src/cpl_discord/events/on_relationship_update_abc.py deleted file mode 100644 index 4d970914..00000000 --- a/src/cpl_discord/events/on_relationship_update_abc.py +++ /dev/null @@ -1,12 +0,0 @@ -from abc import ABC, abstractmethod -import discord - - -class OnRelationshipUpdateABC(ABC): - - @abstractmethod - def __init__(self): pass - - @abstractmethod - async def on_relationship_update( - self, before: discord.Relationship, after: discord.Relationship): pass diff --git a/src/cpl_discord/service/__init__.py b/src/cpl_discord/service/__init__.py index 859fdc57..f0cece4f 100644 --- a/src/cpl_discord/service/__init__.py +++ b/src/cpl_discord/service/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '2022.7.0.post4' +__version__ = '2022.10.1' from collections import namedtuple @@ -29,4 +29,4 @@ from .discord_service import DiscordService from .discord_service_abc import DiscordServiceABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='7', micro='0.post4') +version_info = VersionInfo(major='2022', minor='10', micro='1') diff --git a/src/cpl_discord/service/discord_bot_service.py b/src/cpl_discord/service/discord_bot_service.py index 8d4b1afa..07682187 100644 --- a/src/cpl_discord/service/discord_bot_service.py +++ b/src/cpl_discord/service/discord_bot_service.py @@ -21,29 +21,37 @@ class DiscordBotService(DiscordBotServiceABC): discord_service: DiscordServiceABC ): # services + self._config = config self._logger = logger self._env = env self._logging_st = logging_st self._discord_service = discord_service # settings - if discord_bot_settings is None: - self._discord_settings = DiscordBotSettings() - token = config.get_configuration('TOKEN') - if token is None: - raise Exception('You have to configure discord token by appsettings or environment variables') - - prefix = config.get_configuration('PREFIX') - self._discord_settings.from_dict({ - 'Token': token, - 'Prefix': prefix if prefix is not None else '! ' - }) - else: - self._discord_settings = discord_bot_settings + self._discord_settings = self._get_settings(discord_bot_settings) # setup super DiscordBotServiceABC.__init__(self, command_prefix=self._discord_settings.prefix, help_command=None, intents=discord.Intents().all()) + @staticmethod + def _is_string_invalid(x): + return x is None or x == '' + + def _get_settings(self, settings_from_config: DiscordBotSettings) -> DiscordBotSettings: + new_settings = DiscordBotSettings() + token = settings_from_config.token + prefix = settings_from_config.prefix + env_token = self._config.get_configuration('TOKEN') + env_prefix = self._config.get_configuration('PREFIX') + + new_settings.from_dict({ + 'Token': env_token if token is None or token == '' else token, + 'Prefix': ('! ' if self._is_string_invalid(env_prefix) else env_prefix) if self._is_string_invalid(prefix) else prefix + }) + if new_settings.token is None or new_settings.token == '': + raise Exception('You have to configure discord token by appsettings or environment variables') + return new_settings + async def start_async(self): self._logger.trace(__name__, 'Try to connect to discord') await self.start(self._discord_settings.token) @@ -63,6 +71,9 @@ class DiscordBotService(DiscordBotServiceABC): if self._logging_st.console.value >= LoggingLevelEnum.INFO.value: Console.banner(self._env.application_name if self._env.application_name != '' else 'A bot') - self._discord_service.init(self) + await self._discord_service.init(self) + await self.wait_until_ready() + await self.tree.sync() + self._logger.debug(__name__, f'Finished syncing commands') await self._discord_service.on_ready() diff --git a/src/cpl_discord/service/discord_service.py b/src/cpl_discord/service/discord_service.py index d2dcf0dc..ef047789 100644 --- a/src/cpl_discord/service/discord_service.py +++ b/src/cpl_discord/service/discord_service.py @@ -3,9 +3,8 @@ from typing import Optional, Sequence, Union, Type import discord from discord.ext import commands -from discord.ext.commands import Context, CommandError +from discord.ext.commands import Context, CommandError, Cog, Command -from cpl_core.console import Console from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.logging import LoggerABC from cpl_core.utils import String @@ -52,9 +51,6 @@ from cpl_discord.events.on_reaction_clear_abc import OnReactionClearABC from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC from cpl_discord.events.on_reaction_remove_abc import OnReactionRemoveABC from cpl_discord.events.on_ready_abc import OnReadyABC -from cpl_discord.events.on_relationship_add_abc import OnRelationshipAddABC -from cpl_discord.events.on_relationship_remove_abc import OnRelationshipRemoveABC -from cpl_discord.events.on_relationship_update_abc import OnRelationshipUpdateABC from cpl_discord.events.on_resume_abc import OnResumeABC from cpl_discord.events.on_typing_abc import OnTypingABC from cpl_discord.events.on_user_update_abc import OnUserUpdateABC @@ -97,20 +93,20 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta): except Exception as e: self._logger.error(__name__, f'Cannot execute {func_name} of {type(event_instance).__name__}', e) - def init(self, bot: commands.Bot): + async def init(self, bot: commands.Bot): try: - bot.add_cog(self) + await bot.add_cog(self) except Exception as e: self._logger.error(__name__, f'{type(self).__name__} initialization failed', e) try: for command_type in self._collection.get_commands(): self._logger.trace(__name__, f'Register command {command_type.__name__}') - command = self._services.get_service(command_type) + command: Cog = self._services.get_service(command_type) if command is None: self._logger.warn(__name__, f'Instance of {command_type.__name__} not found') continue - bot.add_cog(command) + await bot.add_cog(command) except Exception as e: self._logger.error(__name__, f'Registration of commands failed', e) @@ -352,18 +348,3 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta): async def on_group_remove(self, channel: discord.GroupChannel, user: discord.User): self._logger.trace(__name__, f'Received on_group_remove:\n\t{channel}\n\t{user}') await self._handle_event(OnGroupRemoveABC, channel, user) - - @commands.Cog.listener() - async def on_relationship_add(self, relationship: discord.Relationship): - self._logger.trace(__name__, f'Received on_relationship_add:\n\t{relationship}') - await self._handle_event(OnRelationshipAddABC, relationship) - - @commands.Cog.listener() - async def on_relationship_remove(self, relationship: discord.Relationship): - self._logger.trace(__name__, f'Received on_relationship_remove:\n\t{relationship}') - await self._handle_event(OnRelationshipRemoveABC, relationship) - - @commands.Cog.listener() - async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship): - self._logger.trace(__name__, f'Received on_relationship_update:\n\t{before}\n\t{after}') - await self._handle_event(OnRelationshipUpdateABC, before, after) diff --git a/src/cpl_discord/service/discord_service_abc.py b/src/cpl_discord/service/discord_service_abc.py index c0911a05..ca2993a3 100644 --- a/src/cpl_discord/service/discord_service_abc.py +++ b/src/cpl_discord/service/discord_service_abc.py @@ -156,13 +156,4 @@ class DiscordServiceABC(ABC): async def on_group_join(self, chhanel: discord.GroupChannel, user: discord.User): pass @abstractmethod - async def on_group_remove(self, chhanel: discord.GroupChannel, user: discord.User): pass - - @abstractmethod - async def on_relationship_add(self, relationship: discord.Relationship): pass - - @abstractmethod - async def on_relationship_remove(self, relationship: discord.Relationship): pass - - @abstractmethod - async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship): pass + async def on_group_remove(self, chhanel: discord.GroupChannel, user: discord.User): pass \ No newline at end of file diff --git a/src/tests/custom/discord/src/discord_bot/appsettings.json b/src/tests/custom/discord/src/discord_bot/appsettings.json index 2725302b..5e211c01 100644 --- a/src/tests/custom/discord/src/discord_bot/appsettings.json +++ b/src/tests/custom/discord/src/discord_bot/appsettings.json @@ -6,9 +6,13 @@ "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" }, "LoggingSettings": { - "Path": "logs/", - "Filename": "log_dev.log", - "ConsoleLogLevel": "TRACE", - "FileLogLevel": "TRACE" - } + "Path": "logs/", + "Filename": "log_dev.log", + "ConsoleLogLevel": "TRACE", + "FileLogLevel": "TRACE" + }, + "DiscordBotSettings": { + "Token": "", + "Prefix": "!cd " + } } \ No newline at end of file diff --git a/src/tests/custom/discord/src/discord_bot/main.py b/src/tests/custom/discord/src/discord_bot/main.py index f6c79e69..669645fe 100644 --- a/src/tests/custom/discord/src/discord_bot/main.py +++ b/src/tests/custom/discord/src/discord_bot/main.py @@ -1,7 +1,7 @@ import asyncio from typing import Optional -from cpl_core.application import ApplicationBuilder +from cpl_core.application import ApplicationBuilder, ApplicationABC from discord_bot.application import Application from discord_bot.startup import Startup @@ -15,7 +15,7 @@ class Main: async def main(self): app_builder = ApplicationBuilder(Application) app_builder.use_startup(Startup) - self._app: Application = await app_builder.build_async() + self._app: ApplicationABC = await app_builder.build_async() await self._app.run_async() async def stop(self): diff --git a/src/tests/custom/discord/src/discord_bot/startup.py b/src/tests/custom/discord/src/discord_bot/startup.py index e138c5d1..11599cb2 100644 --- a/src/tests/custom/discord/src/discord_bot/startup.py +++ b/src/tests/custom/discord/src/discord_bot/startup.py @@ -7,6 +7,7 @@ from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum from modules.hello_world.on_ready_event import OnReadyEvent from modules.hello_world.on_ready_test_event import OnReadyTestEvent from modules.hello_world.ping_command import PingCommand +from modules.hello_world.purge_command import PurgeCommand class Startup(StartupABC): @@ -28,5 +29,6 @@ class Startup(StartupABC): dc_collection.add_event(DiscordEventTypesEnum.on_ready.value, OnReadyEvent) dc_collection.add_event(DiscordEventTypesEnum.on_ready.value, OnReadyTestEvent) dc_collection.add_command(PingCommand) + dc_collection.add_command(PurgeCommand) return services.build_service_provider() diff --git a/src/tests/custom/discord/src/modules/hello_world/ping_command.py b/src/tests/custom/discord/src/modules/hello_world/ping_command.py index 0f6b8106..8d2468b7 100644 --- a/src/tests/custom/discord/src/modules/hello_world/ping_command.py +++ b/src/tests/custom/discord/src/modules/hello_world/ping_command.py @@ -20,8 +20,9 @@ class PingCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.command() + @commands.hybrid_command() async def ping(self, ctx: Context): self._logger.debug(__name__, f'Received command ping {ctx}') self._logger.info(__name__, f'Bot name {self._bot.user.name}') self._logger.trace(__name__, f'Finished ping command') + await ctx.send('Pong') diff --git a/src/tests/custom/discord/src/modules/hello_world/purge_command.py b/src/tests/custom/discord/src/modules/hello_world/purge_command.py new file mode 100644 index 00000000..037543f5 --- /dev/null +++ b/src/tests/custom/discord/src/modules/hello_world/purge_command.py @@ -0,0 +1,31 @@ +from discord.ext import commands +from discord.ext.commands import Context + +from cpl_core.logging import LoggerABC +from cpl_discord.command.discord_command_abc import DiscordCommandABC +from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC + + +class PurgeCommand(DiscordCommandABC): + + def __init__( + self, + logger: LoggerABC, + bot: DiscordBotServiceABC, + ): + DiscordCommandABC.__init__(self) + + self._logger = logger + self._bot = bot + + self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') + + @commands.hybrid_command() + async def purge(self, ctx: Context): + self._logger.debug(__name__, f'Received command ping {ctx}') + self._logger.info(__name__, f'Bot name {self._bot.user.name}') + self._logger.trace(__name__, f'Finished ping command') + await ctx.channel.purge() + if ctx.interaction is None: + return + await ctx.interaction.response.send_message('Purged this channel xD')