mirror of
https://github.com/anope/anope.git
synced 2026-07-04 02:43:12 +02:00
Expand GetQueryCommand to take a command name.
This commit is contained in:
+27
-3
@@ -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)
|
||||
|
||||
+12
-7
@@ -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())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user