anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

ns_alist.cpp (3808B)

      1 /* NickServ core functions
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #include "module.h"
     13 
     14 class CommandNSAList : public Command
     15 {
     16 	static bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2)
     17 	{
     18 		return ci::less()(ci1->name, ci2->name);
     19 	}
     20 
     21  public:
     22 	CommandNSAList(Module *creator) : Command(creator, "nickserv/alist", 0, 2)
     23 	{
     24 		this->SetDesc(_("List channels you have access on"));
     25 		this->SetSyntax(_("[\037nickname\037]"));
     26 	}
     27 
     28 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     29 	{
     30 		Anope::string nick = source.GetNick();
     31 		NickCore *nc = source.nc;
     32 
     33 		if (params.size() && source.HasPriv("nickserv/alist"))
     34 		{
     35 			nick = params[0];
     36 			const NickAlias *na = NickAlias::Find(nick);
     37 			if (!na)
     38 			{
     39 				source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
     40 				return;
     41 			}
     42 			nc = na->nc;
     43 		}
     44 
     45 		ListFormatter list(source.GetAccount());
     46 		int chan_count = 0;
     47 
     48 		list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Access")).AddColumn(_("Description"));
     49 
     50 		std::deque<ChannelInfo *> queue;
     51 		nc->GetChannelReferences(queue);
     52 		std::sort(queue.begin(), queue.end(), ChannelSort);
     53 
     54 		for (unsigned i = 0; i < queue.size(); ++i)
     55 		{
     56 			ChannelInfo *ci = queue[i];
     57 			ListFormatter::ListEntry entry;
     58 
     59 			if (ci->GetFounder() == nc)
     60 			{
     61 				++chan_count;
     62 				entry["Number"] = stringify(chan_count);
     63 				entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
     64 				entry["Access"] = Language::Translate(source.GetAccount(), _("Founder"));
     65 				entry["Description"] = ci->desc;
     66 				list.AddEntry(entry);
     67 				continue;
     68 			}
     69 
     70 			if (ci->GetSuccessor() == nc)
     71 			{
     72 				++chan_count;
     73 				entry["Number"] = stringify(chan_count);
     74 				entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
     75 				entry["Access"] = Language::Translate(source.GetAccount(), _("Successor"));
     76 				entry["Description"] = ci->desc;
     77 				list.AddEntry(entry);
     78 				continue;
     79 			}
     80 
     81 			AccessGroup access = ci->AccessFor(nc, false);
     82 			if (access.empty())
     83 				continue;
     84 
     85 			++chan_count;
     86 
     87 			entry["Number"] = stringify(chan_count);
     88 			entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name;
     89 			for (unsigned j = 0; j < access.paths.size(); ++j)
     90 			{
     91 				ChanAccess::Path &p = access.paths[j];
     92 
     93 				// not interested in indirect access
     94 				if (p.size() != 1)
     95 					continue;
     96 
     97 				ChanAccess *a = p[0];
     98 				entry["Access"] = entry["Access"] + ", " + a->AccessSerialize();
     99 			}
    100 			entry["Access"] = entry["Access"].substr(2);
    101 			entry["Description"] = ci->desc;
    102 			list.AddEntry(entry);
    103 		}
    104 
    105 		std::vector<Anope::string> replies;
    106 		list.Process(replies);
    107 
    108 		if (!chan_count)
    109 		{
    110 			source.Reply(_("\002%s\002 has no access in any channels."), nc->display.c_str());
    111 		}
    112 		else
    113 		{
    114 			source.Reply(_("Channels that \002%s\002 has access on:"), nc->display.c_str());
    115 
    116 			for (unsigned i = 0; i < replies.size(); ++i)
    117 				source.Reply(replies[i]);
    118 
    119 			source.Reply(_("End of list - %d channels shown."), chan_count);
    120 		}
    121 	}
    122 
    123 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    124 	{
    125 		this->SendSyntax(source);
    126 		source.Reply(" ");
    127 		source.Reply(_("Lists all channels you have access on.\n"
    128 				" \n"
    129 				"Channels that have the \037NOEXPIRE\037 option set will be\n"
    130 				"prefixed by an exclamation mark. The nickname parameter is\n"
    131 				"limited to Services Operators"));
    132 
    133 		return true;
    134 	}
    135 };
    136 
    137 class NSAList : public Module
    138 {
    139 	CommandNSAList commandnsalist;
    140 
    141  public:
    142 	NSAList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    143 		commandnsalist(this)
    144 	{
    145 
    146 	}
    147 };
    148 
    149 MODULE_INIT(NSAList)