Fixed discord event schematic

This commit is contained in:
Sven Heidemann 2023-01-12 13:48:55 +01:00
parent 7be3cf38dc
commit 8b40c65661
11 changed files with 48 additions and 28 deletions

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -23,4 +23,4 @@ from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -12,14 +12,16 @@ class Event(GenerateSchematicABC):
GenerateSchematicABC.__init__(self, name, schematic, path) GenerateSchematicABC.__init__(self, name, schematic, path)
event = None event = None
event_class = None
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
for event_type in DiscordEventTypesEnum: for event_type in DiscordEventTypesEnum:
event_name = event_type.value.__name__.replace("ABC", '') event_name = event_type.value.__name__.replace("ABC", '')
if event_name in name: if name.endswith(event_name):
name = name.replace(event_name, "") name = name.replace(event_name, "")
event = event_name event = event_name
event_class = event_type.value
break break
if event is None: if event is None:
@ -29,15 +31,27 @@ class Event(GenerateSchematicABC):
Console.write_line(f'\t{event_type.value.__name__.replace("ABC", "")}') Console.write_line(f'\t{event_type.value.__name__.replace("ABC", "")}')
sys.exit() sys.exit()
self._event_class = f'{event}ABC' self._event_class_name = f'{event}ABC'
self._name = f'{String.convert_to_snake_case(self._event_class.replace("ABC", ""))}_{schematic}.py' event_snake_case = String.convert_to_snake_case(self._event_class_name.replace("ABC", ""))
self._class_name = f'{self._event_class.replace("ABC", "")}{String.first_to_upper(schematic)}'
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 != '': if name != '':
self._name = f'{String.convert_to_snake_case(name)}_{self._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._class_name = f'{String.first_to_upper(name)}{self._class_name}'
def get_code(self) -> str: def get_code(self) -> str:
code = """\ code = """\
import discord
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from cpl_discord.events import $EventClass from cpl_discord.events import $EventClass
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
@ -50,15 +64,21 @@ class Event(GenerateSchematicABC):
logger: LoggerABC, logger: LoggerABC,
bot: DiscordBotServiceABC, bot: DiscordBotServiceABC,
): ):
OnReadyABC.__init__(self) $EventClass.__init__(self)
self._logger = logger self._logger = logger
self._bot = bot self._bot = bot
async def on_ready(self): async def $Func($Signature):
pass 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 @classmethod
def register(cls): def register(cls):

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -55,4 +55,4 @@ def get_discord_collection(services: 'ServiceCollectionABC') -> 'DiscordCollecti
# build-ignore-end # build-ignore-end
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.application'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from collections import namedtuple
from .discord_bot_application_abc import DiscordBotApplicationABC from .discord_bot_application_abc import DiscordBotApplicationABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.command'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -25,4 +25,4 @@ from .discord_command_abc import DiscordCommandABC
from .discord_commands_meta import DiscordCogMeta from .discord_commands_meta import DiscordCogMeta
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.configuration'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from collections import namedtuple
from .discord_bot_settings import DiscordBotSettings from .discord_bot_settings import DiscordBotSettings
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.container'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -31,4 +31,4 @@ from .thread import Thread
from .voice_channel import VoiceChannel from .voice_channel import VoiceChannel
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -4,7 +4,7 @@
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "12", "Minor": "12",
"Micro": "1.post1" "Micro": "1.post2"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.events'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -69,4 +69,4 @@ from .on_voice_state_update_abc import OnVoiceStateUpdateABC
from .on_webhooks_update_abc import OnWebhooksUpdateABC from .on_webhooks_update_abc import OnWebhooksUpdateABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.helper'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from collections import namedtuple
from .to_containers_converter import ToContainersConverter from .to_containers_converter import ToContainersConverter
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_discord.service'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de' __copyright__ = 'Copyright (c) 2022 - 2023 sh-edraft.de'
__version__ = '2022.12.1.post1' __version__ = '2022.12.1.post2'
from collections import namedtuple from collections import namedtuple
@ -29,4 +29,4 @@ from .discord_service import DiscordService
from .discord_service_abc import DiscordServiceABC from .discord_service_abc import DiscordServiceABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') 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')