anope

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

bs_botlist.cpp (1998B)

      1 /* BotServ 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 CommandBSBotList : public Command
     15 {
     16  public:
     17 	CommandBSBotList(Module *creator) : Command(creator, "botserv/botlist", 0, 0)
     18 	{
     19 		this->SetDesc(_("Lists available bots"));
     20 	}
     21 
     22 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     23 	{
     24 		unsigned count = 0;
     25 		ListFormatter list(source.GetAccount());
     26 
     27 		list.AddColumn(_("Nick")).AddColumn(_("Mask"));
     28 
     29 		for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
     30 		{
     31 			BotInfo *bi = it->second;
     32 
     33 			if (source.HasPriv("botserv/administration") || !bi->oper_only)
     34 			{
     35 				++count;
     36 				ListFormatter::ListEntry entry;
     37 				entry["Nick"] = (bi->oper_only ? "* " : "") + bi->nick;
     38 				entry["Mask"] = bi->GetIdent() + "@" + bi->host;
     39 				list.AddEntry(entry);
     40 			}
     41 		}
     42 
     43 		std::vector<Anope::string> replies;
     44 		list.Process(replies);
     45 
     46 		if (!count)
     47 			source.Reply(_("There are no bots available at this time.\n"
     48 					"Ask a Services Operator to create one!"));
     49 		else
     50 		{
     51 			source.Reply(_("Bot list:"));
     52 
     53 			for (unsigned i = 0; i < replies.size(); ++i)
     54 				source.Reply(replies[i]);
     55 
     56 			source.Reply(_("%d bots available."), count);
     57 		}
     58 	}
     59 
     60 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     61 	{
     62 		this->SendSyntax(source);
     63 		source.Reply(" ");
     64 		source.Reply(_("Lists all available bots on this network.\n"
     65 				"Bots prefixed by a * are reserved for IRC Operators."));
     66 		return true;
     67 	}
     68 };
     69 
     70 class BSBotList : public Module
     71 {
     72 	CommandBSBotList commandbsbotlist;
     73 
     74  public:
     75 	BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
     76 		commandbsbotlist(this)
     77 	{
     78 
     79 	}
     80 };
     81 
     82 MODULE_INIT(BSBotList)