diff options
author | Sadie Powell <sadie@witchery.services> | 2025-04-19 16:43:21 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-04-19 16:54:26 +0100 |
commit | 70bf013ef0bf6c8ba60e85aacca2ec97848ca0b3 (patch) | |
tree | 70ae17296baa6de7bc7ffee105702b6e28584a5a | |
parent | 18dfa62626468c18177ba6ff24be34f4b64f1d37 (diff) |
Allow syntax messages to take a predicate.
-rw-r--r-- | include/commands.h | 4 | ||||
-rw-r--r-- | include/services.h | 1 | ||||
-rw-r--r-- | language/anope.en_US.po | 34 | ||||
-rw-r--r-- | modules/database/db_atheme.cpp | 1 | ||||
-rw-r--r-- | modules/nickserv/ns_group.cpp | 28 | ||||
-rw-r--r-- | modules/nickserv/ns_logout.cpp | 33 | ||||
-rw-r--r-- | src/command.cpp | 32 |
7 files changed, 73 insertions, 60 deletions
diff --git a/include/commands.h b/include/commands.h index 9692f438c..49a8e2183 100644 --- a/include/commands.h +++ b/include/commands.h @@ -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); diff --git a/include/services.h b/include/services.h index 7f0752d11..19b837581 100644 --- a/include/services.h +++ b/include/services.h @@ -23,6 +23,7 @@ #include <deque> #include <exception> #include <fstream> +#include <functional> #include <iostream> #include <list> #include <map> diff --git a/language/anope.en_US.po b/language/anope.en_US.po index 77f72b970..4644bcbce 100644 --- a/language/anope.en_US.po +++ b/language/anope.en_US.po @@ -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" @@ -5782,6 +5770,14 @@ msgid "" 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" "With a parameter, does the same for the given nick. If you specify REVALIDATE as well, services will ask the given nick to re-identify. This is limited to Services Operators." diff --git a/modules/database/db_atheme.cpp b/modules/database/db_atheme.cpp index 525173613..fccef4b36 100644 --- a/modules/database/db_atheme.cpp +++ b/modules/database/db_atheme.cpp @@ -9,7 +9,6 @@ * Based on the original code of Services by Andy Church. */ -#include <functional> #include "module.h" #include "modules/botserv/badwords.h" diff --git a/modules/nickserv/ns_group.cpp b/modules/nickserv/ns_group.cpp index e1cd7e46f..d84b8b703 100644 --- a/modules/nickserv/ns_group.cpp +++ b/modules/nickserv/ns_group.cpp @@ -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> ¶ms) 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; diff --git a/modules/nickserv/ns_logout.cpp b/modules/nickserv/ns_logout.cpp index c0095e95d..a5a6a2714 100644 --- a/modules/nickserv/ns_logout.cpp +++ b/modules/nickserv/ns_logout.cpp @@ -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> ¶ms) 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; } }; diff --git a/src/command.cpp b/src/command.cpp index 86d96a02e..b688803cc 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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 |