Skip to content

Commit a89c94a

Browse files
committed
🚧 WIP
1 parent 43efb6a commit a89c94a

File tree

7 files changed

+488
-270
lines changed

7 files changed

+488
-270
lines changed

discord/abc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ async def send(
15111511
if reference is not None:
15121512
try:
15131513
_reference = reference.to_message_reference_dict()
1514-
from .message import MessageReference # noqa: PLC0415
1514+
from .message import MessageReference
15151515

15161516
if not isinstance(reference, MessageReference):
15171517
warn_deprecated(
@@ -1945,6 +1945,10 @@ async def connect(
19451945
return voice
19461946

19471947

1948-
class Mentionable:
1949-
# TODO: documentation, methods if needed
1950-
pass
1948+
@runtime_checkable
1949+
class Mentionable(Protocol):
1950+
"""An ABC that details the common operations on an object that can
1951+
be mentioned.
1952+
"""
1953+
1954+
def mention(self) -> str: ...

discord/commands/core.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
Union,
4646
)
4747

48+
from discord.interactions import AutocompleteInteraction, Interaction
49+
4850
from ..channel import PartialMessageable, _threaded_guild_channel_factory
4951
from ..channel.thread import Thread
5052
from ..enums import Enum as DiscordEnum
@@ -111,7 +113,7 @@
111113

112114

113115
def wrap_callback(coro):
114-
from ..ext.commands.errors import CommandError # noqa: PLC0415
116+
from ..ext.commands.errors import CommandError
115117

116118
@functools.wraps(coro)
117119
async def wrapped(*args, **kwargs):
@@ -131,7 +133,7 @@ async def wrapped(*args, **kwargs):
131133

132134

133135
def hooked_wrapped_callback(command, ctx, coro):
134-
from ..ext.commands.errors import CommandError # noqa: PLC0415
136+
from ..ext.commands.errors import CommandError
135137

136138
@functools.wraps(coro)
137139
async def wrapped(arg):
@@ -188,7 +190,7 @@ class ApplicationCommand(_BaseCommand, Generic[CogT, P, T]):
188190
cog = None
189191

190192
def __init__(self, func: Callable, **kwargs) -> None:
191-
from ..ext.commands.cooldowns import BucketType, CooldownMapping, MaxConcurrency # noqa: PLC0415
193+
from ..ext.commands.cooldowns import BucketType, CooldownMapping, MaxConcurrency
192194

193195
cooldown = getattr(func, "__commands_cooldown__", kwargs.get("cooldown"))
194196

@@ -330,7 +332,7 @@ def _prepare_cooldowns(self, ctx: ApplicationContext):
330332
retry_after = bucket.update_rate_limit(current)
331333

332334
if retry_after:
333-
from ..ext.commands.errors import CommandOnCooldown # noqa: PLC0415
335+
from ..ext.commands.errors import CommandOnCooldown
334336

335337
raise CommandOnCooldown(bucket, retry_after, self._buckets.type) # type: ignore
336338

@@ -1005,7 +1007,7 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
10051007
arg = Object(id=int(arg))
10061008

10071009
elif op.input_type == SlashCommandOptionType.string and (converter := op.converter) is not None:
1008-
from discord.ext.commands import Converter # noqa: PLC0415
1010+
from discord.ext.commands import Converter
10091011

10101012
if isinstance(converter, Converter):
10111013
if isinstance(converter, type):
@@ -1044,10 +1046,10 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
10441046
else:
10451047
await self.callback(ctx, **kwargs)
10461048

1047-
async def invoke_autocomplete_callback(self, ctx: AutocompleteContext):
1049+
async def invoke_autocomplete_callback(self, interaction: AutocompleteInteraction) -> None:
10481050
values = {i.name: i.default for i in self.options}
10491051

1050-
for op in ctx.interaction.data.get("options", []):
1052+
for op in interaction.data.get("options", []):
10511053
if op.get("focused", False):
10521054
# op_name is used because loop variables leak in surrounding scope
10531055
option = find(lambda o, op_name=op["name"]: o.name == op_name, self.options)
@@ -1057,12 +1059,6 @@ async def invoke_autocomplete_callback(self, ctx: AutocompleteContext):
10571059
ctx.value = op.get("value")
10581060
ctx.options = values
10591061

1060-
if option.autocomplete._is_instance_method:
1061-
instance = getattr(option.autocomplete, "__self__", ctx.cog)
1062-
result = option.autocomplete(instance, ctx)
1063-
else:
1064-
result = option.autocomplete(ctx)
1065-
10661062
if inspect.isawaitable(result):
10671063
result = await result
10681064

@@ -1232,7 +1228,7 @@ def __init__(
12321228
self.description_localizations: dict[str, str] = kwargs.get("description_localizations", MISSING)
12331229

12341230
# similar to ApplicationCommand
1235-
from ..ext.commands.cooldowns import BucketType, CooldownMapping, MaxConcurrency # noqa: PLC0415
1231+
from ..ext.commands.cooldowns import BucketType, CooldownMapping, MaxConcurrency
12361232

12371233
# no need to getattr, since slash cmds groups cant be created using a decorator
12381234

@@ -1418,11 +1414,10 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
14181414
ctx.interaction.data = option
14191415
await command.invoke(ctx)
14201416

1421-
async def invoke_autocomplete_callback(self, ctx: AutocompleteContext) -> None:
1422-
option = ctx.interaction.data["options"][0]
1417+
async def invoke_autocomplete_callback(self, interaction: AutocompleteInteraction) -> None:
1418+
option = interaction.data["options"][0]
14231419
command = find(lambda x: x.name == option["name"], self.subcommands)
1424-
ctx.interaction.data = option
1425-
await command.invoke_autocomplete_callback(ctx)
1420+
await command.invoke_autocomplete_callback(interaction)
14261421

14271422
async def call_before_hooks(self, ctx: ApplicationContext) -> None:
14281423
# only call local hooks

0 commit comments

Comments
 (0)