Implement a basic help system.
This commit is contained in:
parent
4ce39f9421
commit
13b10c3fe7
@ -62,7 +62,7 @@ pub async fn handle(session: &ListenerSession, msg: &str, pool: &DBPool) -> DRes
|
|||||||
match handler.handle(&VerbContext { session, pool }, cmd, params).await {
|
match handler.handle(&VerbContext { session, pool }, cmd, params).await {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(UserError(err_msg)) => {
|
Err(UserError(err_msg)) => {
|
||||||
pool.queue_for_session(session, &err_msg).await?;
|
pool.queue_for_session(session, &(err_msg + "\r\n")).await?;
|
||||||
}
|
}
|
||||||
Err(SystemError(e)) => Err(e)?
|
Err(SystemError(e)) => Err(e)?
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,31 @@
|
|||||||
use super::{VerbContext, UserVerb, UserVerbRef, UResult, user_error};
|
use super::{
|
||||||
|
VerbContext, UserVerb, UserVerbRef, UResult,
|
||||||
|
CommandHandlingError::UserError
|
||||||
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use ansi_macro::ansi;
|
||||||
|
use phf::phf_map;
|
||||||
|
|
||||||
|
static HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! {
|
||||||
|
"" =>
|
||||||
|
ansi!("Type <bold>help <lt>topicname><reset> to learn about a topic. Most \
|
||||||
|
commands can be used as a topicname.\r\n\
|
||||||
|
Topics of interest to new users:\r\n\
|
||||||
|
\t<bold>register<reset>\tLearn about the <bold>register<reset> command.\r\n\
|
||||||
|
\t<bold>newbie<reset>\tLearn how to survive as a newb."),
|
||||||
|
"<topicname>" =>
|
||||||
|
ansi!("You are supposed to replace <lt>topicname> with the topic you want \
|
||||||
|
to learn about. Example:\r\n\
|
||||||
|
\t<bold>help register<reset> will tell you about the register command.")
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Verb;
|
pub struct Verb;
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl UserVerb for Verb {
|
impl UserVerb for Verb {
|
||||||
async fn handle(self: &Self, ctx: &VerbContext, _verb: &str, remaining: &str) -> UResult<()> {
|
async fn handle(self: &Self, ctx: &VerbContext, _verb: &str, remaining: &str) -> UResult<()> {
|
||||||
user_error("Not implemented yet\r\n".to_string())?;
|
let help = HELP_PAGES.get(remaining).ok_or(
|
||||||
|
UserError("No help available on that".to_string()))?;
|
||||||
|
ctx.pool.queue_for_session(ctx.session, &(help.to_string() + "\r\n")).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user