mirror of
https://github.com/anope/anope.git
synced 2026-07-07 15:23:13 +02:00
Allow specifying the order of ns_set_misc entries.
This commit is contained in:
@@ -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.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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user