Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ext.pages] Compatibility patch for ext.bridge #1288

Merged
merged 3 commits into from Apr 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 39 additions & 20 deletions discord/ext/pages/pagination.py
Expand Up @@ -736,6 +736,8 @@ def get_page_content(page: Union[Page, str, discord.Embed, List[discord.Embed]])
return Page(content=None, embeds=page)
else:
raise TypeError("All list items must be embeds.")
else:
raise TypeError("Page content must be a Page object, string, an embed, or a list of embeds.")

async def page_action(self, interaction: Optional[discord.Interaction] = None) -> None:
"""Triggers the callback associated with the current page, if any.
Expand Down Expand Up @@ -904,7 +906,7 @@ async def edit(

async def respond(
self,
interaction: discord.Interaction,
interaction: Union[discord.Interaction, discord.ext.bridge.BridgeContext],
ephemeral: bool = False,
target: Optional[discord.abc.Messageable] = None,
target_message: str = "Paginator sent!",
Expand All @@ -913,8 +915,9 @@ async def respond(

Parameters
------------
interaction: :class:`discord.Interaction`
The interaction which invoked the paginator.
interaction: Union[:class:`discord.Interaction`, :class:`discord.ext.bridge.BridgeContext`]
The interaction or BridgeContext which invoked the paginator.
If passing a BridgeContext object, you cannot make this an ephemeral paginator.
ephemeral: :class:`bool`
Whether the paginator message and its components are ephemeral.
If ``target`` is specified, the ephemeral message content will be ``target_message`` instead.
Expand All @@ -934,8 +937,8 @@ async def respond(
The :class:`~discord.Message` or :class:`~discord.WebhookMessage` that was sent with the paginator.
"""

if not isinstance(interaction, discord.Interaction):
raise TypeError(f"expected Interaction not {interaction.__class__!r}")
if not isinstance(interaction, (discord.Interaction, discord.ext.bridge.BridgeContext)):
raise TypeError(f"expected Interaction or BridgeContext, not {interaction.__class__!r}")

if target is not None and not isinstance(target, discord.abc.Messageable):
raise TypeError(f"expected abc.Messageable not {target.__class__!r}")
Expand All @@ -953,16 +956,17 @@ async def respond(
if page_content.custom_view:
self.update_custom_view(page_content.custom_view)

self.user = interaction.user
if target:
await interaction.response.send_message(target_message, ephemeral=ephemeral)
self.message = await target.send(
content=page_content.content,
embeds=page_content.embeds,
view=self,
)
else:
if interaction.response.is_done():
if isinstance(interaction, discord.Interaction):
self.user = interaction.user

if target:
await interaction.response.send_message(target_message, ephemeral=ephemeral)
msg = await target.send(
content=page_content.content,
embeds=page_content.embeds,
view=self,
)
elif interaction.response.is_done():
msg = await interaction.followup.send(
content=page_content.content,
embeds=page_content.embeds,
Expand All @@ -979,11 +983,26 @@ async def respond(
view=self,
ephemeral=ephemeral,
)
if isinstance(msg, (discord.Message, discord.WebhookMessage)):
self.message = msg
elif isinstance(msg, discord.Interaction):
self.message = await msg.original_message()

else:
ctx = interaction
self.user = ctx.author
if target:
await ctx.respond(target_message, ephemeral=ephemeral)
msg = await ctx.send(
content=page_content.content,
embeds=page_content.embeds,
view=self,
)
else:
msg = await ctx.respond(
content=page_content.content,
embeds=page_content.embeds,
view=self,
)
if isinstance(msg, (discord.Message, discord.WebhookMessage)):
self.message = msg
elif isinstance(msg, discord.Interaction):
self.message = await msg.original_message()
return self.message


Expand Down