Skip to content

Commit

Permalink
Merge branch 'master' into ratelimit-prediction
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentRPS authored Nov 1, 2023
2 parents 37039dc + 9e4b3ff commit 2ea1e80
Show file tree
Hide file tree
Showing 23 changed files with 373 additions and 98 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
121 changes: 70 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
77 changes: 64 additions & 13 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ class EmbedMedia: # Thumbnail, Image, Video
height: int | None
width: int | None

def __init__(self, url: str):
self.url = url
self.proxy_url = None
self.height = None
self.width = None

@classmethod
def from_dict(cls, data: dict[str, str | int]) -> EmbedMedia:
self = cls.__new__(cls)
Expand Down Expand Up @@ -355,8 +361,8 @@ def __init__(
fields: list[EmbedField] | None = None,
author: EmbedAuthor | None = None,
footer: EmbedFooter | None = None,
image: str | None = None,
thumbnail: str | None = None,
image: str | EmbedMedia | None = None,
thumbnail: str | EmbedMedia | None = None,
):
self.colour = colour if colour else color
self.title = title
Expand All @@ -378,17 +384,10 @@ def __init__(

self._fields: list[EmbedField] = fields if fields is not None else []

if author:
self.set_author(**author.to_dict())

if footer:
self.set_footer(**footer.to_dict())

if image:
self.set_image(url=image)

if thumbnail:
self.set_thumbnail(url=thumbnail)
self.author = author
self.footer = footer
self.image = image
self.thumbnail = thumbnail

@classmethod
def from_dict(cls: type[E], data: Mapping[str, Any]) -> E:
Expand Down Expand Up @@ -566,6 +565,18 @@ def footer(self) -> EmbedFooter | None:
return None
return EmbedFooter.from_dict(foot)

@footer.setter
def footer(self, value: EmbedFooter | None):
if value is None:
self.remove_footer()
elif isinstance(value, EmbedFooter):
self._footer = value.to_dict()
else:
raise TypeError(
"Expected EmbedFooter or None. Received"
f" {value.__class__.__name__} instead"
)

def set_footer(
self: E,
*,
Expand Down Expand Up @@ -628,6 +639,20 @@ def image(self) -> EmbedMedia | None:
return None
return EmbedMedia.from_dict(img)

@image.setter
def image(self, value: str | EmbedMedia | None):
if value is None:
self.remove_image()
elif isinstance(value, str):
self.set_image(url=value)
elif isinstance(value, EmbedMedia):
self.set_image(url=value.url)
else:
raise TypeError(
"Expected discord.EmbedMedia, or None but received"
f" {value.__class__.__name__} instead."
)

def set_image(self: E, *, url: Any | None) -> E:
"""Sets the image for the embed content.
Expand Down Expand Up @@ -688,6 +713,20 @@ def thumbnail(self) -> EmbedMedia | None:
return None
return EmbedMedia.from_dict(thumb)

@thumbnail.setter
def thumbnail(self, value: str | EmbedMedia | None):
if value is None:
self.remove_thumbnail()
elif isinstance(value, str):
self.set_thumbnail(url=value)
elif isinstance(value, EmbedMedia):
self.set_thumbnail(url=value.url)
else:
raise TypeError(
"Expected discord.EmbedMedia, or None but received"
f" {value.__class__.__name__} instead."
)

def set_thumbnail(self: E, *, url: Any | None) -> E:
"""Sets the thumbnail for the embed content.
Expand Down Expand Up @@ -773,6 +812,18 @@ def author(self) -> EmbedAuthor | None:
return None
return EmbedAuthor.from_dict(auth)

@author.setter
def author(self, value: EmbedAuthor | None):
if value is None:
self.remove_author()
elif isinstance(value, EmbedAuthor):
self._author = value.to_dict()
else:
raise TypeError(
"Expected discord.EmbedAuthor, or None but received"
f" {value.__class__.__name__} instead."
)

def set_author(
self: E,
*,
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 @@ -744,6 +744,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 @@ -758,6 +759,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
Loading

0 comments on commit 2ea1e80

Please sign in to comment.