Allow evaling code from context menus
Closes #2270 Pretty simple change. None of the internals have been tweaked. A new context menu with type 3 has been added that will allow for users to eval their or someone else's code (this is new) with the press of a button.
We wouldn't want, for example, for someone to eval a message from 10 hours ago, especially in help channels
You're right, we wouldn't. We could probably add some config option for this in config.yml or similar, but I think 2 minutes seems reasonable. As for the message popping up without any context, not necessarily. You can see which user ran the command, and you can click on it to be taken back to the original message that eval was ran on.
Since the input message might not have the !eval command invocation, it might be a better UI to reply to the input message (should it still do that for normal invocations?).
This is another slight design issue. Due to the nature of context menus, it can technically be ran on any message, even ones that don't have any code blocks or any code at all. We have a few options here:
- Parse for code block, and if there is none, just use the message content as code to evaluate. If the command is ran on a random message, e.g "Hello people of Python Discord! I'm new to this community 😄 ", the bot would try to eval this and come up with a syntax error.
- We can forcefully look for a code block, and throw an error if there is none. Something along the lines of "this message doesn't have a code block"
Another is limiting a user to eval only their own messages, and posting an ephemeral message if they try otherwise.
I'm not really sure on this one. I don't see any immediate downsides if someone were to try to eval someone else's code. The result would be ephemeral, and no damage is done.
If I'm missing anything important here, please do let me know. Cheers 🎉
I'm not really sure on this one. I don't see any immediate downsides if someone were to try to eval someone else's code. The result would be ephemeral, and no damage is done.
What do you mean by "the result would be ephemeral"? Anyone can see the output right?
I think we still need to decide if this is something we want, and how it should work, so i'll mark this as stalled until there's a consensus on the issue, or on the server/in a staff meeting.
What do you mean by "the result would be ephemeral"? Anyone can see the output right?
@mbaruh: No, the resultant message would be only visible to the person who ran the command. So it shouldn't add any clutter for anybody else in the channel as well.
As for the viability of the feature itself - I'm not entirely sure it's really an improvement over the existing !eval command. There are limitations and I don't see a context menu fixing a major problem that the !eval command already has. I would not be averse to just closing the issue.