Add "what"

main
mat ess 2023-03-01 18:41:04 -05:00
parent 46c5244c1f
commit dccd88f5e9
1 changed files with 22 additions and 2 deletions

View File

@ -13,7 +13,7 @@ type Context<'a> = poise::Context<'a, Data, Error>;
/// all of the commands supported by `buscemi` /// all of the commands supported by `buscemi`
pub fn commands() -> Vec<poise::Command<Data, Error>> { pub fn commands() -> Vec<poise::Command<Data, Error>> {
vec![help(), ping(), eight_ball(), know()] vec![help(), ping(), eight_ball(), know(), what()]
} }
/// print helpful information /// print helpful information
@ -79,7 +79,7 @@ async fn eight_ball(
Ok(()) Ok(())
} }
/// remember some important knowledge /// commit some important knowledge to memory
/// ///
/// usage: /// usage:
/// ``` /// ```
@ -120,3 +120,23 @@ async fn know(
ctx.say(message).await?; ctx.say(message).await?;
Ok(()) 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(())
}