scarletcafe / jishaku

A debugging and testing cog for discord.py rewrite bots.
https://jishaku.readthedocs.io/en/latest/
MIT License
541 stars 181 forks source link

[Feature] ReRun py/pyi command if the message is edited #104

Open circuitsacul opened 3 years ago

circuitsacul commented 3 years ago

The Problem

Very frequently, I will write a long eval code and come across some error. This means I have to copy+paste my code, fix the error, and then resend it. This is spammy and slow.

The Ideal Solution

After running the py/pyi command, jiskaku will listen for the on_raw_message_edit event for the next 30 seconds on this specific message. If edited, rerun the py/pyi command, and instead of sending new output, edit the original message with the new output.

The Current Solution

Copy+paste the eval command and resend it after fixing.

avizum commented 3 years ago

You can do this yourself,

@bot.listen()
async def on_message_edit(before: discord.Message, after: discord.Message):
    if before.content == after.content:
        return
    return await bot.process_commands(after)

You can also limit this to the owner with await bot.is_owner(after.author)

circuitsacul commented 3 years ago

No, because that would send a new result, not edit the original result.

avizum commented 3 years ago

Maybe you can override commands.Context and edit the message with the new content if the message was edited, Not sure though.

pythonmcpi commented 1 year ago

No, because that would send a new result, not edit the original result.

What if your evaluated code sends multiple messages before erroring? If your code works and sends something when it gets rerun, how show Jishaku know to edit the original message without modifying the Context class? (A custom Context class for Jishaku would conflict with any user-set Context classes, and monkeypatching is not a great solution for production code.)