From ab006db973c70181660594f088ad298239cb66a9 Mon Sep 17 00:00:00 2001 From: minneelyyyy Date: Thu, 12 Dec 2024 23:33:24 -0500 Subject: [PATCH 1/4] use no ping reply in eval --- src/commands/eval.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/eval.rs b/src/commands/eval.rs index ae3e5ae..871fca8 100644 --- a/src/commands/eval.rs +++ b/src/commands/eval.rs @@ -1,4 +1,4 @@ -use crate::common::{Context, Error}; +use crate::common::{self, Context, Error}; use std::io::Cursor; /// Evaluates a Lamm program @@ -21,9 +21,9 @@ pub async fn eval(ctx: Context<'_>, expr: poise::CodeBlock) -> Result<(), Error> }); match values { - Ok(values) => ctx.reply(format!("{values}")).await, - Err(e) => ctx.reply(format!("```ansi\n\x1b[31;1merror\x1b[0m: {e}\n```")).await, - }?; + Ok(values) => common::no_ping_reply(&ctx, format!("{values}")).await?, + Err(e) => common::no_ping_reply(&ctx, format!("```ansi\n\x1b[31;1merror\x1b[0m: {e}\n```")).await?, + }; Ok(()) } \ No newline at end of file From e99912465b54c68e3588ade8d15e49efa4c92b2b Mon Sep 17 00:00:00 2001 From: minneelyyyy Date: Fri, 13 Dec 2024 00:02:50 -0500 Subject: [PATCH 2/4] rewrite: readability --- src/commands/eval.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/commands/eval.rs b/src/commands/eval.rs index 871fca8..265809e 100644 --- a/src/commands/eval.rs +++ b/src/commands/eval.rs @@ -1,27 +1,17 @@ use crate::common::{self, Context, Error}; use std::io::Cursor; -/// Evaluates a Lamm program +/// 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), ""); - let values = runtime.values().fold(Ok(String::new()), |acc, v| { - if acc.is_err() { - return acc; - }; - - let x = acc.unwrap(); - - match v { - Ok(lamm::Value::Nil) => Ok(x), - Ok(v) => Ok(format!("{x}\n{v}")), - Err(e) => Err(e), - } - }); + let values = runtime.values() + .map(|res| res.map(|value| value.to_string())) + .collect::, _>>(); match values { - Ok(values) => common::no_ping_reply(&ctx, format!("{values}")).await?, + Ok(values) => common::no_ping_reply(&ctx, format!("{}", values.join("\n"))).await?, Err(e) => common::no_ping_reply(&ctx, format!("```ansi\n\x1b[31;1merror\x1b[0m: {e}\n```")).await?, }; From 4e3dd0015703fc75950d4c2e3ec11d6d94ec87c4 Mon Sep 17 00:00:00 2001 From: minneelyyyy Date: Tue, 24 Dec 2024 14:42:50 -0500 Subject: [PATCH 3/4] revert: using code blocks makes simple calculations more annoying to write --- src/commands/eval.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) 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())) From 90754143ce9d6ba3f36715cd7bfad6ad6403bce2 Mon Sep 17 00:00:00 2001 From: minneelyyyy Date: Tue, 24 Dec 2024 14:43:39 -0500 Subject: [PATCH 4/4] add basic help menu --- src/commands/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 9792b03..9e126e5 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -8,10 +8,21 @@ mod eval; mod self_roles; mod settings; -use crate::common::{Data, Error}; +use crate::common::{Data, Error, Context}; + +/// Display a help menu +#[poise::command(prefix_command, slash_command)] +async fn help(ctx: Context<'_>, + #[description = "Specific command to get help with"] + command: Option) -> Result<(), Error> +{ + poise::builtins::help(ctx, command.as_deref(), poise::builtins::HelpConfiguration::default()).await?; + Ok(()) +} pub fn commands() -> Vec> { vec![ + help(), ping::ping(), dox::dox(), yeehaw::yeehaw(),