Skip to content

Conversation

@Ow0cast
Copy link
Contributor

@Ow0cast Ow0cast commented Aug 29, 2024

Summary by Sourcery

Defer the initial processing message and edit the message with the final image instead of sending a follow-up message, streamlining the interaction flow.

Enhancements:

  • Defer the processing message instead of sending it immediately, improving user experience by indicating that the bot is working on the request.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 29, 2024

Reviewer's Guide by Sourcery

This pull request modifies the image processing functionality in the 'deepfry' command to use deferred responses instead of immediate replies, improving the user experience for longer operations.

File-Level Changes

Change Details Files
Replace immediate response with deferred processing
  • Change interaction.response.send_message() to interaction.response.defer()
  • Update the message content from 'Processing image...' to 'Here is your deepfried image:' in the deferred response
  • Replace interaction.followup.send() with interaction.response.edit_message()
tux/cogs/fun/imgeffect.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Ow0cast - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider updating the logging statements to accurately reflect the new deferred processing behavior.
  • It might be beneficial to add error handling for the image processing operation to gracefully handle any failures.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

# say that the image is being processed
logger.info("Processing image...")
await interaction.response.send_message("Processing image...")
await interaction.response.defer("Processing image...")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider removing the message from defer()

The defer() method doesn't accept a message parameter. It's used to acknowledge the interaction without sending a response. You can remove the "Processing image..." message from here.

Suggested change
await interaction.response.defer("Processing image...")
await interaction.response.defer()

file = discord.File(arr, filename="deepfried.jpg")
# edit message with image
await interaction.followup.send(content="Here is your deepfried image:", file=file)
await interaction.response.edit_message(content="Here is your deepfried image:", file=file)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Use followup.send instead of response.edit_message after deferring

When using defer(), you should use interaction.followup.send() to send the final response, not edit_message(). There's no initial message to edit after deferring, which could lead to an error.

@electron271
Copy link
Member

@Ow0cast has this been tested or does this need testing

in the future please follow the pr template

@Ow0cast
Copy link
Contributor Author

Ow0cast commented Aug 29, 2024

im going to hit you with a can of sprite

@Ow0cast
Copy link
Contributor Author

Ow0cast commented Aug 29, 2024

blame github it doesn't automatically use it

@electron271
Copy link
Member

odd, it does from my experience so ill have to take a look at that

but does it need to be tested?

@Ow0cast
Copy link
Contributor Author

Ow0cast commented Aug 29, 2024

it hasnt been tested but it should work according to the docs but the dumb ai bot thinks otherwise

regardless shouldn't hurt to test

@kzndotsh
Copy link
Contributor

This is a primer on the subject: https://gist.github.com/cibere/7e1356575780e716d2e3a23ea2bcf6da

Copy link
Member

@electron271 electron271 left a comment

Choose a reason for hiding this comment

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

A command invoke error occurred: Command 'deepfry' raised an exception: TypeError: InteractionResponse.defer() takes 1 positional argument but 2 were given

@electron271 electron271 merged commit f446ea6 into main Aug 29, 2024
@electron271 electron271 deleted the Ow0cast-patch-1 branch August 29, 2024 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants