Anope IRC Services  Version 2.0
bs_botlist.cpp
Go to the documentation of this file.
1 /* BotServ core functions
2  *
3  * (C) 2003-2014 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;
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 {
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 
Definition: bots.h:24
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: bs_botlist.cpp:22
const Anope::string & GetIdent() const
Definition: users.cpp:264
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: bs_botlist.cpp:60
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
std::map< Anope::string, Anope::string > ListEntry
Definition: lists.h:68
CoreExport Serialize::Checker< botinfo_map > BotListByNick
#define anope_override
Definition: services.h:56
CommandBSBotList(Module *creator)
Definition: bs_botlist.cpp:17
Anope::string host
Definition: users.h:65
#define MODULE_INIT(x)
Definition: modules.h:45
bool oper_only
Definition: bots.h:41
Anope::string nick
Definition: users.h:62
void SendSyntax(CommandSource &)
Definition: command.cpp:145
CommandBSBotList commandbsbotlist
Definition: bs_botlist.cpp:72
#define _(x)
Definition: services.h:50
ListFormatter & AddColumn(const Anope::string &name)
Definition: misc.cpp:128
BSBotList(const Anope::string &modname, const Anope::string &creator)
Definition: bs_botlist.cpp:75