mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Automatically wrap the help output.
This commit is contained in:
+2
-1
@@ -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
|
||||
|
||||
+16
-4
@@ -11,14 +11,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
class TextSplitter final
|
||||
class CoreExport HelpWrapper final
|
||||
{
|
||||
private:
|
||||
Anope::string text;
|
||||
std::vector<Anope::string> formatting;
|
||||
std::vector<std::pair<Anope::string, Anope::string>> entries;
|
||||
size_t longest = 0;
|
||||
|
||||
public:
|
||||
TextSplitter(const Anope::string &t);
|
||||
void AddEntry(const Anope::string &name, const Anope::string &desc);
|
||||
void SendTo(CommandSource &source);
|
||||
};
|
||||
|
||||
class CoreExport TextSplitter final
|
||||
{
|
||||
private:
|
||||
std::vector<Anope::string> formatting;
|
||||
const size_t max_length;
|
||||
Anope::string text;
|
||||
|
||||
public:
|
||||
TextSplitter(const Anope::string &t, size_t ml = 0);
|
||||
bool GetLine(Anope::string &out);
|
||||
};
|
||||
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -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)
|
||||
{
|
||||
|
||||
+25
-31
@@ -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"))
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"))
|
||||
{
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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; }
|
||||
|
||||
+27
-5
@@ -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;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "opertype.h"
|
||||
#include "language.h"
|
||||
#include "sockets.h"
|
||||
#include "textproc.h"
|
||||
#include "uplink.h"
|
||||
|
||||
user_map UserListByNick, UserListByUID;
|
||||
|
||||
Reference in New Issue
Block a user