@@ -1,29 +1,38 @@
|
||||
use crate::common::{Context, Error};
|
||||
use crate::common::{self, Context, Error};
|
||||
use std::io::Cursor;
|
||||
|
||||
/// Evaluates a Lamm program
|
||||
#[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), "<eval>");
|
||||
|
||||
let values = runtime.values().fold(Ok(String::new()), |acc, v| {
|
||||
if acc.is_err() {
|
||||
return acc;
|
||||
#[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 x = acc.unwrap();
|
||||
let runtime = lamm::Runtime::new(Cursor::new(expr), "<eval>");
|
||||
|
||||
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::<Result<Vec<_>, _>>();
|
||||
|
||||
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.join("\n"))).await?,
|
||||
Err(e) => common::no_ping_reply(&ctx, format!("```ansi\n\x1b[31;1merror\x1b[0m: {e}\n```")).await?,
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -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<String>) -> Result<(), Error>
|
||||
{
|
||||
poise::builtins::help(ctx, command.as_deref(), poise::builtins::HelpConfiguration::default()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn commands() -> Vec<Command<Data, Error>> {
|
||||
vec![
|
||||
help(),
|
||||
ping::ping(),
|
||||
dox::dox(),
|
||||
yeehaw::yeehaw(),
|
||||
|
||||
Reference in New Issue
Block a user