1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 18:54:47 +02:00

Allow syntax messages to take a predicate.

This commit is contained in:
Sadie Powell
2025-04-19 16:43:21 +01:00
parent 18dfa62626
commit 70bf013ef0
7 changed files with 73 additions and 60 deletions
+2 -2
View File
@@ -97,7 +97,7 @@ class CoreExport Command
: public Service
{
Anope::string desc;
std::vector<Anope::string> syntax;
std::vector<std::pair<Anope::string, std::function<bool(CommandSource&)>>> syntax;
/* Allow unregistered users to use this command */
bool allow_unregistered;
/* Command requires that a user is executing it */
@@ -129,7 +129,7 @@ protected:
void SetDesc(const Anope::string &d);
void ClearSyntax();
void SetSyntax(const Anope::string &s);
void SetSyntax(const Anope::string &s, const std::function<bool(CommandSource&)> &p = nullptr);
void SendSyntax(CommandSource &);
void AllowUnregistered(bool b);
+1
View File
@@ -23,6 +23,7 @@
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
+15 -19
View File
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Anope\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-04-16 02:59+0100\n"
"POT-Creation-Date: 2025-04-19 16:53+0100\n"
"PO-Revision-Date: 2025-04-16 02:59+0100\n"
"Last-Translator: Sadie Powell <sadie@witchery.services>\n"
"Language-Team: English\n"
@@ -3198,6 +3198,9 @@ msgstr ""
msgid "Lists all nicknames in your group"
msgstr ""
msgid "Lists all nicks in your group."
msgstr ""
msgid "Lists all registered channels matching the given pattern"
msgstr ""
@@ -4321,6 +4324,9 @@ msgstr ""
msgid "Reverses kicker"
msgstr ""
msgid "Reverses the effect of the IDENTIFY command, i.e. make you not recognized as the real owner of the nick anymore. Note, however, that you won't be asked to reidentify yourself."
msgstr ""
msgid "Reverses the effect of the IDENTIFY command"
msgstr ""
@@ -4929,24 +4935,6 @@ msgstr ""
msgid "Syntax"
msgstr ""
#, c-format
msgid ""
"Syntax: %s\n"
"\n"
"Lists all nicks in your group."
msgstr ""
#, c-format
msgid ""
"Syntax: %s [nickname]\n"
"\n"
"Without a parameter, lists all nicknames that are in your group.\n"
"\n"
"With a parameter, lists all nicknames that are in the group of the given nick.\n"
"\n"
"Specifying a nick is limited to Services Operators."
msgstr ""
msgid ""
"Syntax: DEBUG {ON | OFF}\n"
"\n"
@@ -5781,6 +5769,14 @@ msgid ""
"With a nickname parameter, displays the same information for the given nickname. This is limited to Services Operators."
msgstr ""
msgid ""
"Without a parameter, lists all nicknames that are in your group.\n"
"\n"
"With a parameter, lists all nicknames that are in the group of the given nick.\n"
"\n"
"Specifying a nick is limited to Services Operators."
msgstr ""
msgid ""
"Without a parameter, reverses the effect of the IDENTIFY command, i.e. make you not recognized as the real owner of the nick anymore. Note, however, that you won't be asked to reidentify yourself.\n"
"\n"
-1
View File
@@ -9,7 +9,6 @@
* Based on the original code of Services by Andy Church.
*/
#include <functional>
#include "module.h"
#include "modules/botserv/badwords.h"
+11 -17
View File
@@ -312,6 +312,7 @@ public:
CommandNSGList(Module *creator) : Command(creator, "nickserv/glist", 0, 1)
{
this->SetDesc(_("Lists all nicknames in your group"));
this->SetSyntax(_("[\037nickname\037]"), [](auto &source) { return source.IsServicesOper(); });
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
@@ -372,29 +373,22 @@ public:
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
if (source.IsServicesOper())
{
source.Reply(_(
"Syntax: \002%s [\037nickname\037]\002"
"\n\n"
"Without a parameter, lists all nicknames that are in "
"your group."
"\n\n"
"With a parameter, lists all nicknames that are in the "
"group of the given nick."
"\n\n"
"Specifying a nick is limited to \002Services Operators\002."
),
source.command.c_str());
"Without a parameter, lists all nicknames that are in "
"your group."
"\n\n"
"With a parameter, lists all nicknames that are in the "
"group of the given nick."
"\n\n"
"Specifying a nick is limited to \002Services Operators\002."
));
}
else
{
source.Reply(_(
"Syntax: \002%s\002"
"\n\n"
"Lists all nicks in your group."
),
source.command.c_str());
source.Reply(_("Lists all nicks in your group."));
}
return true;
+22 -11
View File
@@ -20,7 +20,7 @@ public:
CommandNSLogout(Module *creator) : Command(creator, "nickserv/logout", 0, 2)
{
this->SetDesc(_("Reverses the effect of the IDENTIFY command"));
this->SetSyntax(_("[\037nickname\037 [REVALIDATE]]"));
this->SetSyntax(_("[\037nickname\037 [REVALIDATE]]"), [](auto &source) { return source.IsServicesOper(); });
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
@@ -64,17 +64,28 @@ public:
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_(
"Without a parameter, reverses the effect of the \002IDENTIFY\002 "
"command, i.e. make you not recognized as the real owner of the nick "
"anymore. Note, however, that you won't be asked to reidentify "
"yourself."
"\n\n"
"With a parameter, does the same for the given nick. If you "
"specify \002REVALIDATE\002 as well, services will ask the given nick "
"to re-identify. This is limited to \002Services Operators\002."
));
if (source.IsServicesOper())
{
source.Reply(_(
"Without a parameter, reverses the effect of the \002IDENTIFY\002 "
"command, i.e. make you not recognized as the real owner of the nick "
"anymore. Note, however, that you won't be asked to reidentify "
"yourself."
"\n\n"
"With a parameter, does the same for the given nick. If you "
"specify \002REVALIDATE\002 as well, services will ask the given nick "
"to re-identify. This is limited to \002Services Operators\002."
));
}
else
{
source.Reply(_(
"Reverses the effect of the \002IDENTIFY\002 command, i.e. make you not "
"recognized as the real owner of the nick anymore. Note, however, that "
"you won't be asked to reidentify yourself."
));
}
return true;
}
};
+22 -10
View File
@@ -154,23 +154,35 @@ void Command::ClearSyntax()
this->syntax.clear();
}
void Command::SetSyntax(const Anope::string &s)
void Command::SetSyntax(const Anope::string &s, const std::function<bool(CommandSource&)> &p)
{
this->syntax.push_back(s);
this->syntax.emplace_back(s, p);
}
void Command::SendSyntax(CommandSource &source)
{
Anope::string s = Language::Translate(source.GetAccount(), _("Syntax"));
if (!this->syntax.empty())
auto first = true;
Anope::string prefix = Language::Translate(source.GetAccount(), _("Syntax"));
for (const auto &[syntax, predicate] : this->syntax)
{
source.Reply("%s: \002%s %s\002", s.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[0].c_str()));
Anope::string spaces(s.length(), ' ');
for (unsigned i = 1, j = this->syntax.size(); i < j; ++i)
source.Reply("%s \002%s %s\002", spaces.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[i].c_str()));
if (predicate && !predicate(source))
continue; // Not for this user.
if (first)
{
first = false;
source.Reply("%s: \002%s %s\002", prefix.c_str(), source.command.c_str(),
Language::Translate(source.GetAccount(), syntax.c_str()));
}
else
{
source.Reply("%-*s \002%s %s\002", (int)prefix.length(), "", source.command.c_str(),
Language::Translate(source.GetAccount(), syntax.c_str()));
}
}
else
source.Reply("%s: \002%s\002", s.c_str(), source.command.c_str());
if (first)
source.Reply("%s: \002%s\002", prefix.c_str(), source.command.c_str());
}
bool Command::AllowUnregistered() const