summaryrefslogtreecommitdiff
path: root/modules/commands/help.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/commands/help.cpp')
-rw-r--r--modules/commands/help.cpp78
1 files changed, 72 insertions, 6 deletions
diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp
index 252406590..fcac6863c 100644
--- a/modules/commands/help.cpp
+++ b/modules/commands/help.cpp
@@ -1,6 +1,6 @@
/* Core functions
*
- * (C) 2003-2012 Anope Team
+ * (C) 2003-2013 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -15,12 +15,25 @@
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)
{
this->SetDesc(_("Displays this list and give information about commands"));
- this->SetFlag(CFLAG_STRIP_CHANNEL);
- this->SetFlag(CFLAG_ALLOW_UNREGISTERED);
+ this->AllowUnregistered(true);
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
@@ -30,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 \002%s\002:"), 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);
@@ -51,15 +75,57 @@ class CommandHelp : public Command
continue;
else if (!Config->HidePrivilegedCommands)
; // Always show with HidePrivilegedCommands disabled
- else if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !source.GetAccount())
+ else if (!c->AllowUnregistered() && !source.GetAccount())
continue;
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 \002%s ALL\002 command to list all commands and their descriptions."), source_command.c_str());
+ }
}
else
{
@@ -100,7 +166,7 @@ class CommandHelp : public Command
source.Reply(" ");
source.Reply(_("Access to this command requires the permission \002%s\002 to be present in your opertype."), info.permission.c_str());
}
- if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !source.nc)
+ if (!c->AllowUnregistered() && !source.nc)
{
if (info.permission.empty())
source.Reply(" ");