1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*
* Anope IRC Services
*
* Copyright (C) 2003-2017 Anope Team <team@anope.org>
*
* This file is part of Anope. Anope is free software; you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software
* Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
#include "module.h"
class CommandNSAList : public Command
{
static bool ChannelSort(ChanServ::Channel *ci1, ChanServ::Channel *ci2)
{
return ci::less()(ci1->GetName(), ci2->GetName());
}
public:
CommandNSAList(Module *creator) : Command(creator, "nickserv/alist", 0, 2)
{
this->SetDesc(_("List channels you have access on"));
this->SetSyntax(_("[\037nickname\037]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
Anope::string nick = source.GetNick();
NickServ::Account *nc = source.nc;
if (params.size() && source.HasPriv("nickserv/alist"))
{
nick = params[0];
NickServ::Nick *na = NickServ::FindNick(nick);
if (!na)
{
source.Reply(_("\002{0}\002 isn't registered."), nick);
return;
}
nc = na->GetAccount();
}
ListFormatter list(source.GetAccount());
int chan_count = 0;
list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Access")).AddColumn(_("Description"));
std::vector<ChanServ::Channel *> chans = nc->GetRefs<ChanServ::Channel *>();
std::sort(chans.begin(), chans.end(), ChannelSort);
for (ChanServ::Channel *ci : chans)
{
ListFormatter::ListEntry entry;
if (ci->GetFounder() == nc)
{
++chan_count;
entry["Number"] = stringify(chan_count);
entry["Channel"] = (ci->IsNoExpire() ? "!" : "") + ci->GetName();
entry["Access"] = Language::Translate(source.GetAccount(), _("Founder"));
entry["Description"] = ci->GetDesc();
list.AddEntry(entry);
continue;
}
if (ci->GetSuccessor() == nc)
{
++chan_count;
entry["Number"] = stringify(chan_count);
entry["Channel"] = (ci->IsNoExpire() ? "!" : "") + ci->GetName();
entry["Access"] = Language::Translate(source.GetAccount(), _("Successor"));
entry["Description"] = ci->GetDesc();
list.AddEntry(entry);
continue;
}
ChanServ::AccessGroup access = ci->AccessFor(nc, false);
if (access.empty())
continue;
++chan_count;
entry["Number"] = stringify(chan_count);
entry["Channel"] = (ci->IsNoExpire() ? "!" : "") + ci->GetName();
for (unsigned j = 0; j < access.size(); ++j)
entry["Access"] = entry["Access"] + ", " + access[j]->AccessSerialize();
entry["Access"] = entry["Access"].substr(2);
entry["Description"] = ci->GetDesc();
list.AddEntry(entry);
}
std::vector<Anope::string> replies;
list.Process(replies);
if (!chan_count)
{
source.Reply(_("\002{0}\002 has no access in any channels."), nc->GetDisplay());
}
else
{
source.Reply(_("Channels that \002{0}\002 has access on:"), nc->GetDisplay());
for (unsigned i = 0; i < replies.size(); ++i)
source.Reply(replies[i]);
source.Reply(_("End of list - \002{0}\002 channels shown."), chan_count);
}
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(_("Lists all channels you have access on.\n"
" \n"
"Channels that have the \037NOEXPIRE\037 option set will be prefixed by an exclamation mark. The nickname parameter is limited to Services Operators"));
return true;
}
};
class NSAList : public Module
{
CommandNSAList commandnsalist;
public:
NSAList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
, commandnsalist(this)
{
}
};
MODULE_INIT(NSAList)
|