diff options
| author | Nadir Chowdhury <[email protected]> | 2021-06-07 08:28:26 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-06-07 03:28:26 -0400 |
| commit | ab6d592f8ca393e5ef642295b0da44557ad4a2b0 (patch) | |
| tree | a5d44ac3d7617a1d51ee018009b184bc5a57a40f /discord | |
| parent | Add the Guild.delete_custom_emoji method (diff) | |
| download | discord.py-ab6d592f8ca393e5ef642295b0da44557ad4a2b0.tar.xz discord.py-ab6d592f8ca393e5ef642295b0da44557ad4a2b0.zip | |
Add support for integration create/update/delete events
Diffstat (limited to 'discord')
| -rw-r--r-- | discord/flags.py | 3 | ||||
| -rw-r--r-- | discord/raw_models.py | 27 | ||||
| -rw-r--r-- | discord/state.py | 30 |
3 files changed, 60 insertions, 0 deletions
diff --git a/discord/flags.py b/discord/flags.py index 166a82ef..d6a892c8 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -572,6 +572,9 @@ class Intents(BaseFlags): This corresponds to the following events: - :func:`on_guild_integrations_update` + - :func:`on_integration_create` + - :func:`on_integration_update` + - :func:`on_raw_integration_delete` This does not correspond to any attributes or classes in the library in terms of cache. """ diff --git a/discord/raw_models.py b/discord/raw_models.py index 6c0b0da3..0fdae813 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -29,6 +29,7 @@ __all__ = ( 'RawReactionActionEvent', 'RawReactionClearEvent', 'RawReactionClearEmojiEvent', + 'RawIntegrationDeleteEvent', ) class _RawReprMixin: @@ -222,3 +223,29 @@ class RawReactionClearEmojiEvent(_RawReprMixin): self.guild_id = int(data['guild_id']) except KeyError: self.guild_id = None + +class RawIntegrationDeleteEvent(_RawReprMixin): + """Represents the payload for a :func:`on_raw_integration_delete` event. + + .. versionadded:: 2.0 + + Attributes + ----------- + integration_id: :class:`int` + The ID of the integration that got deleted. + application_id: Optional[:class:`int`] + The ID of the bot/OAuth2 application for this deleted integration. + guild_id: :class:`int` + The guild ID where the integration got deleted. + """ + + __slots__ = ('integration_id', 'application_id', 'guild_id') + + def __init__(self, data): + self.integration_id = int(data['id']) + self.guild_id = int(data['guild_id']) + + try: + self.application_id = int(data['application_id']) + except KeyError: + self.application_id = None diff --git a/discord/state.py b/discord/state.py index 71892fd8..f9c02856 100644 --- a/discord/state.py +++ b/discord/state.py @@ -51,6 +51,7 @@ from . import utils from .flags import ApplicationFlags, Intents, MemberCacheFlags from .object import Object from .invite import Invite +from .integrations import _integration_factory from .interactions import Interaction from .ui.view import ViewStore from .stage_instance import StageInstance @@ -957,6 +958,35 @@ class ConnectionState: else: log.debug('GUILD_INTEGRATIONS_UPDATE referencing an unknown guild ID: %s. Discarding.', data['guild_id']) + def parse_integration_create(self, data): + guild_id = int(data.pop('guild_id')) + guild = self._get_guild(guild_id) + if guild is not None: + cls, _ = _integration_factory(data['type']) + integration = cls(data=data, guild=guild) + self.dispatch('integration_create', integration) + else: + log.debug('INTEGRATION_CREATE referencing an unknown guild ID: %s. Discarding.', guild_id) + + def parse_integration_update(self, data): + guild_id = int(data.pop('guild_id')) + guild = self._get_guild(guild_id) + if guild is not None: + cls, _ = _integration_factory(data['type']) + integration = cls(data=data, guild=guild) + self.dispatch('integration_update', integration) + else: + log.debug('INTEGRATION_UPDATE referencing an unknown guild ID: %s. Discarding.', guild_id) + + def parse_integration_delete(self, data): + guild_id = int(data['guild_id']) + guild = self._get_guild(guild_id) + if guild is not None: + raw = RawIntegrationDeleteEvent(data) + self.dispatch('raw_integration_delete', raw) + else: + log.debug('INTEGRATION_DELETE referencing an unknown guild ID: %s. Discarding.', guild_id) + def parse_webhooks_update(self, data): channel = self.get_channel(int(data['channel_id'])) if channel is not None: |