From 8b40c656612a7dcf067af799b88a7147cfec35ca Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Jan 2023 13:48:55 +0100 Subject: [PATCH] Fixed discord event schematic --- src/cpl_discord/.cpl/__init__.py | 4 +- .../.cpl/schematic_discord_event.py | 38 ++++++++++++++----- src/cpl_discord/__init__.py | 4 +- src/cpl_discord/application/__init__.py | 4 +- src/cpl_discord/command/__init__.py | 4 +- src/cpl_discord/configuration/__init__.py | 4 +- src/cpl_discord/container/__init__.py | 4 +- src/cpl_discord/cpl-discord.json | 2 +- src/cpl_discord/events/__init__.py | 4 +- src/cpl_discord/helper/__init__.py | 4 +- src/cpl_discord/service/__init__.py | 4 +- 11 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/cpl_discord/.cpl/__init__.py b/src/cpl_discord/.cpl/__init__.py index 25c717b1..6c75166f 100644 --- a/src/cpl_discord/.cpl/__init__.py +++ b/src/cpl_discord/.cpl/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' 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='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/.cpl/schematic_discord_event.py b/src/cpl_discord/.cpl/schematic_discord_event.py index 43f08354..d3c2387b 100644 --- a/src/cpl_discord/.cpl/schematic_discord_event.py +++ b/src/cpl_discord/.cpl/schematic_discord_event.py @@ -12,14 +12,16 @@ class Event(GenerateSchematicABC): GenerateSchematicABC.__init__(self, name, schematic, path) event = None + event_class = None from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum for event_type in DiscordEventTypesEnum: event_name = event_type.value.__name__.replace("ABC", '') - if event_name in name: + if name.endswith(event_name): name = name.replace(event_name, "") event = event_name + event_class = event_type.value break if event is None: @@ -29,15 +31,27 @@ class Event(GenerateSchematicABC): Console.write_line(f'\t{event_type.value.__name__.replace("ABC", "")}') sys.exit() - self._event_class = f'{event}ABC' - self._name = f'{String.convert_to_snake_case(self._event_class.replace("ABC", ""))}_{schematic}.py' - self._class_name = f'{self._event_class.replace("ABC", "")}{String.first_to_upper(schematic)}' + self._event_class_name = f'{event}ABC' + event_snake_case = String.convert_to_snake_case(self._event_class_name.replace("ABC", "")) + + if event_snake_case.lower() not in dir(event_class): + Console.error(f'Error in event {event}: Function {event_snake_case} not found!') + sys.exit() + + self._name = f'{event_snake_case}_{schematic}.py' + self._class_name = f'{self._event_class_name.replace("ABC", "")}{String.first_to_upper(schematic)}' + + from inspect import signature + self._func_name = event_snake_case + self._signature = str(signature(getattr(event_class, event_snake_case)))[1:][:-1] + if name != '': - self._name = f'{String.convert_to_snake_case(name)}_{self._name}' - self._class_name = f'{String.first_to_upper(name)}{self._class_name}' + self._name = f'{String.convert_to_snake_case(name)}_{self._name}' + self._class_name = f'{String.first_to_upper(name)}{self._class_name}' def get_code(self) -> str: code = """\ + import discord from cpl_core.logging import LoggerABC from cpl_discord.events import $EventClass from cpl_discord.service import DiscordBotServiceABC @@ -50,15 +64,21 @@ class Event(GenerateSchematicABC): logger: LoggerABC, bot: DiscordBotServiceABC, ): - OnReadyABC.__init__(self) + $EventClass.__init__(self) self._logger = logger self._bot = bot - async def on_ready(self): + async def $Func($Signature): pass """ - return self.build_code_str(code, Name=self._class_name, EventClass=self._event_class) + return self.build_code_str( + code, + Name=self._class_name, + EventClass=self._event_class_name, + Func=self._func_name, + Signature=self._signature + ) @classmethod def register(cls): diff --git a/src/cpl_discord/__init__.py b/src/cpl_discord/__init__.py index 046a599f..2d33b3f7 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) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' 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='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/application/__init__.py b/src/cpl_discord/application/__init__.py index fc324cb3..caabdd76 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) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' 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='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/command/__init__.py b/src/cpl_discord/command/__init__.py index bd8ffa24..1d3836b2 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) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' 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='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/configuration/__init__.py b/src/cpl_discord/configuration/__init__.py index 8fca7136..7278a1b9 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) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' 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='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/container/__init__.py b/src/cpl_discord/container/__init__.py index 430aac56..606b067c 100644 --- a/src/cpl_discord/container/__init__.py +++ b/src/cpl_discord/container/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord.container' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' from collections import namedtuple @@ -31,4 +31,4 @@ from .thread import Thread from .voice_channel import VoiceChannel VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json index d75b5cf7..bf3c28fe 100644 --- a/src/cpl_discord/cpl-discord.json +++ b/src/cpl_discord/cpl-discord.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "12", - "Micro": "1.post1" + "Micro": "1.post2" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl_discord/events/__init__.py b/src/cpl_discord/events/__init__.py index 6c4fe2b3..499ed9ac 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) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' from collections import namedtuple @@ -69,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='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/helper/__init__.py b/src/cpl_discord/helper/__init__.py index caaec2b4..6fabdc5c 100644 --- a/src/cpl_discord/helper/__init__.py +++ b/src/cpl_discord/helper/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_discord.helper' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' from collections import namedtuple @@ -24,4 +24,4 @@ from collections import namedtuple from .to_containers_converter import ToContainersConverter VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2022', minor='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2') diff --git a/src/cpl_discord/service/__init__.py b/src/cpl_discord/service/__init__.py index 6f0d18c5..a7e5d9c6 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) 2022 - 2023 sh-edraft.de' -__version__ = '2022.12.1.post1' +__version__ = '2022.12.1.post2' 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='12', micro='1.post1') +version_info = VersionInfo(major='2022', minor='12', micro='1.post2')