Add support for integration create/update/delete events
This commit is contained in:
parent
2ea2693bd7
commit
ab6d592f8c
@ -572,6 +572,9 @@ class Intents(BaseFlags):
|
|||||||
This corresponds to the following events:
|
This corresponds to the following events:
|
||||||
|
|
||||||
- :func:`on_guild_integrations_update`
|
- :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.
|
This does not correspond to any attributes or classes in the library in terms of cache.
|
||||||
"""
|
"""
|
||||||
|
@ -29,6 +29,7 @@ __all__ = (
|
|||||||
'RawReactionActionEvent',
|
'RawReactionActionEvent',
|
||||||
'RawReactionClearEvent',
|
'RawReactionClearEvent',
|
||||||
'RawReactionClearEmojiEvent',
|
'RawReactionClearEmojiEvent',
|
||||||
|
'RawIntegrationDeleteEvent',
|
||||||
)
|
)
|
||||||
|
|
||||||
class _RawReprMixin:
|
class _RawReprMixin:
|
||||||
@ -222,3 +223,29 @@ class RawReactionClearEmojiEvent(_RawReprMixin):
|
|||||||
self.guild_id = int(data['guild_id'])
|
self.guild_id = int(data['guild_id'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.guild_id = None
|
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
|
||||||
|
@ -51,6 +51,7 @@ from . import utils
|
|||||||
from .flags import ApplicationFlags, Intents, MemberCacheFlags
|
from .flags import ApplicationFlags, Intents, MemberCacheFlags
|
||||||
from .object import Object
|
from .object import Object
|
||||||
from .invite import Invite
|
from .invite import Invite
|
||||||
|
from .integrations import _integration_factory
|
||||||
from .interactions import Interaction
|
from .interactions import Interaction
|
||||||
from .ui.view import ViewStore
|
from .ui.view import ViewStore
|
||||||
from .stage_instance import StageInstance
|
from .stage_instance import StageInstance
|
||||||
@ -957,6 +958,35 @@ class ConnectionState:
|
|||||||
else:
|
else:
|
||||||
log.debug('GUILD_INTEGRATIONS_UPDATE referencing an unknown guild ID: %s. Discarding.', data['guild_id'])
|
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):
|
def parse_webhooks_update(self, data):
|
||||||
channel = self.get_channel(int(data['channel_id']))
|
channel = self.get_channel(int(data['channel_id']))
|
||||||
if channel is not None:
|
if channel is not None:
|
||||||
|
45
docs/api.rst
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)
|
.. function:: on_guild_integrations_update(guild)
|
||||||
|
|
||||||
.. versionadded:: 1.4
|
|
||||||
|
|
||||||
Called whenever an integration is created, modified, or removed from a guild.
|
Called whenever an integration is created, modified, or removed from a guild.
|
||||||
|
|
||||||
This requires :attr:`Intents.integrations` to be enabled.
|
This requires :attr:`Intents.integrations` to be enabled.
|
||||||
|
|
||||||
|
.. versionadded:: 1.4
|
||||||
|
|
||||||
:param guild: The guild that had its integrations updated.
|
:param guild: The guild that had its integrations updated.
|
||||||
:type guild: :class:`Guild`
|
: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)
|
.. function:: on_webhooks_update(channel)
|
||||||
|
|
||||||
Called whenever a webhook is created, modified, or removed from a guild channel.
|
Called whenever a webhook is created, modified, or removed from a guild channel.
|
||||||
@ -3332,6 +3365,14 @@ RawReactionClearEmojiEvent
|
|||||||
.. autoclass:: RawReactionClearEmojiEvent()
|
.. autoclass:: RawReactionClearEmojiEvent()
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
RawIntegrationDeleteEvent
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. attributetable:: RawIntegrationDeleteEvent
|
||||||
|
|
||||||
|
.. autoclass:: RawIntegrationDeleteEvent()
|
||||||
|
:members:
|
||||||
|
|
||||||
PartialWebhookGuild
|
PartialWebhookGuild
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user