diff options
author | Adam <Adam@anope.org> | 2017-11-19 16:11:35 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2017-11-19 16:11:35 -0500 |
commit | 2fda0fff4655e92e388d7823e5b1c1f0c6bcfe2d (patch) | |
tree | b2cde60f3c2c98782690d67d134263924f59cc78 /src | |
parent | 3fb9bb5118a5c3c6c916a48feed0e069867f3133 (diff) |
Add subcommand syntax help, and reference subcommand help in syntax error messages
Diffstat (limited to 'src')
-rw-r--r-- | src/command.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/command.cpp b/src/command.cpp index 57203aba2..29846a1ed 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -215,11 +215,32 @@ void Command::SendSyntax(CommandSource &source) { source.Reply("{0}: \002{1} {2}\002", s, source.GetCommand(), Language::Translate(source.GetAccount(), this->syntax[0].c_str())); Anope::string spaces(s.length(), ' '); - for (unsigned i = 1, j = this->syntax.size(); i < j; ++i) + for (unsigned int i = 1; i < this->syntax.size(); ++i) source.Reply("{0} \002{1} {2}\002", spaces, source.GetCommand(), Language::Translate(source.GetAccount(), this->syntax[i].c_str())); } else + { source.Reply("{0}: \002{1}\002", s, source.GetCommand()); + } +} + +void Command::SendHelpCommand(CommandSource &source, const Anope::string &subcommand) +{ + bool has_help = source.service->commands.find("HELP") != source.service->commands.end(); + if (!has_help) + return; + + if (subcommand.empty()) + source.Reply(_("\002{0}{1} HELP {2}\002 for more information."), Config->StrictPrivmsg, source.service->nick, source.GetCommand()); + else + source.Reply(_("\002{0}{1} HELP {2} {3}\002 for more information."), Config->StrictPrivmsg, source.service->nick, source.GetCommand(), subcommand.upper()); +} + +void Command::SubcommandSyntaxError(CommandSource &source, const Anope::string &subcommand, const Anope::string &subsyntax) +{ + Anope::string s = Language::Translate(source.GetAccount(), _("Syntax")); + source.Reply("{0}: \002{1} {2} {3}\002", s, source.GetCommand(), subcommand.upper(), Language::Translate(source.GetAccount(), subsyntax.c_str())); + SendHelpCommand(source, subcommand); } bool Command::AllowUnregistered() const @@ -257,9 +278,7 @@ bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { r void Command::OnSyntaxError(CommandSource &source, const Anope::string &subcommand) { this->SendSyntax(source); - bool has_help = source.service->commands.find("HELP") != source.service->commands.end(); - if (has_help) - source.Reply(_("\002{0}{1} HELP {2}\002 for more information."), Config->StrictPrivmsg, source.service->nick, source.GetCommand()); + SendHelpCommand(source, subcommand); } void Command::Run(CommandSource &source, const Anope::string &message) |