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

Add check_rerun_command util to commands.py #137

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

TizzySaurus
Copy link
Contributor

@TizzySaurus TizzySaurus commented Sep 14, 2022

Rewrites the logic of the eval command in python-discord/bot to create a re-run util (the eval command implementation had flaws, e.g including the python version to run in the edited message caused it to break since the version would be treated as code, and not the python version argument).

The core idea:

  • User invokes a command that calls the check_rerun_command util.
    • If the passed context's message content is edited within REDO_TIMEOUT seconds, and the user then reacts with the 🔁 emoji that appears within 10 seconds, then the util will rerun the command (NB: this means commands with usage statistics will have the rerun add to the statistic, which doesn't currently happen but we arguably want this anyway).
    • Otherwise, the appropriate error message will appear, and the user won't be able to edit and re-invoke anymore.

This is made since python-discord/sir-lancebot#1062 asks for re-run, and as such I got approval from @mbaruh in the staff-lounge to move (and as it turns out, fix) the code from bot.

I have thoroughly tested this but there's of course still a chance I missed something. Example usage of the util to aid with testing:

@bot.command()
async def greet(ctx, *, name: str = "World"):
    response = await ctx.send(f"Hello, {name}!")
    await check_rerun_command(ctx, response)

@TizzySaurus TizzySaurus added s: approved An issue or PR with core developer approval a: code Pull requests which add features, fixes, or any code change t: feature a: other Pull requests which do not fit into any of the other categories labels Sep 14, 2022
@netlify
Copy link

netlify bot commented Sep 14, 2022

Deploy Preview for bot-core failed.

Name Link
🔨 Latest commit ef00c18
🔍 Latest deploy log https://app.netlify.com/sites/bot-core/deploys/632e3b947fd10200080b4249

…heck_rerun_command` to better reflect purpose.

- The util now automatically re-invokes the command when applicable, and sends an error message otherwise. Rest of core functionality remains the same.
@TizzySaurus TizzySaurus changed the title Add check_rerun_job util to commands.py Add check_rerun_command util to commands.py Sep 23, 2022
@TizzySaurus TizzySaurus marked this pull request as ready for review September 23, 2022 21:04
@netlify
Copy link

netlify bot commented May 4, 2023

Deploy Preview for bot-core ready!

Name Link
🔨 Latest commit ecf71ad
🔍 Latest deploy log https://app.netlify.com/sites/bot-core/deploys/645417cf6b0ff50008fdec2a
😎 Deploy Preview https://deploy-preview-137--bot-core.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: code Pull requests which add features, fixes, or any code change a: other Pull requests which do not fit into any of the other categories s: approved An issue or PR with core developer approval t: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant