Add support for integration create/update/delete events
This commit is contained in:
@ -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.
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user