1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 15:44:46 +02:00

Allow specifying the order of ns_set_misc entries.

This commit is contained in:
Kufat
2026-06-08 04:36:18 -04:00
committed by GitHub
parent 9280d90aba
commit d1f6da1817
5 changed files with 23 additions and 9 deletions
+3
View File
@@ -747,6 +747,9 @@ command { service = "NickServ"; name = "SASET LAYOUT"; command = "nickserv/saset
*
* misc_description: A description of the command to show in the help.
* misc_title: A human-readable description of the stored data.
* misc_priority: Positive integer representing display order in nickserv/info
* and (if enabled) WHOIS output. Entries with unspecified
* priority will be prioritized in the order of declaration.
* misc_pattern: If defined then a regex pattern (using the engine specified
* in <options:regexengine> to validate the data with).
* misc_syntax: If defined then the syntax to show in the help output and, if
+1 -1
View File
@@ -279,7 +279,7 @@ public:
virtual void SendSVSHold(const Anope::string &, time_t) { }
virtual void SendSVSHoldDel(const Anope::string &) { }
virtual void SendSWhois(const MessageSource &source, User *target, const Anope::string &tag, const Anope::string &message) { };
virtual void SendSWhois(const MessageSource &source, User *target, const Anope::string &tag, time_t priority, const Anope::string &message) { };
virtual void SendSWhoisDel(const MessageSource &source, User *target, const Anope::string &tag, const Anope::string &message) { }
/** Introduces a server to the uplink
+16 -5
View File
@@ -26,14 +26,15 @@ struct CommandData final
Anope::string pattern;
Anope::string syntax;
Anope::string title;
time_t priority = 0;
bool swhois = false;
};
static Anope::map<CommandData> command_data;
struct NSMiscData;
static Anope::map<ExtensibleItem<NSMiscData> *> items;
static std::vector<std::pair<time_t, ExtensibleItem<NSMiscData> *>> items_by_priority;
static ExtensibleItem<NSMiscData> *GetItem(const Anope::string &name)
{
@@ -132,7 +133,7 @@ static void CheckSWhois(User* u, const Anope::string &name, ExtensibleItem<NSMis
auto *nc = u->Account();
auto *data = nc ? ext->Get(nc) : nullptr;
if (data)
IRCD->SendSWhois(nickserv, u, name, Anope::Format("%s: %s", GetTitle(ext), data->data.c_str()));
IRCD->SendSWhois(nickserv, u, name, it->second.priority, Anope::Format("%s: %s", GetTitle(ext), data->data.c_str()));
else
IRCD->SendSWhoisDel(nickserv, u, name, "");
}
@@ -327,6 +328,8 @@ public:
void OnReload(Configuration::Conf &conf) override
{
command_data.clear();
items_by_priority.clear();
for (int i = 0; i < conf.CountBlock("command"); ++i)
{
const auto &block = conf.GetBlock("command", i);
@@ -341,7 +344,7 @@ public:
// Force creation of the extension item.
const auto extname = GetAttribute(cname);
GetItem(extname);
auto item = GetItem(extname);
auto &data = command_data[extname];
if (cmd == "nickserv/saset/misc")
@@ -354,8 +357,16 @@ public:
data.pattern = block.Get<const Anope::string>("misc_pattern");
data.syntax = block.Get<const Anope::string>("misc_syntax");
data.title = block.Get<const Anope::string>("misc_title");
data.swhois = block.Get<bool>("misc_swhois");
data.priority = block.Get<time_t>("misc_priority", "0");
if (data.priority <= 0)
{
// If no priority is specified, go by order processed
data.priority = i * 1000;
}
data.swhois = block.Get<bool>("misc_swhois");
items_by_priority.emplace_back(data.priority, item);
}
std::sort(items_by_priority.begin(), items_by_priority.end());
}
void OnUserLogin(User *u) override
@@ -374,7 +385,7 @@ public:
void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool) override
{
for (const auto &[_, e] : items)
for (const auto &[_, e] : items_by_priority)
{
NSMiscData *data = e->Get(na->nc);
+2 -2
View File
@@ -587,7 +587,7 @@ public:
Uplink::Send(source, "SVSPART", u->GetUID(), chan);
}
void SendSWhois(const MessageSource &source, User *target, const Anope::string &tag, const Anope::string &message) override
void SendSWhois(const MessageSource &source, User *target, const Anope::string &tag, time_t priority, const Anope::string &message) override
{
if (!IRCD->CanSendMultipleSWhois)
{
@@ -598,7 +598,7 @@ public:
{
// New style SWHOIS.
Uplink::Send("METADATA", target->GetUID(), "specialwhois", Anope::Format("+ @%s s %ld :%s",
tag.c_str(), Anope::CurTime, message.c_str()));
tag.c_str(), priority ? priority : Anope::CurTime, message.c_str()));
}
}
+2 -2
View File
@@ -346,10 +346,10 @@ private:
Uplink::Send("SENDUMODE", 'o', "From " + source.GetName() + ": " + buf);
}
void SendSWhois(const MessageSource &source, User *target, const Anope::string &tag, const Anope::string &message) override
void SendSWhois(const MessageSource &source, User *target, const Anope::string &tag, time_t priority, const Anope::string &message) override
{
const auto utag = tag.empty() ? source.GetName() : tag;
Uplink::Send(source, "SWHOIS", target->GetUID(), "+", utag, 0, message);
Uplink::Send(source, "SWHOIS", target->GetUID(), "+", utag, priority, message);
}
void SendSWhoisDel(const MessageSource &source, User *target, const Anope::string &tag, const Anope::string &message) override