Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
Signed-off-by: Dorukyum <[email protected]>
  • Loading branch information
Dorukyum authored Nov 26, 2023
2 parents 58e0179 + f6ac778 commit 8538f9b
Show file tree
Hide file tree
Showing 24 changed files with 287 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
Expand All @@ -25,7 +25,7 @@ jobs:
bandit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3.1.0
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
Expand All @@ -31,7 +31,7 @@ jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -48,7 +48,7 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
todo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Run tdg-github-action
uses: ribtoks/[email protected]
with:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.0
rev: v2.2.1
hooks:
- id: autoflake
# args:
Expand All @@ -19,7 +19,7 @@ repos:
# - --remove-duplicate-keys
# - --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.13.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.7.0
rev: 23.9.1
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.0
rev: v3.0.3
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
Expand Down
123 changes: 72 additions & 51 deletions CHANGELOG.md

Large diffs are not rendered by default.

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
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
28 changes: 27 additions & 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 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)
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 8538f9b

Please sign in to comment.