Skip to content

Commit

Permalink
Consolidate into ext.bridge.context
Browse files Browse the repository at this point in the history
  • Loading branch information
baronkobama committed May 13, 2022
1 parent f6a47ea commit ead00ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 20 additions & 1 deletion discord/ext/bridge/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,35 @@ class BridgeExtContext(BridgeContext, Context):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._original_response_message: Optional[Message] = None

async def _respond(self, *args, **kwargs) -> Message:
return await self._get_super("reply")(*args, **kwargs)
message = await self._get_super("reply")(*args, **kwargs)
if self._original_response_message is None:
self._original_response_message = message
return message

async def _defer(self, *args, **kwargs) -> None:
return await self._get_super("trigger_typing")(*args, **kwargs)

async def _edit(self, *args, **kwargs) -> Message:
return await self._original_response_message.edit(*args, **kwargs)

async def delete(self, *, delay: Optional[float] = None, reason: Optional[str] = None) -> None:
"""|coro|
Deletes the original response message, if it exists.
Parameters
-----------
delay: Optional[:class:`float`]
If provided, the number of seconds to wait before deleting the message.
reason: Optional[:class:`str`]
The reason for deleting the message. Shows up on the audit log.
"""
if self._original_response_message:
await self._original_response_message.delete(delay=delay, reason=reason)


if TYPE_CHECKING:
# This is a workaround for mypy not being able to resolve the type of BridgeCommand.
Expand Down
21 changes: 1 addition & 20 deletions discord/ext/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def __init__(
self.subcommand_passed: Optional[str] = subcommand_passed
self.command_failed: bool = command_failed
self.current_parameter: Optional[inspect.Parameter] = current_parameter
self._original_response_message: Optional[Message] = None
self._state: ConnectionState = self.message._state

async def invoke(self, command: Command[CogT, P, T], /, *args: P.args, **kwargs: P.kwargs) -> T:
Expand Down Expand Up @@ -397,22 +396,4 @@ async def send_help(self, *args: Any) -> Any:

@discord.utils.copy_doc(Message.reply)
async def reply(self, content: Optional[str] = None, **kwargs: Any) -> Message:
msg = await self.message.reply(content, **kwargs)
if self._original_response_message is None:
self._original_response_message = msg
return msg

async def delete(self, *, delay: Optional[float] = None, reason: Optional[str] = None) -> None:
"""|coro|
Deletes the original response message, if it exists.
Parameters
-----------
delay: Optional[:class:`float`]
If provided, the number of seconds to wait before deleting the message.
reason: Optional[:class:`str`]
The reason for deleting the message. Shows up on the audit log.
"""
if self._original_response_message:
await self._original_response_message.delete(delay=delay, reason=reason)
return await self.message.reply(content, **kwargs)

0 comments on commit ead00ea

Please sign in to comment.