use poise builtin codeblock type
This commit is contained in:
@@ -2,28 +2,9 @@ use crate::common::{Context, Error};
|
|||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
/// Evaluates a Lamm program
|
/// Evaluates a Lamm program
|
||||||
#[poise::command(slash_command, prefix_command, aliases("lamm"))]
|
#[poise::command(prefix_command, aliases("lamm"))]
|
||||||
pub async fn eval(ctx: Context<'_>,
|
pub async fn eval(ctx: Context<'_>, expr: poise::CodeBlock) -> Result<(), Error> {
|
||||||
#[rest]
|
let runtime = lamm::Runtime::new(Cursor::new(expr.code), "<eval>");
|
||||||
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), "<eval>");
|
|
||||||
|
|
||||||
let values = runtime.values().fold(Ok(String::new()), |acc, v| {
|
let values = runtime.values().fold(Ok(String::new()), |acc, v| {
|
||||||
if acc.is_err() {
|
if acc.is_err() {
|
||||||
|
|||||||
Reference in New Issue
Block a user