Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement voice channel status permission and event #1206

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ async def set_permissions(
send_messages_in_threads: Optional[bool] = ...,
send_tts_messages: Optional[bool] = ...,
send_voice_messages: Optional[bool] = ...,
set_voice_channel_status: Optional[bool] = ...,
speak: Optional[bool] = ...,
start_embedded_activities: Optional[bool] = ...,
stream: Optional[bool] = ...,
Expand Down
4 changes: 4 additions & 0 deletions disnake/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,10 @@ class Event(Enum):
"""Called when a `Member` changes their `VoiceState`.
Represents the :func:`on_voice_state_update` event.
"""
voice_channel_status_update = "voice_channel_status_update"
"""Called when a voice channel status is updated.
Represents the :func:`on_voice_channel_status_update` event.
"""
stage_instance_create = "stage_instance_create"
"""Called when a `StageInstance` is created for a `StageChannel`.
Represents the :func:`on_stage_instance_create` event.
Expand Down
1 change: 1 addition & 0 deletions disnake/ext/commands/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ def default_member_permissions(
send_messages_in_threads: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
set_voice_channel_status: bool = ...,
speak: bool = ...,
start_embedded_activities: bool = ...,
stream: bool = ...,
Expand Down
4 changes: 4 additions & 0 deletions disnake/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ def has_permissions(
send_messages_in_threads: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
set_voice_channel_status: bool = ...,
speak: bool = ...,
start_embedded_activities: bool = ...,
stream: bool = ...,
Expand Down Expand Up @@ -2158,6 +2159,7 @@ def bot_has_permissions(
send_messages_in_threads: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
set_voice_channel_status: bool = ...,
speak: bool = ...,
start_embedded_activities: bool = ...,
stream: bool = ...,
Expand Down Expand Up @@ -2260,6 +2262,7 @@ def has_guild_permissions(
send_messages_in_threads: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
set_voice_channel_status: bool = ...,
speak: bool = ...,
start_embedded_activities: bool = ...,
stream: bool = ...,
Expand Down Expand Up @@ -2359,6 +2362,7 @@ def bot_has_guild_permissions(
send_messages_in_threads: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
set_voice_channel_status: bool = ...,
speak: bool = ...,
start_embedded_activities: bool = ...,
stream: bool = ...,
Expand Down
13 changes: 13 additions & 0 deletions disnake/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def __init__(
send_messages_in_threads: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
set_voice_channel_status: bool = ...,
speak: bool = ...,
start_embedded_activities: bool = ...,
stream: bool = ...,
Expand Down Expand Up @@ -582,6 +583,7 @@ def update(
send_messages_in_threads: bool = ...,
send_tts_messages: bool = ...,
send_voice_messages: bool = ...,
set_voice_channel_status: bool = ...,
speak: bool = ...,
start_embedded_activities: bool = ...,
stream: bool = ...,
Expand Down Expand Up @@ -1038,6 +1040,14 @@ def send_voice_messages(self) -> int:
"""
return 1 << 46

@flag_value
def set_voice_channel_status(self) -> int:
""":class:`bool`: Returns ``True`` if a user can set voice channel statuses.

.. versionadded:: 2.10
"""
return 1 << 48


def _augment_from_permissions(cls):
cls.VALID_NAMES = set(Permissions.VALID_FLAGS)
Expand Down Expand Up @@ -1145,6 +1155,7 @@ class PermissionOverwrite:
send_messages_in_threads: Optional[bool]
send_tts_messages: Optional[bool]
send_voice_messages: Optional[bool]
set_voice_channel_status: Optional[bool]
speak: Optional[bool]
start_embedded_activities: Optional[bool]
stream: Optional[bool]
Expand Down Expand Up @@ -1211,6 +1222,7 @@ def __init__(
send_messages_in_threads: Optional[bool] = ...,
send_tts_messages: Optional[bool] = ...,
send_voice_messages: Optional[bool] = ...,
set_voice_channel_status: Optional[bool] = ...,
speak: Optional[bool] = ...,
start_embedded_activities: Optional[bool] = ...,
stream: Optional[bool] = ...,
Expand Down Expand Up @@ -1344,6 +1356,7 @@ def update(
send_messages_in_threads: Optional[bool] = ...,
send_tts_messages: Optional[bool] = ...,
send_voice_messages: Optional[bool] = ...,
set_voice_channel_status: Optional[bool] = ...,
speak: Optional[bool] = ...,
start_embedded_activities: Optional[bool] = ...,
stream: Optional[bool] = ...,
Expand Down
21 changes: 21 additions & 0 deletions disnake/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,27 @@ def parse_voice_server_update(self, data: gateway.VoiceServerUpdateEvent) -> Non
logging_coroutine(coro, info="Voice Protocol voice server update handler")
)

def parse_voice_channel_status_update(self, data: gateway.VoiceChannelStatusUpdate) -> None:
guild_id = int(data["guild_id"])
guild = self._get_guild(guild_id)

if guild is None:
_log.debug(
"VOICE_CHANNEL_STATUS_UPDATE referencing an unknown guild ID: %s. Discarding",
guild_id,
)
return

channel_id = int(data["id"])
channel = guild.get_channel(channel_id)
if channel is None:
_log.debug(
"VOICE_CHANNEL_STATUS_UPDATE referencing an unknown channel ID: %s. Discarding",
channel_id,
)

self.dispatch("voice_channel_status_update", channel, data["status"])

# FIXME: this should be refactored. The `GroupChannel` path will never be hit,
# `raw.timestamp` exists so no need to parse it twice, and `.get_user` should be used before falling back
def parse_typing_start(self, data: gateway.TypingStartEvent) -> None:
Expand Down
7 changes: 7 additions & 0 deletions disnake/types/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,10 @@ class AutoModerationActionExecutionEvent(TypedDict):

# https://discord.com/developers/docs/monetization/entitlements#deleted-entitlement
EntitlementDelete = Entitlement


# https://discord.com/developers/docs/topics/gateway-events#voice-channel-status-update
class VoiceChannelStatusUpdate(TypedDict):
id: Snowflake
guild_id: Snowflake
status: Optional[str]
6 changes: 6 additions & 0 deletions docs/api/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ This section documents events related to Discord channels and threads.
:param channel: The channel that had its webhooks updated.
:type channel: :class:`abc.GuildChannel`

.. function:: on_voice_channel_status_update(channel, status)

Called whenever a channel status is modified.

This requires :attr:`Intents.` to be enabled.

Guilds
~~~~~~

Expand Down
Loading