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(()) +}