From dccd88f5e91fc2ded5093c58635c761b3e8810d0 Mon Sep 17 00:00:00 2001 From: mat ess Date: Wed, 1 Mar 2023 18:41:04 -0500 Subject: [PATCH] Add "what" --- src/commands.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index c0db926..28f9645 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -13,7 +13,7 @@ type Context<'a> = poise::Context<'a, Data, Error>; /// all of the commands supported by `buscemi` pub fn commands() -> Vec> { - vec![help(), ping(), eight_ball(), know()] + vec![help(), ping(), eight_ball(), know(), what()] } /// print helpful information @@ -79,7 +79,7 @@ async fn eight_ball( Ok(()) } -/// remember some important knowledge +/// commit some important knowledge to memory /// /// usage: /// ``` @@ -120,3 +120,23 @@ async fn know( ctx.say(message).await?; Ok(()) } + +/// recall some important knowledge +#[poise::command(prefix_command, slash_command)] +async fn what( + ctx: Context<'_>, + #[rest] + #[description = "the thing you want to look up"] + is: String, +) -> Result<(), Error> { + let message = { + let facts = ctx.data().facts.lock().unwrap(); + let is = is.strip_prefix("is ").unwrap_or(is.as_str()); + facts.get(is).map_or_else( + || format!("i don't know what {is} is"), + |definition| format!("{is} is {definition}"), + ) + }; + ctx.say(message).await?; + Ok(()) +}