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

Allow users to reply to messages without codeblocks #145

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/utls/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,26 @@ pub async fn get_components(input: &str, author : &User, compilation_manager : O
}
else if find_code_block(&mut result, input, author).await? {
// If we find a code block from our executor's message, and it's also a reply
// let's assume we found the stdin and what they're quoting is the code.
// let's assume we found the stdin and what they're replying to is the code.
// Anything else probably doesn't make sense.
if let Some(replied_msg) = reply {
result.stdin = result.code;
result.code = String::default();

let attachment = get_message_attachment(&replied_msg.attachments).await?;
if !attachment.0.is_empty() {
if !result.target.is_empty() {
result.target = attachment.1;
}
// shift previos code to stdin, we have found code
result.stdin = result.code;
result.code = String::default();
result.code = attachment.0;
}
else if !find_code_block(&mut result, &replied_msg.content, author).await? {
return Err(CommandError::from(
"Cannot find code to compile assuming your code block is the program's stdin.",
))
else {
let mut fake_result = ParserResult::default();
if find_code_block(&mut fake_result, &replied_msg.content, author).await? {
// we found a code block - lets assume the reply's codeblock is our actual code
result.stdin = result.code;
result.code = fake_result.code;
}
}
}
}
Expand All @@ -169,10 +172,10 @@ pub async fn get_components(input: &str, author : &User, compilation_manager : O
}
result.code = attachment.0;
}
// no reply in the attachment, lets check for a code-block..
// no attachment in the reply, lets check for a code-block..
else if !find_code_block(&mut result, &replied_msg.content, author).await? {
return Err(CommandError::from(
"You must attach a code-block containing code to your message or quote a message that has one.",
"You must attach a code-block containing code to your message or reply to a message that has one.",
))
}
}
Expand Down