Skip to content

Commit b113113

Browse files
committed
Merge branch 'master' into state-rewrite
2 parents 22a8232 + 5db5b8e commit b113113

Some content is hidden

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

81 files changed

+432
-447
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* @Pycord-Development/pycord-next-contributors
1+
* @Pycord-Development/pycord-next-contributors
22

33
/.github @Lulalaby
44
/crowdin.yml @Pycord-Development/maintain-translations

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
- id: end-of-file-fixer
1111
exclude: \.(po|pot|yml|yaml)$
1212
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.12.11
13+
rev: v0.13.0
1414
hooks:
1515
- id: ruff
1616
args: [ --fix ]

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
⚠️ This is a testing repository, and should not be used in production.
1+
⚠️ This is a testing repository, and should not be used in production ⚠️
22

33
Please use the main repository: https://github.com/Pycord-Development/pycord
44

discord/__version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636
from typing import Literal, NamedTuple
3737

38-
from .utils.private import deprecated
3938
from ._version import __version__, __version_tuple__
39+
from .utils.private import deprecated
4040

4141

4242
class AdvancedVersionInfo(TypedDict):

discord/abc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
runtime_checkable,
4242
)
4343

44-
from .utils.private import warn_deprecated
4544
from . import utils
4645
from .context_managers import Typing
4746
from .enums import ChannelType
@@ -56,6 +55,7 @@
5655
from .role import Role
5756
from .scheduled_events import ScheduledEvent
5857
from .sticker import GuildSticker, StickerItem
58+
from .utils.private import warn_deprecated
5959
from .voice_client import VoiceClient, VoiceProtocol
6060

