Skip to content

Commit 53b5495

Browse files
committed
change InteractionContext to ApplicationContext
1 parent c560dc9 commit 53b5495

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

discord/app/commands.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from ..member import Member
3535
from ..user import User
3636
from ..message import Message
37-
from .context import InteractionContext
37+
from .context import ApplicationContext
3838
from ..utils import find, get_or_fetch, async_all
3939
from ..errors import DiscordException, NotFound, ValidationError, ClientException
4040
from .errors import ApplicationCommandError, CheckFailure, ApplicationCommandInvokeError
@@ -104,7 +104,7 @@ def __repr__(self):
104104
def __eq__(self, other):
105105
return isinstance(other, self.__class__)
106106

107-
async def prepare(self, ctx: InteractionContext) -> None:
107+
async def prepare(self, ctx: ApplicationContext) -> None:
108108
# This should be same across all 3 types
109109
ctx.command = self
110110

@@ -116,13 +116,13 @@ async def prepare(self, ctx: InteractionContext) -> None:
116116
await self.call_before_hooks(ctx)
117117
pass
118118

119-
async def invoke(self, ctx: InteractionContext) -> None:
119+
async def invoke(self, ctx: ApplicationContext) -> None:
120120
await self.prepare(ctx)
121121

122122
injected = hooked_wrapped_callback(self, ctx, self._invoke)
123123
await injected(ctx)
124124

125-
async def can_run(self, ctx: InteractionContext) -> bool:
125+
async def can_run(self, ctx: ApplicationContext) -> bool:
126126

127127
if not await ctx.bot.can_run(ctx):
128128
raise CheckFailure(f'The global check functions for command {self.name} failed.')
@@ -134,7 +134,7 @@ async def can_run(self, ctx: InteractionContext) -> bool:
134134

135135
return await async_all(predicate(ctx) for predicate in predicates) # type: ignore
136136

137-
async def dispatch_error(self, ctx: InteractionContext, error: Exception) -> None:
137+
async def dispatch_error(self, ctx: ApplicationContext, error: Exception) -> None:
138138
ctx.command_failed = True
139139
cog = self.cog
140140
try:
@@ -233,7 +233,7 @@ def after_invoke(self, coro):
233233
self._after_invoke = coro
234234
return coro
235235

236-
async def call_before_hooks(self, ctx: InteractionContext) -> None:
236+
async def call_before_hooks(self, ctx: ApplicationContext) -> None:
237237
# now that we're done preparing we can call the pre-command hooks
238238
# first, call the command local hook:
239239
cog = self.cog
@@ -258,7 +258,7 @@ async def call_before_hooks(self, ctx: InteractionContext) -> None:
258258
if hook is not None:
259259
await hook(ctx)
260260

261-
async def call_after_hooks(self, ctx: InteractionContext) -> None:
261+
async def call_after_hooks(self, ctx: ApplicationContext) -> None:
262262
cog = self.cog
263263
if self._after_invoke is not None:
264264
instance = getattr(self._after_invoke, '__self__', cog)
@@ -391,7 +391,7 @@ def __eq__(self, other) -> bool:
391391
and other.description == self.description
392392
)
393393

394-
async def _invoke(self, ctx: InteractionContext) -> None:
394+
async def _invoke(self, ctx: ApplicationContext) -> None:
395395
# TODO: Parse the args better, apply custom converters etc.
396396
kwargs = {}
397397
for arg in ctx.interaction.data.get("options", []):
@@ -570,7 +570,7 @@ def command_group(self, name, description) -> SlashCommandGroup:
570570
self.subcommands.append(sub_command_group)
571571
return sub_command_group
572572

573-
async def _invoke(self, ctx: InteractionContext) -> None:
573+
async def _invoke(self, ctx: ApplicationContext) -> None:
574574
option = ctx.interaction.data["options"][0]
575575
command = find(lambda x: x.name == option["name"], self.subcommands)
576576
ctx.interaction.data = option
@@ -661,7 +661,7 @@ def __new__(cls, *args, **kwargs) -> UserCommand:
661661
self.__original_kwargs__ = kwargs.copy()
662662
return self
663663

