From da6543d17b689c31226e1b7ba1ce7de29baee2df Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 13 Jan 2013 22:05:30 -0500 Subject: Allow grouping commands to make help output easier to comprehend --- modules/commands/help.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'modules/commands/help.cpp') diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp index 119625000..1bfbdeb77 100644 --- a/modules/commands/help.cpp +++ b/modules/commands/help.cpp @@ -15,6 +15,20 @@ class CommandHelp : public Command { + static const unsigned help_wrap_len = 40; + + static CommandGroup *FindGroup(const Anope::string &name) + { + for (unsigned i = 0; i < Config->CommandGroups.size(); ++i) + { + CommandGroup &gr = Config->CommandGroups[i]; + if (gr.name == name) + return &gr; + } + + return NULL; + } + public: CommandHelp(Module *creator) : Command(creator, "generic/help", 0) { @@ -29,16 +43,27 @@ class CommandHelp : public Command if (MOD_RESULT == EVENT_STOP) return; + Anope::string source_command = source.command; const BotInfo *bi = source.service; const CommandInfo::map &map = source.c ? Config->Fantasy : bi->commands; - if (params.empty()) + if (params.empty() || params[0].equals_ci("ALL")) { + bool all = !params.empty() && params[0].equals_ci("ALL"); + typedef std::map > GroupInfo; + GroupInfo groups; + + if (all) + source.Reply(_("All available commands for \2%s\2:"), source.service->nick.c_str()); + for (CommandInfo::map::const_iterator it = map.begin(), it_end = map.end(); it != it_end; ++it) { const Anope::string &c_name = it->first; const CommandInfo &info = it->second; + if (info.hide) + continue; + // Smaller command exists Anope::string cmd; spacesepstream(c_name).GetToken(cmd, 0); @@ -55,10 +80,52 @@ class CommandHelp : public Command else if (!info.permission.empty() && !source.HasCommand(info.permission)) continue; + if (!info.group.empty() && !all) + { + CommandGroup *gr = FindGroup(info.group); + if (gr != NULL) + { + groups[gr].push_back(c_name); + continue; + } + } + source.command = c_name; c->OnServHelp(source); } + + for (GroupInfo::iterator it = groups.begin(), it_end = groups.end(); it != it_end; ++it) + { + CommandGroup *gr = it->first; + + source.Reply(" "); + source.Reply("%s", gr->description.c_str()); + + Anope::string buf; + for (std::list::iterator it2 = it->second.begin(), it2_end = it->second.end(); it2 != it2_end; ++it2) + { + const Anope::string &c_name = *it2; + + buf += ", " + c_name; + + if (buf.length() > help_wrap_len) + { + source.Reply(" %s", buf.substr(2).c_str()); + buf.clear(); + } + } + if (buf.length() > 2) + { + source.Reply(" %s", buf.substr(2).c_str()); + buf.clear(); + } + } + if (!groups.empty()) + { + source.Reply(" "); + source.Reply(_("Use the \2%s ALL\2 command to list all command descriptions."), source_command.c_str()); + } } else { -- cgit