Browse Source

Add on_raw_app_command_permissions_update event

pull/8221/head
z03h 3 years ago
committed by GitHub
parent
commit
1aaa32d4bc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      discord/raw_models.py
  2. 5
      discord/state.py
  3. 22
      docs/api.rst

35
discord/raw_models.py

@ -29,6 +29,7 @@ from typing import TYPE_CHECKING, Optional, Set, List, Tuple, Union
from .enums import ChannelType, try_enum from .enums import ChannelType, try_enum
from .utils import _get_as_snowflake from .utils import _get_as_snowflake
from .app_commands import AppCommandPermissions
if TYPE_CHECKING: if TYPE_CHECKING:
from .types.gateway import ( from .types.gateway import (
@ -46,11 +47,14 @@ if TYPE_CHECKING:
TypingStartEvent, TypingStartEvent,
GuildMemberRemoveEvent, GuildMemberRemoveEvent,
) )
from .types.command import GuildApplicationCommandPermissions
from .message import Message from .message import Message
from .partial_emoji import PartialEmoji from .partial_emoji import PartialEmoji
from .member import Member from .member import Member
from .threads import Thread from .threads import Thread
from .user import User from .user import User
from .state import ConnectionState
from .guild import Guild
ReactionActionEvent = Union[MessageReactionAddEvent, MessageReactionRemoveEvent] ReactionActionEvent = Union[MessageReactionAddEvent, MessageReactionRemoveEvent]
@ -68,6 +72,7 @@ __all__ = (
'RawThreadMembersUpdate', 'RawThreadMembersUpdate',
'RawTypingEvent', 'RawTypingEvent',
'RawMemberRemoveEvent', 'RawMemberRemoveEvent',
'RawAppCommandPermissionsUpdateEvent',
) )
@ -432,3 +437,33 @@ class RawMemberRemoveEvent(_RawReprMixin):
def __init__(self, data: GuildMemberRemoveEvent, user: User, /) -> None: def __init__(self, data: GuildMemberRemoveEvent, user: User, /) -> None:
self.user: Union[User, Member] = user self.user: Union[User, Member] = user
self.guild_id: int = int(data['guild_id']) self.guild_id: int = int(data['guild_id'])
class RawAppCommandPermissionsUpdateEvent(_RawReprMixin):
"""Represents the payload for a :func:`on_raw_app_command_permissions_update` event.
.. versionadded:: 2.0
Attributes
----------
target_id: :class:`int`
The ID of the command or application whos permissions were updated.
When this is the application ID instead of a command ID, the permissions
apply to all commands that do not contain explicit overwrites.
application_id: :class:`int`
The ID of the application that the command belongs to.
guild: :class:`~discord.Guild`
The guild where the permissions were updated.
permissions: List[:class:`~discord.app_commands.AppCommandPermissions`]
List of new permissions for the app command.
"""
__slots__ = ('target_id', 'application_id', 'guild', 'permissions')
def __init__(self, *, data: GuildApplicationCommandPermissions, state: ConnectionState):
self.target_id: int = int(data['id'])
self.application_id: int = int(data['application_id'])
self.guild: Guild = state._get_or_create_unavailable_guild(int(data['guild_id']))
self.permissions: List[AppCommandPermissions] = [
AppCommandPermissions(data=perm, guild=self.guild, state=state) for perm in data['permissions']
]

5
discord/state.py

@ -95,6 +95,7 @@ if TYPE_CHECKING:
from .types.guild import Guild as GuildPayload from .types.guild import Guild as GuildPayload
from .types.message import Message as MessagePayload, PartialMessage as PartialMessagePayload from .types.message import Message as MessagePayload, PartialMessage as PartialMessagePayload
from .types import gateway as gw from .types import gateway as gw
from .types.command import GuildApplicationCommandPermissions as GuildApplicationCommandPermissionsPayload
T = TypeVar('T') T = TypeVar('T')
Channel = Union[GuildChannel, VocalGuildChannel, PrivateChannel, PartialMessageable] Channel = Union[GuildChannel, VocalGuildChannel, PrivateChannel, PartialMessageable]
@ -1475,6 +1476,10 @@ class ConnectionState:
else: else:
_log.debug('SCHEDULED_EVENT_USER_REMOVE referencing unknown guild ID: %s. Discarding.', data['guild_id']) _log.debug('SCHEDULED_EVENT_USER_REMOVE referencing unknown guild ID: %s. Discarding.', data['guild_id'])
def parse_application_command_permissions_update(self, data: GuildApplicationCommandPermissionsPayload):
raw = RawAppCommandPermissionsUpdateEvent(data=data, state=self)
self.dispatch('raw_app_command_permissions_update', raw)
def parse_voice_state_update(self, data: gw.VoiceStateUpdateEvent) -> None: def parse_voice_state_update(self, data: gw.VoiceStateUpdateEvent) -> None:
guild = self._get_guild(utils._get_as_snowflake(data, 'guild_id')) guild = self._get_guild(utils._get_as_snowflake(data, 'guild_id'))
channel_id = utils._get_as_snowflake(data, 'channel_id') channel_id = utils._get_as_snowflake(data, 'channel_id')

22
docs/api.rst

@ -203,8 +203,20 @@ to handle it, which defaults to logging the traceback and ignoring the exception
errors. In order to turn a function into a coroutine they must be ``async def`` errors. In order to turn a function into a coroutine they must be ``async def``
functions. functions.
App Commands
~~~~~~~~~~~~~
.. function:: on_raw_app_command_permissions_update(payload)
Called when application command permissions are updated.
.. versionadded:: 2.0
:param payload: The raw event payload data.
:type payload: :class:`RawAppCommandPermissionsUpdateEvent`
AutoMod AutoMod
~~~~~~~ ~~~~~~~~
.. function:: on_automod_rule_create(rule) .. function:: on_automod_rule_create(rule)
@ -4417,6 +4429,14 @@ RawMemberRemoveEvent
.. autoclass:: RawMemberRemoveEvent() .. autoclass:: RawMemberRemoveEvent()
:members: :members:
RawAppCommandPermissionsUpdateEvent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. attributetable:: RawAppCommandPermissionsUpdateEvent
.. autoclass:: RawAppCommandPermissionsUpdateEvent()
:members:
PartialWebhookGuild PartialWebhookGuild
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

Loading…
Cancel
Save