664-
async def _invoke(self, ctx: InteractionContext) -> None:
664+
async def _invoke(self, ctx: ApplicationContext) -> None:
665665
if "members" not in ctx.interaction.data["resolved"]:
666666
_data = ctx.interaction.data["resolved"]["users"]
667667
for i, v in _data.items():
@@ -736,7 +736,7 @@ def __new__(cls, *args, **kwargs) -> MessageCommand:
736736
self.__original_kwargs__ = kwargs.copy()
737737
return self
738738

739-
async def _invoke(self, ctx: InteractionContext):
739+
async def _invoke(self, ctx: ApplicationContext):
740740
_data = ctx.interaction.data["resolved"]["messages"]
741741
for i, v in _data.items():
742742
v["id"] = int(i)

discord/app/context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from ..context_managers import Typing
3737

3838

39-
class InteractionContext:
39+
class ApplicationContext:
4040
"""Represents a Discord interaction context.
4141
4242
This class is not created manually and is instead passed to application
@@ -102,7 +102,7 @@ def respond(self):
102102

103103
@property
104104
def send(self):
105-
"""Behaves like :attr:`~discord.abc.Messagable.send` if the response is done, else behaves like :attr:`~discord.app.InteractionContext.respond`"""
105+
"""Behaves like :attr:`~discord.abc.Messagable.send` if the response is done, else behaves like :attr:`~discord.app.ApplicationContext.respond`"""
106106
return self.channel.send if self.response.is_done() else self.respond
107107

108108
@property
@@ -114,8 +114,8 @@ def followup(self):
114114
return self.interaction.followup
115115

116116
async def delete(self):
117-
"""Calls :attr:`~discord.app.InteractionContext.respond`.
118-
If the response is done, then calls :attr:`~discord.app.InteractionContext.respond` first."""
117+
"""Calls :attr:`~discord.app.ApplicationContext.respond`.
118+
If the response is done, then calls :attr:`~discord.app.ApplicationContext.respond` first."""
119119
if not self.response.is_done():
120120
await self.defer()
121121

discord/bot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
MessageCommand,
4141
UserCommand,
4242
ApplicationCommand,
43-
InteractionContext,
43+
ApplicationContext,
4444
command,
4545
)
4646
from .cog import CogMixin
@@ -323,7 +323,7 @@ def command_group(self, name: str, description: str, guild_ids=None) -> SlashCom
323323

324324
async def get_application_context(
325325
self, interaction: Interaction, cls=None
326-
) -> InteractionContext:
326+
) -> ApplicationContext:
327327
r"""|coro|
328328
329329
Returns the invocation context from the interaction.
@@ -337,18 +337,18 @@ async def get_application_context(
337337
The interaction to get the invocation context from.
338338
cls
339339
The factory class that will be used to create the context.
340-
By default, this is :class:`.InteractionContext`. Should a custom
340+
By default, this is :class:`.ApplicationContext`. Should a custom
341341
class be provided, it must be similar enough to
342-
:class:`.InteractionContext`\'s interface.
342+
:class:`.ApplicationContext`\'s interface.
343343
344344
Returns
345345
--------
346-
:class:`.InteractionContext`
346+
:class:`.ApplicationContext`
347347
The invocation context. Tye type of this can change via the
348348
``cls`` parameter.
349349
"""
350350
if cls is None:
351-
cls = InteractionContext
351+
cls = ApplicationContext
352352
return cls(self, interaction)
353353

354354

@@ -378,7 +378,7 @@ async def on_connect(self):
378378
async def on_interaction(self, interaction):
379379
await self.process_application_commands(interaction)
380380

381-
async def on_application_command_error(self, context: InteractionContext, exception: DiscordException) -> None:
381+
async def on_application_command_error(self, context: ApplicationContext, exception: DiscordException) -> None:
382382
"""|coro|
383383
384384
The default command error handler provided by the bot.
@@ -492,7 +492,7 @@ def whitelist(ctx):
492492
self.add_check(func, call_once=True)
493493
return func
494494

495-
async def can_run(self, ctx: InteractionContext, *, call_once: bool = False) -> bool:
495+
async def can_run(self, ctx: ApplicationContext, *, call_once: bool = False) -> bool:
496496
data = self._check_once if call_once else self._checks
497497

498498
if len(data) == 0:

0 commit comments

Comments
 (0)