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 statuses #2368

Merged
merged 34 commits into from Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ac6ba7c
feat: implement coice channel statuses
Icebluewolf Feb 28, 2024
d4686fe
chore: changelog
Icebluewolf Feb 28, 2024
fb6b607
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
1060693
chore: changelog
Icebluewolf Feb 28, 2024
3207c21
chore: Apply suggestions from code review
Icebluewolf Feb 28, 2024
65c8ef2
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
5e4fe99
fix: payload
Lulalaby Feb 28, 2024
a09470d
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
3d88511
feat: raw_voice_channel_status_update
Lulalaby Feb 28, 2024
35ad8c8
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
fa87ec0
fuck me
Lulalaby Feb 28, 2024
d43119f
Merge branch 'master' of github.com:Icebluewolf/pycord into pr/2368
Lulalaby Feb 28, 2024
f3a4bf9
REEEEEEE
Lulalaby Feb 28, 2024
2f438e2
feat: implement coice channel statuses
Icebluewolf Feb 28, 2024
786d861
chore: changelog
Icebluewolf Feb 28, 2024
b5ba2b9
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
549fa56
chore: Apply suggestions from code review
Icebluewolf Feb 28, 2024
8d86cb6
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
fa7894f
fix: payload
Lulalaby Feb 28, 2024
7972c8e
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
5c85b07
feat: raw_voice_channel_status_update
Lulalaby Feb 28, 2024
2251855
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
07ba832
fuck me
Lulalaby Feb 28, 2024
17ae14b
REEEEEEE
Lulalaby Feb 28, 2024
e1107cd
Merge branch 'master' of github.com:Icebluewolf/pycord into pr/2368
Lulalaby Feb 28, 2024
c165c80
intent for this is unknown atm
Lulalaby Feb 28, 2024
0bed18d
fix: abc.GuildChannel
Lulalaby Feb 28, 2024
e3943a6
fix: versionadded
Lulalaby Feb 28, 2024
14c304b
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2024
41bb87b
bleh
Lulalaby Feb 28, 2024
4858424
docs: update docstring
Dorukyum Feb 28, 2024
7e7f942
Merge branch 'master' of https://github.com/Icebluewolf/pycord
Icebluewolf Feb 28, 2024
8a3d10b
docs: Use conventional event args
Icebluewolf Feb 28, 2024
23bddc8
docs: Use conventional event args again
Icebluewolf Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -93,6 +93,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2342](https://github.com/Pycord-Development/pycord/pull/2342))
- Added `invitable` and `slowmode_delay` to `Thread` creation methods.
([#2350](https://github.com/Pycord-Development/pycord/pull/2350))
- Added support for voice channel statuses
Icebluewolf marked this conversation as resolved.
Show resolved Hide resolved
([#2368](https://github.com/Pycord-Development/pycord/pull/2368))

### Changed

Expand Down
40 changes: 40 additions & 0 deletions discord/channel.py
Expand Up @@ -1522,17 +1522,32 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
.. versionadded:: 2.5
flags: :class:`ChannelFlags`
Extra features of the channel.
status: Optional[:class:`str`]
The channel's status, if set.

.. versionadded:: 2.0
"""

def __init__(
self,
*,
state: ConnectionState,
guild: Guild,
data: VoiceChannelPayload,
):
self.status: str | None = None
super().__init__(state=state, guild=guild, data=data)

def _update(self, guild: Guild, data: VoiceChannelPayload):
super()._update(guild, data)
if data.get("status"):
self.status = data.get("status")

def __repr__(self) -> str:
attrs = [
("id", self.id),
("name", self.name),
("status", self.status),
("rtc_region", self.rtc_region),
("position", self.position),
("bitrate", self.bitrate),
Expand Down Expand Up @@ -1955,6 +1970,31 @@ async def create_activity_invite(
**kwargs,
)

async def set_status(self, status: str | None, *, reason=None) -> None:
Icebluewolf marked this conversation as resolved.
Show resolved Hide resolved
"""|coro|

Sets the status of the voice channel.

You must have the :attr:`~Permissions.set_voice_channel_status` permission to use this.

Parameters
----------
status: Union[:class:`str`, None]
The new status.
reason: Optional[:class:`str`]
The reason for setting the status. Shows up on the audit log.

Raises
------
Forbidden
You do not have proper permissions to set the status.
HTTPException
Setting the status failed.
"""
await self._state.http.set_voice_channel_status(
self.id, {"status": status}, reason=reason
)


class StageChannel(discord.abc.Messageable, VocalGuildChannel):
"""Represents a Discord guild stage channel.
Expand Down
6 changes: 6 additions & 0 deletions discord/http.py
Expand Up @@ -2185,6 +2185,12 @@ def move_member(
guild_id=guild_id, user_id=user_id, channel_id=channel_id, reason=reason
)

def set_voice_channel_status(
self, channel_id: Snowflake, payload: Any, *, reason: str | None = None
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
) -> Response[None]:
r = Route("PUT", "/channels/{channel_id}/voice-status", channel_id=channel_id)
return self.request(r, json=payload, reason=reason)

# Stage instance management

def get_stage_instance(
Expand Down
13 changes: 11 additions & 2 deletions discord/permissions.py
Expand Up @@ -180,7 +180,7 @@ def all(cls: type[P]) -> P:
"""A factory method that creates a :class:`Permissions` with all
permissions set to ``True``.
"""
return cls(0b11111111111111111111111111111111111111111)
return cls(0b1111111111111111111111111111111111111111111111111)

@classmethod
def all_channel(cls: type[P]) -> P:
Expand Down Expand Up @@ -250,7 +250,7 @@ def voice(cls: type[P]) -> P:
"""A factory method that creates a :class:`Permissions` with all
"Voice" permissions from the official Discord UI set to ``True``.
"""
return cls(0b00000011111100000000001100000000)
return cls(0b1000000001000000000000011111100000000001100000000)

@classmethod
def stage(cls: type[P]) -> P:
Expand Down Expand Up @@ -618,6 +618,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 member can set voice channel status.

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


PO = TypeVar("PO", bound="PermissionOverwrite")

Expand Down Expand Up @@ -736,6 +744,7 @@ class PermissionOverwrite:
start_embedded_activities: bool | None
moderate_members: bool | None
send_voice_messages: bool | None
set_voice_channel_status: bool | None

def __init__(self, **kwargs: bool | None):
self._values: dict[str, bool | None] = {}
Expand Down
22 changes: 22 additions & 0 deletions discord/state.py
Expand Up @@ -1785,6 +1785,28 @@ def parse_voice_server_update(self, data) -> None:
)
)

def parse_voice_channel_status_update(self, data) -> None:
guild = self._get_guild(int(data["guild_id"]))
channel_id = int(data["id"])
if guild is not None:
channel = guild.get_channel(channel_id)
if channel is not None:
old_status = channel.status
channel.status = data.get("status", None)
self.dispatch(
"voice_channel_status_update", channel, old_status, channel.status
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
)
else:
_log.debug(
"VOICE_CHANNEL_STATUS_UPDATE referencing an unknown channel ID: %s. Discarding.",
channel_id,
)
else:
_log.debug(
"VOICE_CHANNEL_STATUS_UPDATE referencing unknown guild ID: %s. Discarding.",
data["guild_id"],
)

def parse_typing_start(self, data) -> None:
raw = RawTypingEvent(data)

Expand Down
1 change: 1 addition & 0 deletions discord/types/channel.py
Expand Up @@ -108,6 +108,7 @@ class NewsChannel(_BaseGuildChannel, _TextChannelOptional):
class VoiceChannel(_BaseGuildChannel):
rtc_region: NotRequired[str | None]
video_quality_mode: NotRequired[VideoQualityMode]
status: NotRequired[str | None]
type: Literal[2]
bitrate: int
user_limit: int
Expand Down