summaryrefslogtreecommitdiff
path: root/modules/commands
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-01-13 22:05:30 -0500
committerAdam <Adam@anope.org>2013-01-13 22:07:27 -0500
commitda6543d17b689c31226e1b7ba1ce7de29baee2df (patch)
tree750c38fc64ac41a93c9eb539637ae029239855fd /modules/commands
parent29a018088ecf42c870b78d1539a90776a21276ec (diff)
Allow grouping commands to make help output easier to comprehend
Diffstat (limited to 'modules/commands')
-rw-r--r--modules/commands/cs_info.cpp1
-rw-r--r--modules/commands/help.cpp69
2 files changed, 69 insertions, 1 deletions
diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp
index a4a0e4151..c007d9341 100644
--- a/modules/commands/cs_info.cpp
+++ b/modules/commands/cs_info.cpp
@@ -31,6 +31,7 @@ class CommandCSInfo : public Command
{
this->SetDesc(_("Lists information about the named registered channel"));
this->SetSyntax(_("\037channel\037"));
+ this->SetFlag(CFLAG_ALLOW_UNREGISTERED);
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
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<CommandGroup *, std::list<Anope::string> > 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<Anope::string>::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
{