Browse Source

Add support for integration create/update/delete events

pull/7030/head
Nadir Chowdhury 4 years ago
committed by GitHub
parent
commit
ab6d592f8c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      discord/flags.py
  2. 27
      discord/raw_models.py
  3. 30
      discord/state.py
  4. 45
      docs/api.rst

3
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.
"""

27
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

30
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:

45
docs/api.rst

@ -660,15 +660,48 @@ to handle it, which defaults to print a traceback and ignoring the exception.
.. function:: on_guild_integrations_update(guild)
.. versionadded:: 1.4
Called whenever an integration is created, modified, or removed from a guild.
This requires :attr:`Intents.integrations` to be enabled.
.. versionadded:: 1.4
:param guild: The guild that had its integrations updated.
:type guild: :class:`Guild`
.. function:: on_integration_create(integration)
Called when an integration is created.
This requires :attr:`Intents.integrations` to be enabled.
.. versionadded:: 2.0
:param integration: The integration that was created.
:type integration: :class:`Integration`
.. function:: on_integration_update(integration)
Called when an integration is updated.
This requires :attr:`Intents.integrations` to be enabled.
.. versionadded:: 2.0
:param integration: The integration that was created.
:type integration: :class:`Integration`
.. function:: on_raw_integration_delete(payload)
Called when an integration is deleted.
This requires :attr:`Intents.integrations` to be enabled.
.. versionadded:: 2.0
:param payload: The raw event payload data.
:type payload: :class:`RawIntegrationDeleteEvent`
.. function:: on_webhooks_update(channel)
Called whenever a webhook is created, modified, or removed from a guild channel.
@ -3332,6 +3365,14 @@ RawReactionClearEmojiEvent
.. autoclass:: RawReactionClearEmojiEvent()
:members:
RawIntegrationDeleteEvent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. attributetable:: RawIntegrationDeleteEvent
.. autoclass:: RawIntegrationDeleteEvent()
:members:
PartialWebhookGuild
~~~~~~~~~~~~~~~~~~~~

Loading…
Cancel
Save