2022-12-24 21:38:14 +11:00
|
|
|
use super::{
|
|
|
|
VerbContext, UserVerb, UserVerbRef, UResult,
|
|
|
|
CommandHandlingError::UserError
|
|
|
|
};
|
2022-12-24 21:16:23 +11:00
|
|
|
use async_trait::async_trait;
|
2022-12-28 20:00:55 +11:00
|
|
|
use ansi::ansi;
|
2022-12-24 21:38:14 +11:00
|
|
|
use phf::phf_map;
|
|
|
|
|
2022-12-27 00:20:09 +11:00
|
|
|
static ALWAYS_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! {
|
|
|
|
"<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.")
|
|
|
|
};
|
|
|
|
|
|
|
|
static UNREGISTERED_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 unregistered users:\r\n\
|
|
|
|
\t<bold>register<reset>\tLearn about the <bold>register<reset> command.\r\n\
|
|
|
|
\t<bold>login<reset>\tLearn how to log in as an existing user.\r\n"),
|
2022-12-27 16:08:27 +11:00
|
|
|
"register" =>
|
|
|
|
ansi!("Registers a new user. You are allowed at most 5 at once.\r\n\
|
|
|
|
\t<bold>register <lt>username> <lt>password> <lt>email><reset>\r\n\
|
|
|
|
Email will be used to check you don't have too many accounts and \
|
|
|
|
in case you need to reset your password."),
|
|
|
|
"login" =>
|
|
|
|
ansi!("Logs in as an existing user.\r\n\
|
|
|
|
\t<bold>login <lt>username> <lt>password<reset>")
|
2022-12-27 00:20:09 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
static REGISTERED_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! {
|
2022-12-24 21:38:14 +11:00
|
|
|
"" =>
|
|
|
|
ansi!("Type <bold>help <lt>topicname><reset> to learn about a topic. Most \
|
|
|
|
commands can be used as a topicname.\r\n\
|
2022-12-27 16:08:27 +11:00
|
|
|
Topics of interest:\r\n\
|
|
|
|
\t<bold>newbie<reset>\tLearn the absolute basics."),
|
|
|
|
"newbie" =>
|
|
|
|
ansi!("So you've just landed in BlastMud, and want to know how to get started?\r\n\
|
|
|
|
As we develop the game, this will eventually have some useful information for you!"),
|
2022-12-24 21:38:14 +11:00
|
|
|
};
|
2022-12-24 21:16:23 +11:00
|
|
|
|
2022-12-25 01:42:51 +11:00
|
|
|
static EXPLICIT_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! {
|
|
|
|
"fuck" =>
|
|
|
|
ansi!("Type <bold>fuck <lt>name><reset> to fuck someone. It only works if \
|
|
|
|
they have consented.")
|
|
|
|
};
|
|
|
|
|
2022-12-24 21:16:23 +11:00
|
|
|
pub struct Verb;
|
|
|
|
#[async_trait]
|
|
|
|
impl UserVerb for Verb {
|
2022-12-26 01:30:59 +11:00
|
|
|
async fn handle(self: &Self, ctx: &mut VerbContext, _verb: &str, remaining: &str) -> UResult<()> {
|
2022-12-25 01:42:51 +11:00
|
|
|
let mut help = None;
|
2022-12-27 00:20:09 +11:00
|
|
|
let is_unregistered = match ctx.user_dat {
|
|
|
|
None => true,
|
|
|
|
Some(user_dat) => !user_dat.terms.terms_complete
|
|
|
|
};
|
|
|
|
if is_unregistered {
|
|
|
|
help = help.or_else(|| UNREGISTERED_HELP_PAGES.get(remaining));
|
|
|
|
} else {
|
|
|
|
help = help.or_else(|| REGISTERED_HELP_PAGES.get(remaining));
|
|
|
|
if !ctx.session_dat.less_explicit_mode {
|
|
|
|
help = help.or_else(|| EXPLICIT_HELP_PAGES.get(remaining))
|
|
|
|
}
|
2022-12-25 01:42:51 +11:00
|
|
|
}
|
2022-12-27 00:20:09 +11:00
|
|
|
help = help.or_else(|| ALWAYS_HELP_PAGES.get(remaining));
|
2022-12-25 01:42:51 +11:00
|
|
|
let help_final = help.ok_or(
|
2022-12-24 21:38:14 +11:00
|
|
|
UserError("No help available on that".to_string()))?;
|
2022-12-25 12:42:03 +11:00
|
|
|
ctx.trans.queue_for_session(ctx.session,
|
|
|
|
Some(&(help_final.to_string() + "\r\n"))
|
|
|
|
).await?;
|
2022-12-24 21:16:23 +11:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static VERB_INT: Verb = Verb;
|
|
|
|
pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;
|