From 8ad6d50a04a0d2a95399cc0a7fd3efeafc9dcbef Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 3 Oct 2022 17:31:42 +0200 Subject: [PATCH] Added reaction raw events --- 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/discord_event_types_enum.py | 8 +++++++ src/cpl_discord/events/__init__.py | 4 ++-- .../events/on_raw_reaction_add_abc.py | 13 +++++++++++ .../events/on_raw_reaction_clear_abc.py | 13 +++++++++++ .../events/on_raw_reaction_clear_emoji_abc.py | 13 +++++++++++ .../events/on_raw_reaction_remove_abc.py | 13 +++++++++++ src/cpl_discord/helper/__init__.py | 4 ++-- src/cpl_discord/service/__init__.py | 4 ++-- src/cpl_discord/service/discord_service.py | 23 ++++++++++++++++++- 15 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 src/cpl_discord/events/on_raw_reaction_add_abc.py create mode 100644 src/cpl_discord/events/on_raw_reaction_clear_abc.py create mode 100644 src/cpl_discord/events/on_raw_reaction_clear_emoji_abc.py create mode 100644 src/cpl_discord/events/on_raw_reaction_remove_abc.py diff --git a/src/cpl_discord/__init__.py b/src/cpl_discord/__init__.py index 71bb56c8..d7558290 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.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/application/__init__.py b/src/cpl_discord/application/__init__.py index efcb28ad..42dd438f 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.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/command/__init__.py b/src/cpl_discord/command/__init__.py index e3b5c5b0..f4fcd32b 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.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/configuration/__init__.py b/src/cpl_discord/configuration/__init__.py index 9d3ae054..e381bd7f 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.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/container/__init__.py b/src/cpl_discord/container/__init__.py index 5f7684f1..8a2e5496 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) 2021 - 2022 sh-edraft.de' -__version__ = '2022.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json index a4c3788c..852c882d 100644 --- a/src/cpl_discord/cpl-discord.json +++ b/src/cpl_discord/cpl-discord.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "10", - "Micro": "0.post2" + "Micro": "0.post3" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl_discord/discord_event_types_enum.py b/src/cpl_discord/discord_event_types_enum.py index 7106d29a..c8069eab 100644 --- a/src/cpl_discord/discord_event_types_enum.py +++ b/src/cpl_discord/discord_event_types_enum.py @@ -37,6 +37,10 @@ from cpl_discord.events.on_private_channel_create_abc import OnPrivateChannelCre from cpl_discord.events.on_private_channel_delete_abc import OnPrivateChannelDeleteABC from cpl_discord.events.on_private_channel_pins_update_abc import OnPrivateChannelPinsUpdateABC from cpl_discord.events.on_private_channel_update_abc import OnPrivateChannelUpdateABC +from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC +from cpl_discord.events.on_raw_reaction_clear_abc import OnRawReactionClearABC +from cpl_discord.events.on_raw_reaction_clear_emoji_abc import OnRawReactionClearEmojiABC +from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC from cpl_discord.events.on_reaction_add_abc import OnReactionAddABC from cpl_discord.events.on_reaction_clear_abc import OnReactionClearABC from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC @@ -87,6 +91,10 @@ class DiscordEventTypesEnum(Enum): on_private_channel_delete = OnPrivateChannelDeleteABC on_private_channel_pins_update = OnPrivateChannelPinsUpdateABC on_private_channel_update = OnPrivateChannelUpdateABC + on_raw_reaction_add = OnRawReactionAddABC + on_raw_reaction_clear = OnRawReactionClearABC + on_raw_reaction_clear_emoji = OnRawReactionClearEmojiABC + on_raw_reaction_remove = OnRawReactionRemoveABC on_reaction_add = OnReactionAddABC on_reaction_clear = OnReactionClearABC on_reaction_clear_emoji = OnReactionClearEmojiABC diff --git a/src/cpl_discord/events/__init__.py b/src/cpl_discord/events/__init__.py index d07e23e1..d7d11aa0 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.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/events/on_raw_reaction_add_abc.py b/src/cpl_discord/events/on_raw_reaction_add_abc.py new file mode 100644 index 00000000..99e6fcbf --- /dev/null +++ b/src/cpl_discord/events/on_raw_reaction_add_abc.py @@ -0,0 +1,13 @@ +from abc import ABC, abstractmethod +import discord +from discord import RawReactionActionEvent + + +class OnRawReactionAddABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_raw_reaction_add(self, payload: RawReactionActionEvent): pass + \ No newline at end of file diff --git a/src/cpl_discord/events/on_raw_reaction_clear_abc.py b/src/cpl_discord/events/on_raw_reaction_clear_abc.py new file mode 100644 index 00000000..dc1895b5 --- /dev/null +++ b/src/cpl_discord/events/on_raw_reaction_clear_abc.py @@ -0,0 +1,13 @@ +from abc import ABC, abstractmethod +import discord +from discord import RawReactionActionEvent + + +class OnRawReactionClearABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_raw_reaction_clear(self, payload: RawReactionActionEvent): pass + \ No newline at end of file diff --git a/src/cpl_discord/events/on_raw_reaction_clear_emoji_abc.py b/src/cpl_discord/events/on_raw_reaction_clear_emoji_abc.py new file mode 100644 index 00000000..6bd5b953 --- /dev/null +++ b/src/cpl_discord/events/on_raw_reaction_clear_emoji_abc.py @@ -0,0 +1,13 @@ +from abc import ABC, abstractmethod +import discord +from discord import RawReactionActionEvent + + +class OnRawReactionClearEmojiABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_raw_reaction_clear_emoji(self, payload: RawReactionActionEvent): pass + diff --git a/src/cpl_discord/events/on_raw_reaction_remove_abc.py b/src/cpl_discord/events/on_raw_reaction_remove_abc.py new file mode 100644 index 00000000..fcd02d40 --- /dev/null +++ b/src/cpl_discord/events/on_raw_reaction_remove_abc.py @@ -0,0 +1,13 @@ +from abc import ABC, abstractmethod +import discord +from discord import RawReactionActionEvent + + +class OnRawReactionRemoveABC(ABC): + + @abstractmethod + def __init__(self): pass + + @abstractmethod + async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): pass + \ No newline at end of file diff --git a/src/cpl_discord/helper/__init__.py b/src/cpl_discord/helper/__init__.py index fb493f10..896110ce 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) 2021 - 2022 sh-edraft.de' -__version__ = '2022.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/service/__init__.py b/src/cpl_discord/service/__init__.py index d8e7d69a..a269aef3 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.10.0.post2' +__version__ = '2022.10.0.post3' 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='10', micro='0.post2') +version_info = VersionInfo(major='2022', minor='10', micro='0.post3') diff --git a/src/cpl_discord/service/discord_service.py b/src/cpl_discord/service/discord_service.py index 70518911..e085fccd 100644 --- a/src/cpl_discord/service/discord_service.py +++ b/src/cpl_discord/service/discord_service.py @@ -2,6 +2,7 @@ from datetime import datetime from typing import Optional, Sequence, Union, Type import discord +from discord import RawReactionActionEvent from discord.ext import commands from discord.ext.commands import Context, CommandError, Cog, Command @@ -175,10 +176,30 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta): await self._handle_event(OnBulkMessageDeleteABC, messages) @commands.Cog.listener() - async def on_message_edit(self, before: discord.Message, after: discord.Message): + async def on_raw_message_edit(self, before: discord.Message, after: discord.Message): self._logger.trace(__name__, f'Received on_message_edit:\n\t{before}\n\t{after}') await self._handle_event(OnMessageEditABC, before, after) + @commands.Cog.listener() + async def on_raw_reaction_add(self, payload: RawReactionActionEvent): + self._logger.trace(__name__, f'Received on_raw_reaction_add') + await self._handle_event(OnReactionAddABC, payload) + + @commands.Cog.listener() + async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): + self._logger.trace(__name__, f'Received on_raw_reaction_remove') + await self._handle_event(OnReactionRemoveABC, payload) + + @commands.Cog.listener() + async def on_raw_reaction_clear(self, payload: RawReactionActionEvent): + self._logger.trace(__name__, f'Received on_raw_reaction_clear') + await self._handle_event(OnReactionClearABC, payload) + + @commands.Cog.listener() + async def on_raw_reaction_clear_emoji(self, payload: RawReactionActionEvent): + self._logger.trace(__name__, f'Received on_raw_reaction_clear_emoji') + await self._handle_event(OnReactionClearEmojiABC, payload) + @commands.Cog.listener() async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): self._logger.trace(__name__, f'Received on_reaction_add:\n\t{reaction}\n\t{user}')