summaryrefslogtreecommitdiff
path: root/modules/commands/ns_alist.cpp
blob: 84af7caddcacb74e4e21b5259ae1bbe4b9696133 (plain)
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
/* NickServ core functions
 *
 * (C) 2003-2011 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 *
 * Based on the original code of Epona by Lara.
 * Based on the original code of Services by Andy Church.
 */

/*************************************************************************/

#include "module.h"

class CommandNSAList : public Command
{
 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> &params)
	{
		User *u = source.u;
		Anope::string nick = u->Account()->display;

		if (params.size() && u->IsServicesOper())
			nick = params[0];

		NickAlias *na = findnick(nick);

		if (!na)
			source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
		else
		{
			int chan_count = 0;

			source.Reply(_("Channels that \002%s\002 has access on:\n"
					"  Num  Channel              Access"), na->nick.c_str());

			for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
			{
				ChannelInfo *ci = it->second;

				if (ci->GetFounder() && ci->GetFounder() == na->nc)
				{
					source.Reply(_("  %3d %c%-20s Founder"), ++chan_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str());
					continue;
				}

				AccessGroup access = ci->AccessFor(na->nc);
				if (access.empty())
					continue;
				
				++chan_count;

				if (access.size() > 1)
				{
					source.Reply(_("  %3d You match %d access entries on %c%s, they are"), chan_count, access.size(), ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str());
					for (unsigned i = 0; i < access.size(); ++i)
						source.Reply(_("  %3d %-8s"), i + 1, access[i]->Serialize().c_str());
				}
				else
					source.Reply(_("  %3d %c%-20s %-8s"), chan_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), access[0]->Serialize().c_str());
			}

			source.Reply(_("End of list - %d channels shown."), chan_count);
		}
	}

	bool OnHelp(CommandSource &source, const Anope::string &subcommand)
	{
		this->SendSyntax(source);
		source.Reply(" ");
		source.Reply(_("Lists all channels you have access on.\n"
				" \n"
				"Channels that have the \037NOEXPIRE\037 option set will be\n"
				"prefixed by an exclamation mark. The nickname parameter is\n"
				"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, CORE),
		commandnsalist(this)
	{
		this->SetAuthor("Anope");

	}
};

MODULE_INIT(NSAList)