Skip to content

Commit

Permalink
Merge pull request #26 from Pycord-Development/master
Browse files Browse the repository at this point in the history
[pull] master from Pycord-Development:master
  • Loading branch information
OmLanke authored Aug 29, 2023
2 parents 1b81356 + 402f2bd commit 7073e06
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ These changes are available on the `master` branch, but have not yet been releas
- Added `suppress` and `allowed_mentions` parameters to `Webhook` and
`InteractionResponse` edit methods.
([#2138](https://github.com/Pycord-Development/pycord/pull/2138))
- Added `wait_finish` parameter to `VoiceClient.play` for awaiting the end of a play.
([#2194](https://github.com/Pycord-Development/pycord/pull/2194))
- Added support for custom bot status.
([#2206](https://github.com/Pycord-Development/pycord/pull/2206))
- Added function `Guild.delete_auto_moderation_rule`.
([#2153](https://github.com/Pycord-Development/pycord/pull/2153))

### Changed

Expand Down Expand Up @@ -162,6 +168,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2191](https://github.com/Pycord-Development/pycord/pull/2191))
- Fixed a misplaced payload object inside of the thread creation payload.
([#2192](https://github.com/Pycord-Development/pycord/pull/2192))
- Fixed `DMChannel.recipient` being None and consequently `User.dm_channel` also being
None. ([#2219](https://github.com/Pycord-Development/pycord/pull/2219))

## [2.4.1] - 2023-03-20

Expand Down
11 changes: 8 additions & 3 deletions discord/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Activity(BaseActivity):
type: :class:`ActivityType`
The type of activity currently being done.
state: Optional[:class:`str`]
The user's current state. For example, "In Game".
The user's current party status or text used for a custom status.
details: Optional[:class:`str`]
The detail of the user's current activity.
timestamps: Dict[:class:`str`, :class:`int`]
Expand Down Expand Up @@ -229,7 +229,6 @@ def __init__(self, **kwargs):
self.assets: ActivityAssets = kwargs.pop("assets", {})
self.party: ActivityParty = kwargs.pop("party", {})
self.application_id: int | None = _get_as_snowflake(kwargs, "application_id")
self.name: str | None = kwargs.pop("name", None)
self.url: str | None = kwargs.pop("url", None)
self.flags: int = kwargs.pop("flags", 0)
self.sync_id: str | None = kwargs.pop("sync_id", None)
Expand All @@ -242,6 +241,9 @@ def __init__(self, **kwargs):
if isinstance(activity_type, ActivityType)
else try_enum(ActivityType, activity_type)
)
self.name: str | None = kwargs.pop(
"name", "Custom Status" if self.type == ActivityType.custom else None
)

emoji = kwargs.pop("emoji", None)
self.emoji: PartialEmoji | None = (
Expand All @@ -252,6 +254,7 @@ def __repr__(self) -> str:
attrs = (
("type", self.type),
("name", self.name),
("state", self.state),
("url", self.url),
("details", self.details),
("application_id", self.application_id),
Expand Down Expand Up @@ -760,6 +763,8 @@ class CustomActivity(BaseActivity):
The custom activity's name.
emoji: Optional[:class:`PartialEmoji`]
The emoji to pass to the activity, if any.
state: Optional[:class:`str`]
The text used for the custom activity.
"""

__slots__ = ("name", "emoji", "state")
Expand All @@ -769,7 +774,7 @@ def __init__(
):
super().__init__(**extra)
self.name: str | None = name
self.state: str | None = extra.pop("state", None)
self.state: str | None = extra.pop("state", name)
if self.name == "Custom Status":
self.name = self.state

Expand Down
2 changes: 1 addition & 1 deletion discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,7 @@ def __init__(
self._state: ConnectionState = state
self.recipient: User | None = None
if r := data.get("recipients"):
self.recipient: state.store_user(r[0])
self.recipient = state.store_user(r[0])
self.me: ClientUser = me
self.id: int = int(data["id"])

Expand Down
26 changes: 26 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -3816,3 +3816,29 @@ async def create_auto_moderation_rule(
self.id, payload, reason=reason
)
return AutoModRule(state=self._state, data=data)

async def delete_auto_moderation_rule(
self,
id: int,
*,
reason: str | None = None,
) -> None:
"""
Deletes an auto moderation rule.
Parameters
----------
id: :class:`int`
The ID of the auto moderation rule.
reason: Optional[:class:`str`]
The reason for deleting the rule. Shows up in the audit log.
Raises
------
HTTPException
Deleting the auto moderation rule failed.
Forbidden
You do not have the Manage Guild permission.
"""

await self._state.http.delete_auto_moderation_rule(self.id, id, reason=reason)
28 changes: 27 additions & 1 deletion discord/voice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,11 @@ def get_ssrc(self, user_id):
]

def play(
self, source: AudioSource, *, after: Callable[[Exception | None], Any] = None
self,
source: AudioSource,
*,
after: Callable[[Exception | None], Any] = None,
wait_finish: bool = False,
) -> None:
"""Plays an :class:`AudioSource`.
Expand All @@ -643,6 +647,14 @@ def play(
The finalizer that is called after the stream is exhausted.
This function must have a single parameter, ``error``, that
denotes an optional exception that was raised during playing.
wait_finish: bool
If True, an awaitable will be returned, which can be used to wait for
audio to stop playing. This awaitable will return an exception if raised,
or None when no exception is raised.
If False, None is returned and the function does not block.
.. versionadded:: v2.5
Raises
------
Expand All @@ -668,8 +680,22 @@ def play(
if not self.encoder and not source.is_opus():
self.encoder = opus.Encoder()

future = None
if wait_finish:
future = asyncio.Future()
after_callback = after

def _after(exc: Exception | None):
if callable(after_callback):
after_callback(exc)

future.set_result(exc)

after = _after

self._player = AudioPlayer(source, self, after=after)
self._player.start()
return future

def unpack_audio(self, data):
"""Takes an audio packet received from Discord and decodes it into pcm audio data.
Expand Down

0 comments on commit 7073e06

Please sign in to comment.