Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby authored Nov 27, 2023
2 parents 16bf8a9 + ba5a52d commit dc53fbc
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 28 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -19,7 +19,7 @@ repos:
# - --remove-duplicate-keys
# - --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v3.11.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -28,7 +28,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down Expand Up @@ -77,7 +77,7 @@ repos:
# - id: mypy

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v3.1.0
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2156](https://github.com/Pycord-Development/pycord/pull/2156))
- Fixed `ScheduledEvent.creator_id` returning `str` instead of `int`.
([#2162](https://github.com/Pycord-Development/pycord/pull/2162))
- Fixed `_bytes_to_base64_data` not defined.
([#2185](https://github.com/Pycord-Development/pycord/pull/2185))
- Fixed type-hinting of `values` argument of `basic_autocomplete` to include
type-hinting of `Iterable[OptionChoice]`.
([#2164](https://github.com/Pycord-Development/pycord/pull/2164))
Expand All @@ -180,6 +182,10 @@ These changes are available on the `master` branch, but have not yet been releas
([#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))
- Fixed ffmpeg being terminated prematurely when piping audio stream.
([#2240](https://github.com/Pycord-Development/pycord/pull/2240))
- Fixed tasks looping infinitely when `tzinfo` is neither `None` nor UTC.
([#2196](https://github.com/Pycord-Development/pycord/pull/2196))

## [2.4.1] - 2023-03-20

Expand Down
8 changes: 8 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"AutoModActionType",
"AutoModKeywordPresetType",
"ApplicationRoleConnectionMetadataType",
"ReactionType",
)


Expand Down Expand Up @@ -944,6 +945,13 @@ class ApplicationRoleConnectionMetadataType(Enum):
boolean_not_equal = 8


class ReactionType(Enum):
"""The reaction type"""

normal = 0
burst = 1


T = TypeVar("T")


Expand Down
18 changes: 13 additions & 5 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _get_next_sleep_time(self) -> datetime.datetime:
if self._current_loop == 0:
# if we're at the last index on the first iteration, we need to sleep until tomorrow
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(self._time[0].tzinfo or datetime.timezone.utc)
+ datetime.timedelta(days=1),
self._time[0],
)
Expand All @@ -584,18 +584,26 @@ def _get_next_sleep_time(self) -> datetime.datetime:

if self._current_loop == 0:
self._time_index += 1
if next_time > datetime.datetime.now(datetime.timezone.utc).timetz():
if (
next_time
> datetime.datetime.now(
next_time.tzinfo or datetime.timezone.utc
).timetz()
):
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc), next_time
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc),
next_time,
)
else:
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc)
+ datetime.timedelta(days=1),
next_time,
)

next_date = cast(datetime.datetime, self._last_iteration)
next_date = cast(
datetime.datetime, self._last_iteration.astimezone(next_time.tzinfo)
)
if next_time < next_date.timetz():
next_date += datetime.timedelta(days=1)

Expand Down
2 changes: 1 addition & 1 deletion discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,7 @@ async def create_role(
if icon is None:
fields["icon"] = None
else:
fields["icon"] = _bytes_to_base64_data(icon)
fields["icon"] = utils._bytes_to_base64_data(icon)
fields["unicode_emoji"] = None

if unicode_emoji is not MISSING:
Expand Down
3 changes: 3 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ def get_reaction_users(
emoji: str,
limit: int,
after: Snowflake | None = None,
type: int | None = None,
) -> Response[list[user.User]]:
r = Route(
"GET",
Expand All @@ -771,6 +772,8 @@ def get_reaction_users(
}
if after:
params["after"] = after
if type:
params["type"] = type
return self.request(r, params=params)

def clear_reactions(
Expand Down
10 changes: 8 additions & 2 deletions discord/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ async def next(self) -> T:


class ReactionIterator(_AsyncIterator[Union["User", "Member"]]):
def __init__(self, message, emoji, limit=100, after=None):
def __init__(self, message, emoji, limit=100, after=None, type=None):
self.message = message
self.limit = limit
self.after = after
self.type = type
state = message._state
self.getter = state.http.get_reaction_users
self.state = state
Expand All @@ -212,7 +213,12 @@ async def fill_users(self):

after = self.after.id if self.after else None
data: list[PartialUserPayload] = await self.getter(
self.channel_id, self.message.id, self.emoji, retrieve, after=after
self.channel_id,
self.message.id,
self.emoji,
retrieve,
after=after,
type=self.type,
)

if data:
Expand Down
2 changes: 1 addition & 1 deletion discord/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _pipe_writer(self, source: io.BufferedIOBase) -> None:
# arbitrarily large read size
data = source.read(8192)
if not data:
self._process.terminate()
self._stdin.close()
return
try:
self._stdin.write(data)
Expand Down
33 changes: 31 additions & 2 deletions discord/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from typing import TYPE_CHECKING

from .automod import AutoModAction, AutoModTriggerType
from .enums import AuditLogAction, ChannelType, try_enum
from .enums import AuditLogAction, ChannelType, ReactionType, try_enum
from .types.user import User

if TYPE_CHECKING:
Expand Down Expand Up @@ -214,6 +214,15 @@ class RawReactionActionEvent(_RawReprMixin):
``REACTION_REMOVE`` for reaction removal.
.. versionadded:: 1.3
burst: :class:`bool`
Whether this reaction is a burst (super) reaction.
burst_colours: Optional[:class:`list`]
A list of hex codes this reaction can be. Only available if `event_type` is `REACTION_ADD`
and this emoji has super reactions available.
burst_colors: Optional[:class:`list`]
Alias for :attr:`burst_colours`.
type: :class:`ReactionType`
The type of reaction added.
data: :class:`dict`
The raw data sent by the `gateway <https://discord.com/developers/docs/topics/gateway-events#message-reaction-add>`_.
Expand All @@ -226,6 +235,10 @@ class RawReactionActionEvent(_RawReprMixin):
"channel_id",
"guild_id",
"emoji",
"burst",
"burst_colours",
"burst_colors",
"type",
"event_type",
"member",
"data",
Expand All @@ -240,6 +253,10 @@ def __init__(
self.emoji: PartialEmoji = emoji
self.event_type: str = event_type
self.member: Member | None = None
self.burst: bool = data.get("burst")
self.burst_colours: list = data.get("burst_colors", [])
self.burst_colors: list = self.burst_colours
self.type: ReactionType = try_enum(ReactionType, data.get("type", 0))

try:
self.guild_id: int | None = int(data["guild_id"])
Expand Down Expand Up @@ -293,18 +310,30 @@ class RawReactionClearEmojiEvent(_RawReprMixin):
The guild ID where the reactions got cleared.
emoji: :class:`PartialEmoji`
The custom or unicode emoji being removed.
burst: :class:`bool`
Whether this reaction was a burst (super) reaction.
burst_colours: :class:`list`
The available HEX codes of the removed super reaction.
burst_colors: Optional[:class:`list`]
Alias for :attr:`burst_colours`.
type: :class:`ReactionType`
The type of reaction removed.
data: :class:`dict`
The raw data sent by the `gateway <https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-emoji>`_.
.. versionadded:: 2.5
"""

__slots__ = ("message_id", "channel_id", "guild_id", "emoji", "data")
__slots__ = ("message_id", "channel_id", "guild_id", "emoji", "burst", "data")

def __init__(self, data: ReactionClearEmojiEvent, emoji: PartialEmoji) -> None:
self.emoji: PartialEmoji = emoji
self.message_id: int = int(data["message_id"])
self.channel_id: int = int(data["channel_id"])
self.burst: bool = data.get("burst")
self.burst_colours: list = data.get("burst_colors", [])
self.burst_colors: list = self.burst_colours
self.type: ReactionType = try_enum(ReactionType, data.get("type", 0))

try:
self.guild_id: int | None = int(data["guild_id"])
Expand Down
Loading

0 comments on commit dc53fbc

Please sign in to comment.