From 81795082488fc135c1f45188da7d457d21e1ccbb Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 13 Feb 2023 16:58:46 +0100 Subject: [PATCH] Added scheduled event support for cpl-discord --- src/cpl_discord/.cpl/__init__.py | 4 +-- 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 | 10 +++---- src/cpl_discord/discord_event_types_enum.py | 10 +++++++ src/cpl_discord/events/__init__.py | 4 +-- .../events/on_scheduled_event_create_abc.py | 11 +++++++ .../events/on_scheduled_event_delete_abc.py | 11 +++++++ .../events/on_scheduled_event_update_abc.py | 11 +++++++ .../events/on_scheduled_event_user_add_abc.py | 11 +++++++ .../on_scheduled_event_user_remove_abc.py | 11 +++++++ src/cpl_discord/helper/__init__.py | 4 +-- src/cpl_discord/service/__init__.py | 4 +-- src/cpl_discord/service/discord_service.py | 30 +++++++++++++++++++ 17 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 src/cpl_discord/events/on_scheduled_event_create_abc.py create mode 100644 src/cpl_discord/events/on_scheduled_event_delete_abc.py create mode 100644 src/cpl_discord/events/on_scheduled_event_update_abc.py create mode 100644 src/cpl_discord/events/on_scheduled_event_user_add_abc.py create mode 100644 src/cpl_discord/events/on_scheduled_event_user_remove_abc.py diff --git a/src/cpl_discord/.cpl/__init__.py b/src/cpl_discord/.cpl/__init__.py index 6c75166f..dcada057 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/__init__.py b/src/cpl_discord/__init__.py index 2d33b3f7..100e9dd6 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/application/__init__.py b/src/cpl_discord/application/__init__.py index caabdd76..838c6c15 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/command/__init__.py b/src/cpl_discord/command/__init__.py index 1d3836b2..0b5b94db 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/configuration/__init__.py b/src/cpl_discord/configuration/__init__.py index 7278a1b9..0fefae46 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/container/__init__.py b/src/cpl_discord/container/__init__.py index 606b067c..3ce5277a 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json index bf3c28fe..b9ece160 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.post2" + "Micro": "2" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,12 +16,12 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.12.1.post2", - "discord.py==2.1.0", - "cpl-query>=2022.12.2.post1" + "cpl-core==2022.12.1.post3", + "discord.py==2.1.1", + "cpl-query==2022.12.2.post1" ], "DevDependencies": [ - "cpl-cli>=2022.12.1" + "cpl-cli==2022.12.1.post3" ], "PythonVersion": ">=3.10", "PythonPath": {}, diff --git a/src/cpl_discord/discord_event_types_enum.py b/src/cpl_discord/discord_event_types_enum.py index c8069eab..9d306cb7 100644 --- a/src/cpl_discord/discord_event_types_enum.py +++ b/src/cpl_discord/discord_event_types_enum.py @@ -47,6 +47,11 @@ from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiA from cpl_discord.events.on_reaction_remove_abc import OnReactionRemoveABC from cpl_discord.events.on_ready_abc import OnReadyABC from cpl_discord.events.on_resume_abc import OnResumeABC +from cpl_discord.events.on_scheduled_event_create_abc import OnScheduledEventCreateABC +from cpl_discord.events.on_scheduled_event_delete_abc import OnScheduledEventDeleteABC +from cpl_discord.events.on_scheduled_event_update_abc import OnScheduledEventUpdateABC +from cpl_discord.events.on_scheduled_event_user_add_abc import OnScheduledEventUserAddABC +from cpl_discord.events.on_scheduled_event_user_remove_abc import OnScheduledEventUserRemoveABC from cpl_discord.events.on_typing_abc import OnTypingABC from cpl_discord.events.on_user_update_abc import OnUserUpdateABC from cpl_discord.events.on_voice_state_update_abc import OnVoiceStateUpdateABC @@ -76,6 +81,11 @@ class DiscordEventTypesEnum(Enum): on_guild_role_delete = OnGuildRoleDeleteABC on_guild_role_update = OnGuildRoleUpdateABC on_guild_unavailable = OnGuildUnavailableABC + on_scheduled_event_create = OnScheduledEventCreateABC + on_scheduled_event_delete = OnScheduledEventDeleteABC + on_scheduled_event_update = OnScheduledEventUpdateABC + on_scheduled_event_user_add = OnScheduledEventUserAddABC + on_scheduled_event_user_remove = OnScheduledEventUserRemoveABC on_guild_update = OnGuildUpdateABC on_invite_create = OnInviteCreateABC on_invite_delete = OnInviteDeleteABC diff --git a/src/cpl_discord/events/__init__.py b/src/cpl_discord/events/__init__.py index 499ed9ac..dd5c3304 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/events/on_scheduled_event_create_abc.py b/src/cpl_discord/events/on_scheduled_event_create_abc.py new file mode 100644 index 00000000..a83a6e33 --- /dev/null +++ b/src/cpl_discord/events/on_scheduled_event_create_abc.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod +import discord + + +class OnScheduledEventCreateABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_scheduled_event_create(self, event: discord.ScheduledEvent): pass diff --git a/src/cpl_discord/events/on_scheduled_event_delete_abc.py b/src/cpl_discord/events/on_scheduled_event_delete_abc.py new file mode 100644 index 00000000..afec0ce7 --- /dev/null +++ b/src/cpl_discord/events/on_scheduled_event_delete_abc.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod +import discord + + +class OnScheduledEventDeleteABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_scheduled_event_delete(self, event: discord.ScheduledEvent): pass diff --git a/src/cpl_discord/events/on_scheduled_event_update_abc.py b/src/cpl_discord/events/on_scheduled_event_update_abc.py new file mode 100644 index 00000000..b78ba357 --- /dev/null +++ b/src/cpl_discord/events/on_scheduled_event_update_abc.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod +import discord + + +class OnScheduledEventUpdateABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_scheduled_event_update(self, before: discord.ScheduledEvent, after: discord.ScheduledEvent): pass diff --git a/src/cpl_discord/events/on_scheduled_event_user_add_abc.py b/src/cpl_discord/events/on_scheduled_event_user_add_abc.py new file mode 100644 index 00000000..944ab298 --- /dev/null +++ b/src/cpl_discord/events/on_scheduled_event_user_add_abc.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod +import discord + + +class OnScheduledEventUserAddABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_scheduled_event_user_add(self, event: discord.ScheduledEvent, user: discord.User): pass diff --git a/src/cpl_discord/events/on_scheduled_event_user_remove_abc.py b/src/cpl_discord/events/on_scheduled_event_user_remove_abc.py new file mode 100644 index 00000000..0839207f --- /dev/null +++ b/src/cpl_discord/events/on_scheduled_event_user_remove_abc.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod +import discord + + +class OnScheduledEventUserRemoveABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_scheduled_event_user_remove(self, event: discord.ScheduledEvent, user: discord.User): pass diff --git a/src/cpl_discord/helper/__init__.py b/src/cpl_discord/helper/__init__.py index 6fabdc5c..b29a74a0 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/service/__init__.py b/src/cpl_discord/service/__init__.py index a7e5d9c6..d8e5a409 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.post2' +__version__ = '2022.12.2' 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.post2') +version_info = VersionInfo(major='2022', minor='12', micro='2') diff --git a/src/cpl_discord/service/discord_service.py b/src/cpl_discord/service/discord_service.py index 6316952d..44c09db6 100644 --- a/src/cpl_discord/service/discord_service.py +++ b/src/cpl_discord/service/discord_service.py @@ -57,6 +57,11 @@ from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiA from cpl_discord.events.on_reaction_remove_abc import OnReactionRemoveABC from cpl_discord.events.on_ready_abc import OnReadyABC from cpl_discord.events.on_resume_abc import OnResumeABC +from cpl_discord.events.on_scheduled_event_create_abc import OnScheduledEventCreateABC +from cpl_discord.events.on_scheduled_event_delete_abc import OnScheduledEventDeleteABC +from cpl_discord.events.on_scheduled_event_update_abc import OnScheduledEventUpdateABC +from cpl_discord.events.on_scheduled_event_user_add_abc import OnScheduledEventUserAddABC +from cpl_discord.events.on_scheduled_event_user_remove_abc import OnScheduledEventUserRemoveABC from cpl_discord.events.on_typing_abc import OnTypingABC from cpl_discord.events.on_user_update_abc import OnUserUpdateABC from cpl_discord.events.on_voice_state_update_abc import OnVoiceStateUpdateABC @@ -339,6 +344,31 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta): self._logger.trace(__name__, f'Received on_guild_unavailable:\n\t{guild}') await self._handle_event(OnGuildUnavailableABC, guild) + @commands.Cog.listener() + async def on_scheduled_event_create(self, event: discord.ScheduledEvent): + self._logger.trace(__name__, f'Received on_scheduled_event_create:\n\t{event}') + await self._handle_event(OnScheduledEventCreateABC, event) + + @commands.Cog.listener() + async def on_scheduled_event_delete(self, event: discord.ScheduledEvent): + self._logger.trace(__name__, f'Received on_scheduled_event_delete:\n\t{event}') + await self._handle_event(OnScheduledEventDeleteABC, event) + + @commands.Cog.listener() + async def on_scheduled_event_update(self, before: discord.ScheduledEvent, after: discord.ScheduledEvent): + self._logger.trace(__name__, f'Received on_scheduled_event_update:\n\t{before}, {after}') + await self._handle_event(OnScheduledEventUpdateABC, before, after) + + @commands.Cog.listener() + async def on_scheduled_event_user_add(self, event: discord.ScheduledEvent, user: discord.User): + self._logger.trace(__name__, f'Received on_scheduled_event_user_add:\n\t{event}, {user}') + await self._handle_event(OnScheduledEventUserAddABC, event, user) + + @commands.Cog.listener() + async def on_scheduled_event_user_remove(self, event: discord.ScheduledEvent, user: discord.User): + self._logger.trace(__name__, f'Received on_scheduled_event_user_remove:\n\t{event}, {user}') + await self._handle_event(OnScheduledEventUserRemoveABC, event, user) + @commands.Cog.listener() async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): self._logger.trace(__name__, f'Received on_voice_state_update:\n\t{member}\n\t{before}\n\t{after}')