rust-lang / discord-mods-bot

discord moderation bot
MIT License
72 stars 30 forks source link

?play and ?eval erroneously claim that the code block is missing when there is content after the code block #84

Closed PatchMixolydic closed 3 years ago

PatchMixolydic commented 3 years ago
Screenshot of rustbot on Discord. I send '?eval `Box::new(Vec::new())` text after', to which rustbot replies 'Missing code block. ...' I then send '?play ```rust fn main() {} ``` text after', and again, rustbot replies 'Missing code block. ...'

This is a fairly minor nitpick, but the message is inaccurate since code blocks are present in both cases. This message might cause confusion for someone who doesn't realize that their message must end after the code block.

khionu commented 3 years ago

Commands don't allow for arguments in excess of what they expect. This could be accounted for, but it would be odd for commands like our ?ban, which takes a reason of arbitrary length as the last argument.

technetos commented 3 years ago

Actually, if we add another variant of the command for play and eval to accept any text after the code block these would be recognized.

@PatchMixolydic Can you provide a use case for this?

PatchMixolydic commented 3 years ago

Ignoring any text after the code block could be marginally useful for explaining code examples in the #beginners and #rust-usage sections of the The Rust Programming Language Discord server. An alternative (which is what I was originally thinking of but failed to communicate) would be to emit a different error message if the user's message contains a code block explaining that ?play and ?eval expect nothing to follow the code block, though I'm not sure how feasible this is.

technetos commented 3 years ago

@PatchMixolydic #85

khionu commented 3 years ago

This is easy enough to do by typing it all out, then copying the comment and sending it after the command, using println! to comment the output. Slash commands, which we probably will switch to in the future, would complicate this addition.

Aside from println!, what we could do is add an API within the boilerplate we send to the Playground that would allow customizing the output of the command. In short, the stdout would become a JSON blob augmented by the API we create, and then we can format the command output by that blob. We could start by replacing println! and print! with our own macros.

Just to note the more specific idea while I have it, another feature would be lined outputs. Ie, the bot could provide this at the output:

pub fn main() {
    println!("42");     // Output: 42
}

Loops may complicate this, but I think it's well within the realm of possibilities.