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

Fix timeout for ephemeral paginators and hybrid commands #1751

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from

Conversation

AutonomousCat
Copy link

@AutonomousCat AutonomousCat commented Jan 25, 2025

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

While I was writing a command that uses ephemeral paginators, I noticed the timeout resulted in a 404 NotFound. While looking for ways to resolve this, I noticed that HybridContext required a message object in it's edit() function, so I used _prefixed_ctx to determine HybridContext. Probably not the best way to handle this, but I did what I could.

Changes

  • Added edit field to Timeout class to store the message edit coroutine
  • Updated send() and reply() to use the appropriate edit method based on command type

Test Scenarios

I tested with ephemeral, non-ephemeral, send, reply, slash, hybrid, and prefixed. Now works in all cases without errors.

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@@ -38,6 +39,8 @@ class Timeout:
repr=False,
)
"""The paginator that this timeout is associated with."""
edit: Callable[..., Coroutine] = attrs.field(repr=False, default=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to pass edit to Timeout instead of, say, ctx? At least that way you can forgo the if-else chain added in send() below to determine the right edit() by just using ctx.edit() regardless of command type, as have been done by the _on_button() callback. (Alternatively, add ctx to Paginator attributes instead of Timeout, then use self.paginator.ctx.edit().)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mifuyutsuki HybridContext requires message. Storing ctx was the first thing I tried, but when testing, HybridContext types would error out since the message param was missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants