diff --git a/src/commands/eval.rs b/src/commands/eval.rs index 265809e..97bb09e 100644 --- a/src/commands/eval.rs +++ b/src/commands/eval.rs @@ -1,10 +1,29 @@ use crate::common::{self, Context, Error}; use std::io::Cursor; -/// Evaluate a program written in the Lamm programming language -#[poise::command(prefix_command, aliases("lamm"))] -pub async fn eval(ctx: Context<'_>, expr: poise::CodeBlock) -> Result<(), Error> { - let runtime = lamm::Runtime::new(Cursor::new(expr.code), ""); +/// Evaluates a Lamm program +#[poise::command(slash_command, prefix_command, aliases("lamm"))] +pub async fn eval(ctx: Context<'_>, + #[rest] + expr: String) -> Result<(), Error> +{ + let expr = if expr.starts_with("```\n") { + expr.strip_prefix("```\n") + .and_then(|s| s.strip_suffix("```")) + .unwrap_or(&expr) + } else if expr.starts_with("```") { + expr.strip_prefix("```") + .and_then(|s| s.strip_suffix("```")) + .unwrap_or(&expr) + } else if expr.starts_with('`') { + expr.strip_prefix("`") + .and_then(|s| s.strip_suffix("`")) + .unwrap_or(&expr) + } else { + &expr + }; + + let runtime = lamm::Runtime::new(Cursor::new(expr), ""); let values = runtime.values() .map(|res| res.map(|value| value.to_string()))