Skip to content

Commit

Permalink
Rename original_message to original_response (#1609)
Browse files Browse the repository at this point in the history
* Rename `original_message` to `original_response`

* Add Aliases

* Fix Errors

* Remove Unnecessary `kwargs`

* Add Warnings

* Improve Warnings

* Use `utils.deprecated`

* Fix Errors

* Update Decorators

* Fix Errors

* Fix Workflow Errors

* Create a Changelog Entry

* Update the Changelog

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Lala Sabathil <[email protected]>
Co-authored-by: BobDotCom <[email protected]>
  • Loading branch information
3 people authored Oct 2, 2022
1 parent 8764a0e commit 88d43dc
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `BridgeCommand.invoke()` method. ([#1642](https://github.com/Pycord-Development/pycord/pull/1642))
- New `raw_mentions`, `raw_role_mentions` and `raw_channel_mentions` functions in `discord.utils`.
([#1658](https://github.com/Pycord-Development/pycord/pull/1658))
- New methods `original_response`, `edit_original_response` & `delete_original_response` for `Interaction` objects.
([#1609](https://github.com/Pycord-Development/pycord/pull/1609)


### Deprecated
- The `delete_message_days` parameter in ban methods is now deprecated. Please use `delete_message_seconds` instead.
([#1557](https://github.com/Pycord-Development/pycord/pull/1557))
- The `original_message`, `edit_original_message` & `delete_original_message` methods for `Interaction` are now deprecated. Please use the respective `original_response`, `edit_original_response` & `delete_original_response` methods instead.
([#1557](https://github.com/Pycord-Development/pycord/pull/1557))

### Fixed
- Various fixes to ext.bridge groups ([#1633](https://github.com/Pycord-Development/pycord/pull/1633) &
Expand Down
8 changes: 4 additions & 4 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ async def delete(self, *, delay: Optional[float] = None) -> None:
Deletes the original interaction response message.
This is a higher level interface to :meth:`Interaction.delete_original_message`.
This is a higher level interface to :meth:`Interaction.delete_original_response`.
Parameters
-----------
Expand All @@ -330,12 +330,12 @@ async def delete(self, *, delay: Optional[float] = None) -> None:
if not self.interaction.response.is_done():
await self.defer()

return await self.interaction.delete_original_message(delay=delay)
return await self.interaction.delete_original_response(delay=delay)

@property
@discord.utils.copy_doc(Interaction.edit_original_message)
@discord.utils.copy_doc(Interaction.edit_original_response)
def edit(self) -> Callable[..., Awaitable[InteractionMessage]]:
return self.interaction.edit_original_message
return self.interaction.edit_original_response

@property
def cog(self) -> Optional[Cog]:
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ async def respond(
if isinstance(msg, (discord.Message, discord.WebhookMessage)):
self.message = msg
elif isinstance(msg, discord.Interaction):
self.message = await msg.original_message()
self.message = await msg.original_response()

return self.message

Expand Down
83 changes: 68 additions & 15 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Interaction:
"_app_permissions",
"_state",
"_session",
"_original_message",
"_original_response",
"_cs_app_permissions",
"_cs_response",
"_cs_followup",
Expand All @@ -149,7 +149,7 @@ class Interaction:
def __init__(self, *, data: InteractionPayload, state: ConnectionState):
self._state: ConnectionState = state
self._session: ClientSession = state.http._HTTPClient__session
self._original_message: Optional[InteractionMessage] = None
self._original_response: Optional[InteractionMessage] = None
self._from_data(data)

def _from_data(self, data: InteractionPayload):
Expand Down Expand Up @@ -263,7 +263,7 @@ def followup(self) -> Webhook:
}
return Webhook.from_state(data=payload, state=self._state)

async def original_message(self) -> InteractionMessage:
async def original_response(self) -> InteractionMessage:
"""|coro|
Fetches the original interaction response message associated with the interaction.
Expand All @@ -287,8 +287,8 @@ async def original_message(self) -> InteractionMessage:
The original interaction response message.
"""

if self._original_message is not None:
return self._original_message
if self._original_response is not None:
return self._original_response

# TODO: fix later to not raise?
channel = self.channel
Expand All @@ -306,10 +306,28 @@ async def original_message(self) -> InteractionMessage:
)
state = _InteractionMessageState(self, self._state)
message = InteractionMessage(state=state, channel=channel, data=data) # type: ignore
self._original_message = message
self._original_response = message
return message

async def edit_original_message(
@utils.deprecated("Interaction.original_response", "2.1")
async def original_message(self):
"""An alias for :meth:`original_response`.
Raises
-------
HTTPException
Fetching the original response message failed.
ClientException
The channel for the message could not be resolved.
Returns
--------
InteractionMessage
The original interaction response message.
"""
return self.original_response()

async def edit_original_response(
self,
*,
content: Optional[str] = MISSING,
Expand Down Expand Up @@ -409,11 +427,33 @@ async def edit_original_message(
self._state.store_view(view, message.id)

if delete_after is not None:
await self.delete_original_message(delay=delete_after)
await self.delete_original_response(delay=delete_after)

return message

async def delete_original_message(self, *, delay: Optional[float] = None) -> None:
@utils.deprecated("Interaction.edit_original_response", "2.1")
async def edit_original_message(self, **kwargs):
"""An alias for :meth:`edit_original_response`.
Raises
-------
HTTPException
Editing the message failed.
Forbidden
Edited a message that is not yours.
TypeError
You specified both ``embed`` and ``embeds`` or ``file`` and ``files``
ValueError
The length of ``embeds`` was invalid.
Returns
--------
:class:`InteractionMessage`
The newly edited message.
"""
return self.edit_original_response(**kwargs)

async def delete_original_response(self, *, delay: Optional[float] = None) -> None:
"""|coro|
Deletes the original interaction response message.
Expand Down Expand Up @@ -449,6 +489,19 @@ async def delete_original_message(self, *, delay: Optional[float] = None) -> Non
else:
await func

@utils.deprecated("Interaction.delete_original_response", "2.1")
async def delete_original_message(self, **kwargs):
"""An alias for :meth:`delete_original_response`.
Raises
-------
HTTPException
Deleting the message failed.
Forbidden
Deleted a message that is not yours.
"""
return self.delete_original_response(**kwargs)

def to_dict(self) -> Dict[str, Any]:
"""
Converts this interaction object into a dict.
Expand Down Expand Up @@ -761,12 +814,12 @@ async def send_message(
if ephemeral and view.timeout is None:
view.timeout = 15 * 60.0

view.message = await self._parent.original_message()
view.message = await self._parent.original_response()
self._parent._state.store_view(view)

self._responded = True
if delete_after is not None:
await self._parent.delete_original_message(delay=delete_after)
await self._parent.delete_original_response(delay=delete_after)
return self._parent

async def edit_message(
Expand Down Expand Up @@ -894,7 +947,7 @@ async def edit_message(

self._responded = True
if delete_after is not None:
await self._parent.delete_original_message(delay=delete_after)
await self._parent.delete_original_response(delay=delete_after)

async def send_autocomplete_result(
self,
Expand Down Expand Up @@ -1032,7 +1085,7 @@ class InteractionMessage(Message):
"""Represents the original interaction response message.
This allows you to edit or delete the message associated with
the interaction response. To retrieve this object see :meth:`Interaction.original_message`.
the interaction response. To retrieve this object see :meth:`Interaction.original_response`.
This inherits from :class:`discord.Message` with changes to
:meth:`edit` and :meth:`delete` to work.
Expand Down Expand Up @@ -1105,7 +1158,7 @@ async def edit(
"""
if attachments is MISSING:
attachments = self.attachments or MISSING
return await self._state._interaction.edit_original_message(
return await self._state._interaction.edit_original_response(
content=content,
embeds=embeds,
embed=embed,
Expand Down Expand Up @@ -1137,7 +1190,7 @@ async def delete(self, *, delay: Optional[float] = None) -> None:
HTTPException
Deleting the message failed.
"""
await self._state._interaction.delete_original_message(delay=delay)
await self._state._interaction.delete_original_response(delay=delay)


class MessageInteraction:
Expand Down

0 comments on commit 88d43dc

Please sign in to comment.