1
0
mirror of https://github.com/anope/anope.git synced 2026-06-28 12:26:36 +02:00
Files
anope/modules/webcpanel/pages/nickserv/alist.cpp
T
Sadie Powell 29e7674e56 Replace convertTo/stringify with non-throwing alternatives.
Having these throw is terrible for ergonomics and there are loads
of places where the exception was either silently ignored or not
handled at all. Having a function which returns an optional and
another that returns a default works a lot better imo.
2024-03-11 19:17:29 +00:00

56 lines
1.5 KiB
C++

/*
* (C) 2003-2024 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*/
#include "../../webcpanel.h"
static bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2)
{
return ci::less()(ci1->name, ci2->name);
}
WebCPanel::NickServ::Alist::Alist(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
{
}
bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
{
std::deque<ChannelInfo *> queue;
na->nc->GetChannelReferences(queue);
std::sort(queue.begin(), queue.end(), ChannelSort);
int chan_count = 0;
for (auto *ci : queue)
{
if (ci->GetFounder() == na->nc)
{
++chan_count;
replacements["NUMBERS"] = Anope::ToString(chan_count);
replacements["CHANNELS"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
replacements["ACCESSES"] = "Founder";
continue;
}
AccessGroup access = ci->AccessFor(na->nc);
if (access.empty())
continue;
++chan_count;
replacements["NUMBERS"] = Anope::ToString(chan_count);
replacements["CHANNELS"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
const ChanAccess *highest = access.Highest();
replacements["ACCESSES"] = highest ? highest->AccessSerialize() : "";
}
TemplateFileServer page("nickserv/alist.html");
page.Serve(server, page_name, client, message, reply, replacements);
return true;
}