Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
Signed-off-by: Middledot <78228142+Middledot@users.noreply.github.com>
  • Loading branch information
Middledot authored Oct 30, 2023
2 parents 5d3f0b9 + 6888b90 commit b460602
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 100 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/tdg-github-action@v0.4.7-beta
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
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
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)
29 changes: 17 additions & 12 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,37 +1183,42 @@ def start_forum_thread(
"auto_archive_duration": auto_archive_duration,
"invitable": invitable,
}
if content:
payload["content"] = content

if applied_tags:
payload["applied_tags"] = applied_tags

if rate_limit_per_user:
payload["rate_limit_per_user"] = rate_limit_per_user

message = {}

if content:
message["content"] = content

if embed:
payload["embeds"] = [embed]
message["embeds"] = [embed]

if embeds:
payload["embeds"] = embeds
message["embeds"] = embeds

if nonce:
payload["nonce"] = nonce
message["nonce"] = nonce

if allowed_mentions:
payload["allowed_mentions"] = allowed_mentions
message["allowed_mentions"] = allowed_mentions

if components:
payload["components"] = components
message["components"] = components

if stickers:
payload["sticker_ids"] = stickers
message["sticker_ids"] = stickers

if rate_limit_per_user:
payload["rate_limit_per_user"] = rate_limit_per_user
if message != {}:
payload["message"] = message

# TODO: Once supported by API, remove has_message=true query parameter
route = Route(
"POST",
"/channels/{channel_id}/threads?has_message=true",
"/channels/{channel_id}/threads",
channel_id=channel_id,
)

Expand Down
Loading

0 comments on commit b460602

Please sign in to comment.