6161
__all__ = (
@@ -99,9 +99,9 @@
9999
from .ui.view import View
100100
from .user import ClientUser
101101

102-
PartialMessageableChannel = Union[TextChannel, VoiceChannel, StageChannel, Thread, DMChannel, PartialMessageable]
103-
MessageableChannel = Union[PartialMessageableChannel, GroupChannel]
104-
SnowflakeTime = Union["Snowflake", datetime]
102+
PartialMessageableChannel = TextChannel | VoiceChannel | StageChannel | Thread | DMChannel | PartialMessageable
103+
MessageableChannel = PartialMessageableChannel | GroupChannel
104+
SnowflakeTime = "Snowflake" | datetime
105105

106106
MISSING = utils.MISSING
107107

@@ -911,8 +911,8 @@ async def set_permissions(self, target, *, overwrite=MISSING, reason=None, **per
911911
raise InvalidArgument("No overwrite provided.")
912912
try:
913913
overwrite = PermissionOverwrite(**permissions)
914-
except (ValueError, TypeError):
915-
raise InvalidArgument("Invalid permissions given to keyword arguments.")
914+
except (ValueError, TypeError) as e:
915+
raise InvalidArgument("Invalid permissions given to keyword arguments.") from e
916916
elif len(permissions) > 0:
917917
raise InvalidArgument("Cannot mix overwrite and keyword arguments.")
918918

@@ -1752,8 +1752,8 @@ def can_send(self, *objects) -> bool:
17521752
if obj.guild_id == channel.guild.id:
17531753
continue
17541754

1755-
except (KeyError, AttributeError):
1756-
raise TypeError(f"The object {obj} is of an invalid type.")
1755+
except (KeyError, AttributeError) as e:
1756+
raise TypeError(f"The object {obj} is of an invalid type.") from e
17571757

17581758
if not getattr(channel.permissions_for(channel.guild.me), permission):
17591759
return False

discord/activity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def __repr__(self) -> str:
805805
return f"<CustomActivity name={self.name!r} emoji={self.emoji!r}>"
806806

807807

808-
ActivityTypes = Union[Activity, Game, CustomActivity, Streaming, Spotify]
808+
ActivityTypes = Activity | Game | CustomActivity | Streaming | Spotify
809809

810810

811811
@overload

discord/appinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
from typing import TYPE_CHECKING
2929

30-
from .utils.private import warn_deprecated, get_as_snowflake
3130
from . import utils
3231
from .asset import Asset
3332
from .permissions import Permissions
33+
from .utils.private import get_as_snowflake, warn_deprecated
3434

3535
if TYPE_CHECKING:
3636
from .guild import Guild

discord/banner.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11

22

3-
${bold_white} ${reset} ${blue} ````'````````````````````````'`
4-
${bold_white} ${reset} ${bold_blue} `. `-
5-
${bold_white} O88888${reset} ${yellow}'' _
6-
${bold_white}u@@@@@@@@@@@BG! O@@@@8${reset} ${bold_yellow}_ ${reset}${bold_white}:oQ@@@@@@#Rr${reset}${bold_yellow} `-
7-
${bold_white}u@@@@@@@@@@@@@@O. O@@@@8${reset} ${red}- ${reset}${bold_white}k@@@@#dWQ@@@@D`${reset}${red} .
8-
${bold_white}u@@@@@` 'I@@@@@a`O9999r V6996u ,LaEQQQDUv. :}P$QQ8OI?. V9999L_H8Qc !y0QQRY.O@@@@8${reset} ${bold_red}- ${reset}${bold_white}Vkkk} E@@@@:${reset}${bold_red} .
9-
${bold_white}u@@@@@` :@@@@@R I@@@@Q` ^@@@@@" -M@@@@@@@@@@@q ,Q@@@@@@@@@@@V` O@@@@Q#@@@G-0@@@@@@@##@@@@8${reset} ${purple}- ${reset}${bold_white}-m3HQ@@@0r${reset}${purple} .
10-
${bold_white}u@@@@@}iYz#@@@@@) `$@@@@} O@@@@j -B@@@@Q \@@@T ,#@@@@K_`=#@@@@q O@@@@@8]*);E@@@@@V::V@@@@@8${reset} ${bold_purple}- ${reset}${bold_white}:@@@@@#$z;${reset}${bold_purple} .
11-
${bold_white}u@@@@@@@@@@@@@O! ,#@@@B.*@@@@0` L@@@@@ T@@@@@` y@@@@@: O@@@@Q` @@@@@H G@@@@8${reset} ${black}- ${reset}${bold_white}```=D@@@@P${reset}${black} .
12-
${bold_white}u@@@@@6OOOMj]! x@@@@}9@@@#! x@@@@@ }@@@@@. U@@@@@, O@@@@$ #@@@@b d@@@@8${reset} ${bold_black}- ${reset}${bold_white},####0~` :6@@@@8${reset}${bold_black} .
13-
${bold_white}u@@@@@` K@@@#@@@@x `0@@@@# /@@| .Q@@@@0r~Y@@@@@w O@@@@$ P@@@@@OxxO@@@@@8${reset} ${blue}- ${reset}${bold_white}c#@@@@@@@@@@@Q=${reset}${blue} .
14-
${bold_white}u@@@@@` `#@@@@@@g `c@@@@@@@@@@#T `M@@@@@@@@@@#) O@@@@$ `z@@@@@@@QQ@@@@8${reset} ${bold_blue}_ ${reset}${bold_white}`rz0QBBB8bV:${reset}${bold_blue} `-
15-
${bold_white}=yyyyV x@@@@@#: `~YI5MWIx! `^}m5MGwx: |yyyyv `*w33y~ )yyyyx${reset} ${yellow}.` -
16-
${bold_white}=gEB@@@@#r ${reset} ${bold_yellow} '. .`
17-
${bold_white}`g@@@@@#X_ ${reset} ${blue} '`````'''''''''''''''''''````'`
3+
${bold_white} ${reset}
4+
${bold_white} ${reset}
5+
${bold_white} O88888${reset}
6+
${bold_white}u@@@@@@@@@@@BG! O@@@@8${reset}
7+
${bold_white}u@@@@@@@@@@@@@@O. O@@@@8${reset}
8+
${bold_white}u@@@@@` 'I@@@@@a`O9999r V6996u ,LaEQQQDUv. :}P$QQ8OI?. V9999L_H8Qc !y0QQRY.O@@@@8${reset}
9+
${bold_white}u@@@@@` :@@@@@R I@@@@Q` ^@@@@@" -M@@@@@@@@@@@q ,Q@@@@@@@@@@@V` O@@@@Q#@@@G-0@@@@@@@##@@@@8${reset}
10+
${bold_white}u@@@@@}iYz#@@@@@) `$@@@@} O@@@@j -B@@@@Q \@@@T ,#@@@@K_`=#@@@@q O@@@@@8]*);E@@@@@V::V@@@@@8${reset}
11+
${bold_white}u@@@@@@@@@@@@@O! ,#@@@B.*@@@@0` L@@@@@ T@@@@@` y@@@@@: O@@@@Q` @@@@@H G@@@@8${reset}
12+
${bold_white}u@@@@@6OOOMj]! x@@@@}9@@@#! x@@@@@ }@@@@@. U@@@@@, O@@@@$ #@@@@b d@@@@8${reset}
13+
${bold_white}u@@@@@` K@@@#@@@@x `0@@@@# /@@| .Q@@@@0r~Y@@@@@w O@@@@$ P@@@@@OxxO@@@@@8${reset}
14+
${bold_white}u@@@@@` `#@@@@@@g `c@@@@@@@@@@#T `M@@@@@@@@@@#) O@@@@$ `z@@@@@@@QQ@@@@8${reset}
15+
${bold_white}=yyyyV x@@@@@#: `~YI5MWIx! `^}m5MGwx: |yyyyv `*w33y~ )yyyyx${reset}
16+
${bold_white}=gEB@@@@#r ${reset}
17+
${bold_white}`g@@@@@#X_ ${reset}
1818
${bold_white}`-":_`

