summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-04-16 01:46:52 +0100
committerSadie Powell <sadie@witchery.services>2025-04-16 01:50:59 +0100
commit74e9a9d2feb3690dc06a310e0477cd6f17e25fab (patch)
treebfde58ac0c6babff941b29459b92e89c22cb9d76
parentd2aee394ea5bc91b132001fb5bf2457eec295432 (diff)
Automatically wrap the help output.
-rw-r--r--include/commands.h3
-rw-r--r--include/textproc.h18
-rw-r--r--modules/botserv/bs_kick.cpp4
-rw-r--r--modules/botserv/bs_set.cpp6
-rw-r--r--modules/chanserv/cs_set.cpp6
-rw-r--r--modules/chanserv/cs_set_misc.cpp4
-rw-r--r--modules/help.cpp4
-rw-r--r--modules/memoserv/ms_set.cpp56
-rw-r--r--modules/nickserv/ns_register.cpp4
-rw-r--r--modules/nickserv/ns_set.cpp9
-rw-r--r--modules/nickserv/ns_set_misc.cpp4
-rw-r--r--modules/operserv/os_set.cpp16
-rw-r--r--modules/rewrite.cpp4
-rw-r--r--src/command.cpp4
-rw-r--r--src/misc.cpp32
-rw-r--r--src/users.cpp1
16 files changed, 112 insertions, 63 deletions
diff --git a/include/commands.h b/include/commands.h
index e9df980e0..9692f438c 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -14,6 +14,7 @@
#include "service.h"
#include "anope.h"
#include "channels.h"
+#include "textproc.h"
struct CommandGroup final
{
@@ -153,7 +154,7 @@ public:
/** Called when help is requested for the client this command is on.
* @param source The source
*/
- virtual void OnServHelp(CommandSource &source);
+ virtual void OnServHelp(CommandSource &source, HelpWrapper &help);
/** Requested when the user is requesting help on this command. Help on this command should be sent to the user.
* @param source The source
diff --git a/include/textproc.h b/include/textproc.h
index 62c88bcb4..cfde60637 100644
--- a/include/textproc.h
+++ b/include/textproc.h
@@ -11,14 +11,26 @@
#pragma once
-class TextSplitter final
+class CoreExport HelpWrapper final
+{
+private:
+ std::vector<std::pair<Anope::string, Anope::string>> entries;
+ size_t longest = 0;
+
+public:
+ void AddEntry(const Anope::string &name, const Anope::string &desc);
+ void SendTo(CommandSource &source);
+};
+
+class CoreExport TextSplitter final
{
private:
- Anope::string text;
std::vector<Anope::string> formatting;
+ const size_t max_length;
+ Anope::string text;
public:
- TextSplitter(const Anope::string &t);
+ TextSplitter(const Anope::string &t, size_t ml = 0);
bool GetLine(Anope::string &out);
};
diff --git a/modules/botserv/bs_kick.cpp b/modules/botserv/bs_kick.cpp
index 80d8fc45d..97ca62d54 100644
--- a/modules/botserv/bs_kick.cpp
+++ b/modules/botserv/bs_kick.cpp
@@ -139,6 +139,7 @@ public:
source.Reply(" ");
source.Reply(_("Configures bot kickers. \037option\037 can be one of:"));
+ HelpWrapper help;
Anope::string this_name = source.command;
for (const auto &[c_name, info] : source.service->commands)
{
@@ -148,10 +149,11 @@ public:
if (command)
{
source.command = c_name;
- command->OnServHelp(source);
+ command->OnServHelp(source, help);
}
}
}
+ help.SendTo(source);
source.Reply(_(
"Type \002%s\032\037option\037\002 for more information "
diff --git a/modules/botserv/bs_set.cpp b/modules/botserv/bs_set.cpp
index 4cce07b98..a7c6ba414 100644
--- a/modules/botserv/bs_set.cpp
+++ b/modules/botserv/bs_set.cpp
@@ -37,6 +37,8 @@ public:
));
bool hide_privileged_commands = Config->GetBlock("options").Get<bool>("hideprivilegedcommands"),
hide_registered_commands = Config->GetBlock("options").Get<bool>("hideregisteredcommands");
+
+ HelpWrapper help;
Anope::string this_name = source.command;
for (const auto &[c_name, info] : source.service->commands)
{
@@ -56,10 +58,12 @@ public:
continue;
source.command = c_name;
- command->OnServHelp(source);
+ command->OnServHelp(source, help);
}
}
}
+ help.SendTo(source);
+
source.Reply(_("Type \002%s\032\037option\037\002 for more information on a particular option."),
source.service->GetQueryCommand("generic/help", this_name).c_str());
diff --git a/modules/chanserv/cs_set.cpp b/modules/chanserv/cs_set.cpp
index d4325bd8a..d5b7994de 100644
--- a/modules/chanserv/cs_set.cpp
+++ b/modules/chanserv/cs_set.cpp
@@ -39,6 +39,8 @@ public:
Anope::string this_name = source.command;
bool hide_privileged_commands = Config->GetBlock("options").Get<bool>("hideprivilegedcommands"),
hide_registered_commands = Config->GetBlock("options").Get<bool>("hideregisteredcommands");
+
+ HelpWrapper help;
for (const auto &[c_name, info] : source.service->commands)
{
if (c_name.find_ci(this_name + " ") == 0)
@@ -57,9 +59,11 @@ public:
continue;
source.command = c_name;
- c->OnServHelp(source);
+ c->OnServHelp(source, help);
}
}
+ help.SendTo(source);
+
source.Reply(_("Type \002%s\032\037option\037\002 for more information on a particular option."),
source.service->GetQueryCommand("generic/help", this_name).c_str());
return true;
diff --git a/modules/chanserv/cs_set_misc.cpp b/modules/chanserv/cs_set_misc.cpp
index 71afbe942..58650f557 100644
--- a/modules/chanserv/cs_set_misc.cpp
+++ b/modules/chanserv/cs_set_misc.cpp
@@ -157,12 +157,12 @@ public:
}
}
- void OnServHelp(CommandSource &source) override
+ void OnServHelp(CommandSource &source, HelpWrapper &help) override
{
if (descriptions.count(source.command))
{
this->SetDesc(descriptions[source.command]);
- Command::OnServHelp(source);
+ Command::OnServHelp(source, help);
}
}
diff --git a/modules/help.cpp b/modules/help.cpp
index abf97f7e1..bd29c01e5 100644
--- a/modules/help.cpp
+++ b/modules/help.cpp
@@ -47,6 +47,7 @@ public:
bool hide_privileged_commands = Config->GetBlock("options").Get<bool>("hideprivilegedcommands"),
hide_registered_commands = Config->GetBlock("options").Get<bool>("hideregisteredcommands");
+ HelpWrapper help;
if (params.empty() || params[0].equals_ci("ALL"))
{
bool all = !params.empty() && params[0].equals_ci("ALL");
@@ -88,9 +89,10 @@ public:
}
source.command = c_name;
- c->OnServHelp(source);
+ c->OnServHelp(source, help);
}
+ help.SendTo(source);
for (auto &[gr, cmds] : groups)
{
diff --git a/modules/memoserv/ms_set.cpp b/modules/memoserv/ms_set.cpp
index f4158c855..f1bd798af 100644
--- a/modules/memoserv/ms_set.cpp
+++ b/modules/memoserv/ms_set.cpp
@@ -225,18 +225,17 @@ public:
{
this->SendSyntax(source);
source.Reply(" ");
- source.Reply(_(
- "Sets various memo options. \037option\037 can be one of:"
- "\n\n"
- " NOTIFY Changes when you will be notified about\n"
- " new memos (only for nicknames)"
- "\n\n"
- " LIMIT Sets the maximum number of memos you can\n"
- " receive"
- "\n\n"
- "Type \002%s\032\037option\037\002 for more information "
- "on a specific option."
- ),
+ source.Reply(_("Sets various memo options. \037option\037 can be one of:"));
+
+ HelpWrapper help;
+ help.AddEntry("NOTIFY", _("Changes when you will be notified about new memos (only for nicknames)"));
+ help.AddEntry("LIMIT", _("Sets the maximum number of memos you can receive"));
+
+ source.Reply(" ");
+ help.SendTo(source);
+
+ source.Reply(" ");
+ source.Reply(_("Type \002%s\032\037option\037\002 for more information on a specific option."),
source.service->GetQueryCommand("generic/help", source.command).c_str());
}
else if (subcommand.equals_ci("NOTIFY"))
@@ -245,26 +244,21 @@ public:
"Syntax: \002NOTIFY {ON | LOGON | NEW | MAIL | NOMAIL | OFF}\002"
"\n\n"
"Changes when you will be notified about new memos:"
- "\n\n"
- " ON You will be notified of memos when you log on,\n"
- " when you unset /AWAY, and when they are sent\n"
- " to you."
- "\n\n"
- " LOGON You will only be notified of memos when you log\n"
- " on or when you unset /AWAY."
- "\n\n"
- " NEW You will only be notified of memos when they\n"
- " are sent to you."
- "\n\n"
- " MAIL You will be notified of memos by email as well as\n"
- " any other settings you have."
- "\n\n"
- " NOMAIL You will not be notified of memos by email."
- "\n\n"
- " OFF You will not receive any notification of memos."
- "\n\n"
- "\002ON\002 is essentially \002LOGON\002 and \002NEW\002 combined."
));
+
+ HelpWrapper help;
+ help.AddEntry("ON", _("You will be notified of memos when you log on, when you unset /AWAY, and when they are sent to you."));
+ help.AddEntry("LOGON", _("You will only be notified of memos when you log on or when you unset /AWAY."));
+ help.AddEntry("NEW", _("You will only be notified of memos when they are sent to you."));
+ help.AddEntry("MAIL", _("You will be notified of memos by email as well as any other settings you have."));
+ help.AddEntry("NOMAIL", _("You will not be notified of memos by email."));
+ help.AddEntry("OFF", _("You will not receive any notification of memos."));
+
+ source.Reply(" ");
+ help.SendTo(source);
+
+ source.Reply(" ");
+ source.Reply(_("\002ON\002 is essentially \002LOGON\002 and \002NEW\002 combined."));
}
else if (subcommand.equals_ci("LIMIT"))
{
diff --git a/modules/nickserv/ns_register.cpp b/modules/nickserv/ns_register.cpp
index bfa528bd5..55f79772d 100644
--- a/modules/nickserv/ns_register.cpp
+++ b/modules/nickserv/ns_register.cpp
@@ -376,10 +376,10 @@ public:
return true;
}
- void OnServHelp(CommandSource &source) override
+ void OnServHelp(CommandSource &source, HelpWrapper &help) override
{
if (Config->GetModule(this->owner).Get<const Anope::string>("registration").equals_ci("mail"))
- Command::OnServHelp(source);
+ Command::OnServHelp(source, help);
}
};
diff --git a/modules/nickserv/ns_set.cpp b/modules/nickserv/ns_set.cpp
index d1fefecab..200430988 100644
--- a/modules/nickserv/ns_set.cpp
+++ b/modules/nickserv/ns_set.cpp
@@ -36,6 +36,8 @@ public:
Anope::string this_name = source.command;
bool hide_privileged_commands = Config->GetBlock("options").Get<bool>("hideprivilegedcommands"),
hide_registered_commands = Config->GetBlock("options").Get<bool>("hideregisteredcommands");
+
+ HelpWrapper help;
for (const auto &[c_name, info] : source.service->commands)
{
if (c_name.find_ci(this_name + " ") == 0)
@@ -53,9 +55,10 @@ public:
continue;
source.command = c_name;
- c->OnServHelp(source);
+ c->OnServHelp(source, help);
}
}
+ help.SendTo(source);
source.Reply(_("Type \002%s\032\037option\037\002 for more information on a specific option."),
source.service->GetQueryCommand("generic/help", this_name).c_str());
@@ -86,6 +89,7 @@ public:
source.Reply(" ");
source.Reply(_("Sets various nickname options. \037option\037 can be one of:"));
+ HelpWrapper help;
Anope::string this_name = source.command;
for (const auto &[c_name, info] : source.service->commands)
{
@@ -95,10 +99,11 @@ public:
if (command)
{
source.command = c_name;
- command->OnServHelp(source);
+ command->OnServHelp(source, help);
}
}
}
+ help.SendTo(source);
source.Reply(_(
"Type \002%s\032\037option\037\002 for more information "
diff --git a/modules/nickserv/ns_set_misc.cpp b/modules/nickserv/ns_set_misc.cpp
index c7606cf85..ca048487c 100644
--- a/modules/nickserv/ns_set_misc.cpp
+++ b/modules/nickserv/ns_set_misc.cpp
@@ -153,12 +153,12 @@ public:
this->Run(source, source.nc->display, !params.empty() ? params[0] : "");
}
- void OnServHelp(CommandSource &source) override
+ void OnServHelp(CommandSource &source, HelpWrapper &help) override
{
if (descriptions.count(source.command))
{
this->SetDesc(descriptions[source.command]);
- Command::OnServHelp(source);
+ Command::OnServHelp(source, help);
}
}
diff --git a/modules/operserv/os_set.cpp b/modules/operserv/os_set.cpp
index ced5a9d97..a667bb7bb 100644
--- a/modules/operserv/os_set.cpp
+++ b/modules/operserv/os_set.cpp
@@ -200,13 +200,17 @@ public:
source.Reply(_(
"Sets various global services options. Option names "
"currently defined are:"
- "\n\n"
- " READONLY Set read-only or read-write mode\n"
- " DEBUG Activate or deactivate debug mode\n"
- " NOEXPIRE Activate or deactivate no expire mode\n"
- " SUPERADMIN Activate or deactivate super admin mode\n"
- " LIST List the options"
));
+
+ HelpWrapper help;
+ help.AddEntry("READONLY", "Set read-only or read-write mode");
+ help.AddEntry("DEBUG", "Activate or deactivate debug mode");
+ help.AddEntry("NOEXPIRE", "Activate or deactivate no expire mode");
+ help.AddEntry("SUPERADMIN", "Activate or deactivate super admin mode");
+ help.AddEntry("LIST", "List the options");
+
+ source.Reply(" ");
+ help.SendTo(source);
}
else if (subcommand.equals_ci("LIST"))
{
diff --git a/modules/rewrite.cpp b/modules/rewrite.cpp
index 28007dadd..94cacb8cc 100644
--- a/modules/rewrite.cpp
+++ b/modules/rewrite.cpp
@@ -129,13 +129,13 @@ public:
Log() << "rewrite: Unable to rewrite '" << source.command << (!params.empty() ? " " + params[0] : "") << "'";
}
- void OnServHelp(CommandSource &source) override
+ void OnServHelp(CommandSource &source, HelpWrapper &help) override
{
Rewrite *r = Rewrite::Find(!source.c ? source.service->nick : "", source.command);
if (r != NULL && !r->desc.empty())
{
this->SetDesc(r->desc);
- Command::OnServHelp(source);
+ Command::OnServHelp(source, help);
}
}
diff --git a/src/command.cpp b/src/command.cpp
index f307e8aa4..86d96a02e 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -198,9 +198,9 @@ const Anope::string Command::GetDesc(CommandSource &) const
return this->desc;
}
-void Command::OnServHelp(CommandSource &source)
+void Command::OnServHelp(CommandSource &source, HelpWrapper &help)
{
- source.Reply(" %-14s %s", source.command.c_str(), Language::Translate(source.nc, this->GetDesc(source).c_str()));
+ help.AddEntry(source.command, this->GetDesc(source));
}
bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; }
diff --git a/src/misc.cpp b/src/misc.cpp
index 40fac7db7..7b2759f90 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -264,8 +264,33 @@ void InfoFormatter::AddOption(const Anope::string &opt)
*optstr += Language::Translate(nc, opt.c_str());
}
-TextSplitter::TextSplitter(const Anope::string &t)
- : text(t)
+
+void HelpWrapper::AddEntry(const Anope::string &name, const Anope::string &desc)
+{
+ entries.emplace_back(name, desc);
+ if (name.length() > longest)
+ longest = name.length();
+}
+
+void HelpWrapper::SendTo(CommandSource &source)
+{
+ const auto max_length = Config->GetBlock("options").Get<size_t>("linelength", "100") - longest - 8;
+ for (const auto &[entry_name, entry_desc] : entries)
+ {
+ TextSplitter splitter(Language::Translate(source.nc, entry_desc.c_str()), max_length);
+
+ Anope::string line;
+ if (splitter.GetLine(line))
+ source.Reply(" %-*s %s", (int)longest, entry_name.c_str(), line.c_str());
+
+ while (splitter.GetLine(line))
+ source.Reply(" %-*s %s", (int)longest, "", line.c_str());
+ }
+};
+
+TextSplitter::TextSplitter(const Anope::string &t, size_t ml)
+ : max_length(ml ? ml : Config->GetBlock("options").Get<size_t>("linelength", "100"))
+ , text(t)
{
}
@@ -280,9 +305,6 @@ bool TextSplitter::GetLine(Anope::string &out)
for (const auto &fmt : formatting)
out.append(fmt);
- // The maximum length of a line.
- const auto max_length = Config->GetBlock("options").Get<size_t>("linelength", "100");
-
// The current printable length of the output.
size_t current_length = 0;
diff --git a/src/users.cpp b/src/users.cpp
index 33e840160..c252e51d7 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -21,7 +21,6 @@
#include "opertype.h"
#include "language.h"
#include "sockets.h"
-#include "textproc.h"
#include "uplink.h"
user_map UserListByNick, UserListByUID;