summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp30
-rw-r--r--src/command.cpp19
2 files changed, 39 insertions, 10 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index b01b7389f..d2cbd0cb4 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -271,11 +271,35 @@ CommandInfo *BotInfo::GetCommand(const Anope::string &cname)
return NULL;
}
-Anope::string BotInfo::GetQueryCommand() const
+Anope::string BotInfo::GetQueryCommand(const Anope::string &command, const Anope::string &extra) const
{
+ Anope::string buf;
if (Config->ServiceAlias && !this->alias.empty())
- return Anope::printf("/%s", this->alias.c_str());
- return Anope::printf("/msg %s", this->nick.c_str());
+ buf.append("/").append(this->alias);
+ else
+ buf.append("/msg ").append(this->nick);
+
+ if (!command.empty())
+ {
+ Anope::string actual_command = "\036(MISSING)\036";
+ for (const auto &[c_name, info] : this->commands)
+ {
+ if (info.name != command)
+ continue; // Wrong command.
+
+ actual_command = c_name;
+ if (!info.hide)
+ break; // Keep going to find a non-hidden alternative.
+ }
+
+ if (!actual_command.empty())
+ buf.append(" ").append(actual_command);
+ }
+
+ if (!extra.empty())
+ buf.append(" ").append(extra);
+
+ return buf;
}
BotInfo *BotInfo::Find(const Anope::string &nick, bool nick_only)
diff --git a/src/command.cpp b/src/command.cpp
index 6df28aa9f..94f88aba5 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -212,9 +212,14 @@ 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(MORE_INFO, source.service->GetQueryCommand().c_str(), source.command.c_str());
+
+ auto it = std::find_if(source.service->commands.begin(), source.service->commands.end(), [](const auto &cmd)
+ {
+ // The help command may not be called HELP.
+ return cmd.second.name == "generic/help";
+ });
+ if (it == source.service->commands.end())
+ source.Reply(MORE_INFO, source.service->GetQueryCommand("generic/help", source.command).c_str());
}
namespace
@@ -241,13 +246,13 @@ namespace
bool has_help = source.service->commands.find("HELP") != source.service->commands.end();
if (has_help && similar.empty())
{
- source.Reply(_("Unknown command \002%s\002. \"%s HELP\" for help."), message.c_str(),
- source.service->GetQueryCommand().c_str());
+ source.Reply(_("Unknown command \002%s\002. \"%s\" for help."), message.c_str(),
+ source.service->GetQueryCommand("generic/help").c_str());
}
else if (has_help)
{
- source.Reply(_("Unknown command \002%s\002. Did you mean \002%s\002? \"%s HELP\" for help."),
- message.c_str(), similar.c_str(), source.service->GetQueryCommand().c_str());
+ source.Reply(_("Unknown command \002%s\002. Did you mean \002%s\002? \"%s\" for help."),
+ message.c_str(), similar.c_str(), source.service->GetQueryCommand("generic/help").c_str());
}
else if (similar.empty())
{