discord/banners.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
import time
1212
import warnings
1313
from typing import Sequence
14-
from . import __version__
1514

1615
import colorlog
1716
import colorlog.escape_codes
1817

18+
from . import __version__
19+
1920
__all__: Sequence[str] = ("start_logging", "print_banner")
2021

2122

discord/bot.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def pending_application_commands(self):
111111
def commands(self) -> list[ApplicationCommand | Any]:
112112
commands = self.application_commands
113113
if self._bot._supports_prefixed_commands and hasattr(self._bot, "prefixed_commands"):
114-
commands += getattr(self._bot, "prefixed_commands")
114+
commands += self._bot.prefixed_commands
115115
return commands
116116

117117
@property
@@ -265,7 +265,7 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
265265
if isinstance(cmd, SlashCommandGroup):
266266
if len(cmd.subcommands) != len(match.get("options", [])):
267267
return True
268-
for i, subcommand in enumerate(cmd.subcommands):
268+
for subcommand in cmd.subcommands:
269269
match_ = next(
270270
(data for data in match["options"] if data["name"] == subcommand.name),
271271
MISSING,
@@ -357,8 +357,9 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
357357
return_value.append({"command": cmd, "action": None, "id": int(match["id"])})
358358

359359
# Now let's see if there are any commands on discord that we need to delete
360-
for cmd, value_ in registered_commands_dict.items():
361-
match = find(lambda c: c.name == value_["name"], pending)
360+
for _, value_ in registered_commands_dict.items():
361+
# name default arg is used because loop variables leak in surrounding scope
362+
match = find(lambda c, name=value_["name"]: c.name == name, pending)
362363
if match is None:
363364
# We have this command registered but not in our list
364365
return_value.append(
@@ -517,7 +518,11 @@ def register(
517518
)
518519
continue
519520
# We can assume the command item is a command, since it's only a string if action is delete
520-
match = find(lambda c: c.name == cmd["command"].name and c.type == cmd["command"].type, pending)
521+
wanted = cmd["command"]
522+
name = wanted.name
523+
type_ = wanted.type
524+
525+
match = next((c for c in pending if c.name == name and c.type == type_), None)
521526
if match is None:
522527
continue
523528
if cmd["action"] == "edit":
@@ -606,8 +611,10 @@ def register(
606611
registered = await register("bulk", data, guild_id=guild_id)
607612

608613
for i in registered:
614+
type_ = i.get("type")
615+
# name, type_ default args are used because loop variables leak in surrounding scope
609616
cmd = find(
610-
lambda c: c.name == i["name"] and c.type == i.get("type"),
617+
lambda c, name=i["name"], type_=type_: c.name == name and c.type == type_,
611618
self.pending_application_commands,
612619
)
613620
if not cmd:
@@ -624,7 +631,7 @@ async def sync_commands(
624631
force: bool = False,
625632
guild_ids: list[int] | None = None,
626633
register_guild_commands: bool = True,
627-
check_guilds: list[int] | None = [],
634+
check_guilds: list[int] | None = None,
628635
delete_existing: bool = True,
629636
) -> None:
630637
"""|coro|
@@ -711,25 +718,37 @@ async def on_connect():
711718
)
712719
registered_guild_commands[guild_id] = app_cmds
713720

714-
for i in registered_commands:
721+
for item in registered_commands:
722+
type_ = item.get("type")
723+
# name, type_ default args are used because loop variables leak in surrounding scope
715724
cmd = find(
716-
lambda c: c.name == i["name"] and c.guild_ids is None and c.type == i.get("type"),
725+
lambda c, name=item["name"], type_=type_: (c.name == name and c.guild_ids is None and c.type == type_),
717726
self.pending_application_commands,
718727
)
719728
if cmd:
720-
cmd.id = i["id"]
729+
cmd.id = item["id"]
721730
self._application_commands[cmd.id] = cmd
722731

723732
if register_guild_commands and registered_guild_commands:
724733
for guild_id, guild_cmds in registered_guild_commands.items():
725734
for i in guild_cmds:
726-
cmd = find(
727-
lambda cmd: cmd.name == i["name"]
728-
and cmd.type == i.get("type")
729-
and cmd.guild_ids is not None
730-
and (guild_id := i.get("guild_id"))
731-
and guild_id in cmd.guild_ids,
732-
self.pending_application_commands,
735+
name = i["name"]
736+
type_ = i.get("type")
737+
target_gid = i.get("guild_id")
738+
if target_gid is None:
739+
continue
740+
741+
cmd = next(
742+
(
743+
c
744+
for c in self.pending_application_commands
745+
if c.name == name
746+
and c.type == type_
747+
and c.guild_ids is not None
748+
and target_gid == guild_id
749+
and target_gid in c.guild_ids
750+
),
751+
None,
733752
)
734753
if not cmd:
735754
# command has not been added yet

0 commit comments

Comments
 (0)