Skip to content

Commit 7c81d85

Browse files
authored
Merge branch 'master' into soundboard
2 parents def647e + 975a0d9 commit 7c81d85

File tree

513 files changed

+51312
-12397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

513 files changed

+51312
-12397
lines changed

.github/workflows/docs-localization-download.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
working-directory: ./docs
4141
- name: "Crowdin"
4242
id: crowdin
43-
uses: crowdin/[email protected].0
43+
uses: crowdin/[email protected].1
4444
with:
4545
upload_sources: false
4646
upload_translations: false

.github/workflows/docs-localization-upload.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
sphinx-intl update -p ./build/locales ${{ vars.SPHINX_LANGUAGES }}
4545
working-directory: ./docs
4646
- name: "Crowdin"
47-
uses: crowdin/[email protected].0
47+
uses: crowdin/[email protected].1
4848
with:
4949
upload_sources: true
5050
upload_translations: false

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,20 @@ These changes are available on the `master` branch, but have not yet been releas
6060
([#2564](https://github.com/Pycord-Development/pycord/pull/2564))
6161
- Added `Message.forward_to`, `Message.snapshots`, and other related attributes.
6262
([#2598](https://github.com/Pycord-Development/pycord/pull/2598))
63+
- Add missing `Guild` feature flags and `Guild.edit` parameters.
64+
([#2672](https://github.com/Pycord-Development/pycord/pull/2672))
6365
- Added the ability to change the API's base URL with `Route.API_BASE_URL`.
6466
([#2714](https://github.com/Pycord-Development/pycord/pull/2714))
6567
- Added the ability to pass a `datetime.time` object to `format_dt`.
6668
([#2747](https://github.com/Pycord-Development/pycord/pull/2747))
69+
- Added support for type hinting slash command options with `typing.Annotated`.
70+
([#2782](https://github.com/Pycord-Development/pycord/pull/2782))
71+
- Added conversion to `Member` in `MentionableConverter`.
72+
([#2775](https://github.com/Pycord-Development/pycord/pull/2775))
6773
- Added `discord.Interaction.created_at`.
6874
([#2801](https://github.com/Pycord-Development/pycord/pull/2801))
75+
- Added role gradients support with `Role.colours` and the `RoleColours` class.
76+
([#2818](https://github.com/Pycord-Development/pycord/pull/2818))
6977

7078
### Fixed
7179

@@ -130,6 +138,10 @@ These changes are available on the `master` branch, but have not yet been releas
130138
([#2800](https://github.com/Pycord-Development/pycord/pull/2800))
131139
- Fixed `VoiceClient.connect` failing to do initial connection.
132140
([#2812](https://github.com/Pycord-Development/pycord/pull/2812))
141+
- Fixed `AttributeError` when printing a File component's `__repr__`.
142+
([#2843](https://github.com/Pycord-Development/pycord/pull/2843))
143+
- Fixed `TypeError` when using `@option` with certain annotations and along with
144+
`channel_types`. ([#2835](https://github.com/Pycord-Development/pycord/pull/2835))
133145

134146
### Changed
135147

crowdin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ preserve_hierarchy: true
55

66
commit_message: "docs: Update translations"
77

8-
export_languages: ["de", "ja", "fr", "it", "hi", "ko", "pt-BR", "es-ES", "zh-CN"]
8+
export_languages: ["de", "ja", "fr", "it", "hi", "ko", "pt-BR", "es-ES", "zh-CN", "tr"]
99

1010
bundles:
1111
- 1

discord/asset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ class Asset(AssetMixin):
144144
145145
.. describe:: hash(x)
146146
147-
Returns the hash of the asset.
147+
Returns the asset's url's hash.
148+
149+
This is equivalent to hash(:attr:`url`).
148150
"""
149151

150152
__slots__: tuple[str, ...] = (

discord/commands/core.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
from .options import Option, OptionChoice
7474

7575
if sys.version_info >= (3, 11):
76-
from typing import Annotated, get_args, get_origin
76+
from typing import Annotated, Literal, get_args, get_origin
7777
else:
78-
from typing_extensions import Annotated, get_args, get_origin
78+
from typing_extensions import Annotated, Literal, get_args, get_origin
7979

8080
__all__ = (
8181
"_BaseCommand",
@@ -806,6 +806,26 @@ def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
806806
if option == inspect.Parameter.empty:
807807
option = str
808808

809+
if self._is_typing_literal(option):
810+
literal_values = get_args(option)
811+
if not all(isinstance(v, (str, int, float)) for v in literal_values):
812+
raise TypeError(
813+
"Literal values for choices must be str, int, or float."
814+
)
815+
816+
value_type = type(literal_values[0])
817+
if not all(isinstance(v, value_type) for v in literal_values):
818+
raise TypeError(
819+
"All Literal values for choices must be of the same type."
820+
)
821+
822+
option = Option(
823+
value_type,
824+
choices=[
825+
OptionChoice(name=str(v), value=v) for v in literal_values
826+
],
827+
)
828+
809829
if self._is_typing_annotated(option):
810830
type_hint = get_args(option)[0]
811831
metadata = option.__metadata__
@@ -908,6 +928,9 @@ def _is_typing_union(self, annotation):
908928
def _is_typing_optional(self, annotation):
909929
return self._is_typing_union(annotation) and type(None) in annotation.__args__ # type: ignore
910930

931+
def _is_typing_literal(self, annotation):
932+
return get_origin(annotation) is Literal
933+
911934
def _is_typing_annotated(self, annotation):
912935
return get_origin(annotation) is Annotated
913936

discord/commands/options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ def __init__(
225225
self.description = description or "No description provided"
226226
self.channel_types: list[ChannelType] = kwargs.pop("channel_types", [])
227227

228-
if isinstance(input_type, SlashCommandOptionType):
228+
if self.channel_types:
229+
self.input_type = SlashCommandOptionType.channel
230+
elif isinstance(input_type, SlashCommandOptionType):
229231
self.input_type = input_type
230232
else:
231233
from ..ext.commands import Converter

discord/components.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,18 +670,36 @@ class UnfurledMediaItem(AssetMixin):
670670
def __init__(self, url: str):
671671
self._state = None
672672
self._url: str = url
673+
self._static_url: str | None = (
674+
url if url and url.startswith("attachment://") else None
675+
)
673676
self.proxy_url: str | None = None
674677
self.height: int | None = None
675678
self.width: int | None = None
676679
self.content_type: str | None = None
677680
self.flags: AttachmentFlags | None = None
678681
self.attachment_id: int | None = None
679682

683+
def __repr__(self) -> str:
684+
return (
685+
f"<UnfurledMediaItem url={self.url!r} attachment_id={self.attachment_id}>"
686+
)
687+
688+
def __str__(self) -> str:
689+
return self.url or self.__repr__()
690+
680691
@property
681692
def url(self) -> str:
682693
"""Returns this media item's url."""
683694
return self._url
684695

696+
@url.setter
697+
def url(self, value: str) -> None:
698+
self._url = value
699+
self._static_url = (
700+
value if value and value.startswith("attachment://") else None
701+
)
702+
685703
@classmethod
686704
def from_dict(cls, data: UnfurledMediaItemPayload, state=None) -> UnfurledMediaItem:
687705

@@ -696,7 +714,7 @@ def from_dict(cls, data: UnfurledMediaItemPayload, state=None) -> UnfurledMediaI
696714
return r
697715

698716
def to_dict(self) -> dict[str, str]:
699-
return {"url": self.url}
717+
return {"url": self._static_url or self.url}
700718

701719

702720
class Thumbnail(Component):

discord/ext/bridge/core.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
Converter,
5252
Group,
5353
GuildChannelConverter,
54+
MemberConverter,
5455
RoleConverter,
5556
UserConverter,
5657
)
@@ -566,13 +567,21 @@ def predicate(func: Callable | ApplicationCommand):
566567

567568

568569
class MentionableConverter(Converter):
569-
"""A converter that can convert a mention to a user or a role."""
570+
"""A converter that can convert a mention to a member, a user or a role."""
570571

571572
async def convert(self, ctx, argument):
572573
try:
573574
return await RoleConverter().convert(ctx, argument)
574575
except BadArgument:
575-
return await UserConverter().convert(ctx, argument)
576+
pass
577+
578+
if ctx.guild:
579+
try:
580+
return await MemberConverter().convert(ctx, argument)
581+
except BadArgument:
582+
pass
583+
584+
return await UserConverter().convert(ctx, argument)
576585

577586

578587
class AttachmentConverter(Converter):
@@ -600,6 +609,7 @@ async def convert(self, ctx, arg: bool):
600609
SlashCommandOptionType.mentionable: MentionableConverter,
601610
SlashCommandOptionType.number: float,
602611
SlashCommandOptionType.attachment: AttachmentConverter,
612+
discord.Member: MemberConverter,
603613
}
604614

605615

@@ -608,16 +618,24 @@ class BridgeOption(Option, Converter):
608618
command option and a prefixed command argument for bridge commands.
609619
"""
610620

621+
def __init__(self, input_type, *args, **kwargs):
622+
self.converter = kwargs.pop("converter", None)
623+
super().__init__(input_type, *args, **kwargs)
624+
625+
self.converter = self.converter or BRIDGE_CONVERTER_MAPPING.get(input_type)
626+
611627
async def convert(self, ctx, argument: str) -> Any:
612628
try:
613629
if self.converter is not None:
614-
converted = await self.converter.convert(ctx, argument)
630+
converted = await self.converter().convert(ctx, argument)
615631
else:
616-
converter = BRIDGE_CONVERTER_MAPPING[self.input_type]
617-
if issubclass(converter, Converter):
632+
converter = BRIDGE_CONVERTER_MAPPING.get(self.input_type)
633+
if isinstance(converter, type) and issubclass(converter, Converter):
618634
converted = await converter().convert(ctx, argument) # type: ignore # protocol class
619-
else:
635+
elif callable(converter):
620636
converted = converter(argument)
637+
else:
638+
raise TypeError(f"Invalid converter: {converter}")
621639

622640
if self.choices:
623641
choices_names: list[str | int | float] = [

0 commit comments

Comments
 (0)