Anope IRC Services  Version 2.0
bs_info.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  */
13 #include "module.h"
14 
15 class CommandBSInfo : public Command
16 {
17  private:
18  void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi)
19  {
20  Anope::string buf;
21  for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
22  {
23  const ChannelInfo *ci = it->second;
24 
25  if (ci->bi == bi)
26  {
27  buf += " " + ci->name + " ";
28  if (buf.length() > 300)
29  {
30  buffers.push_back(buf);
31  buf.clear();
32  }
33  }
34  }
35  if (!buf.empty())
36  buffers.push_back(buf);
37  }
38 
39  public:
40  CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1)
41  {
42  this->SetSyntax(_("{\037channel\037 | \037nickname\037}"));
43  }
44 
45  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
46  {
47  const Anope::string &query = params[0];
48 
49  BotInfo *bi = BotInfo::Find(query, true);
51  InfoFormatter info(source.nc);
52 
53  if (bi)
54  {
55  source.Reply(_("Information for bot \002%s\002:"), bi->nick.c_str());
56  info[_("Mask")] = bi->GetIdent() + "@" + bi->host;
57  info[_("Real name")] = bi->realname;
58  info[_("Created")] = Anope::strftime(bi->created, source.GetAccount());
59  info[_("Options")] = bi->oper_only ? _("Private") : _("None");
60  info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)";
61 
62  FOREACH_MOD(OnBotInfo, (source, bi, ci, info));
63 
64  std::vector<Anope::string> replies;
65  info.Process(replies);
66 
67  for (unsigned i = 0; i < replies.size(); ++i)
68  source.Reply(replies[i]);
69 
70  if (source.HasPriv("botserv/administration"))
71  {
72  std::vector<Anope::string> buf;
73  this->send_bot_channels(buf, bi);
74  for (unsigned i = 0; i < buf.size(); ++i)
75  source.Reply(buf[i]);
76  }
77 
78  }
79  else if (ci)
80  {
81  if (!source.AccessFor(ci).HasPriv("INFO") && !source.HasPriv("botserv/administration"))
82  {
83  source.Reply(ACCESS_DENIED);
84  return;
85  }
86 
87  source.Reply(CHAN_INFO_HEADER, ci->name.c_str());
88  info[_("Bot nick")] = ci->bi ? ci->bi->nick : _("not assigned yet");
89 
90  Anope::string enabled = Language::Translate(source.nc, _("Enabled"));
91  Anope::string disabled = Language::Translate(source.nc, _("Disabled"));
92 
93  FOREACH_MOD(OnBotInfo, (source, bi, ci, info));
94 
95  std::vector<Anope::string> replies;
96  info.Process(replies);
97 
98  for (unsigned i = 0; i < replies.size(); ++i)
99  source.Reply(replies[i]);
100  }
101  else
102  source.Reply(_("\002%s\002 is not a valid bot or registered channel."), query.c_str());
103  }
104 
105  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
106  {
107  this->SendSyntax(source);
108  source.Reply(" ");
109  source.Reply(_("Allows you to see %s information about a channel or a bot.\n"
110  "If the parameter is a channel, then you'll get information\n"
111  "such as enabled kickers. If the parameter is a nick,\n"
112  "you'll get information about a bot, such as creation\n"
113  "time or number of channels it is on."), source.service->nick.c_str());
114  return true;
115  }
116 
118  {
119  return Anope::printf(Language::Translate(source.GetAccount(), _("Allows you to see %s information about a channel or a bot")), source.service->nick.c_str());
120  }
121 };
122 
123 class BSInfo : public Module
124 {
126 
127  public:
128  BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
129  commandbsinfo(this)
130  {
131 
132  }
133 };
134 
Definition: bots.h:24
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: bs_info.cpp:45
const Anope::string & GetIdent() const
Definition: users.cpp:264
void send_bot_channels(std::vector< Anope::string > &buffers, const BotInfo *bi)
Definition: bs_info.cpp:18
Definition: hashcomp.h:84
void clear()
Definition: anope.h:187
Anope::string name
Definition: regchannel.h:63
void push_back(char c)
Definition: anope.h:142
#define ACCESS_DENIED
Definition: language.h:73
CoreExport string printf(const char *fmt,...)
Definition: misc.cpp:536
void Process(std::vector< Anope::string > &)
Definition: misc.cpp:222
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
size_type length() const
Definition: anope.h:131
CommandBSInfo(Module *creator)
Definition: bs_info.cpp:40
unsigned GetChannelCount() const
Definition: bots.cpp:188
CoreExport Serialize::Checker< registered_channel_map > RegisteredChannelList
BSInfo(const Anope::string &modname, const Anope::string &creator)
Definition: bs_info.cpp:128
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
Anope::string host
Definition: users.h:65
#define MODULE_INIT(x)
Definition: modules.h:45
CoreExport const char * Translate(const char *string)
Definition: language.cpp:59
time_t created
Definition: bots.h:29
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#define CHAN_INFO_HEADER
Definition: language.h:109
Anope::string stringify(const T &x)
Definition: anope.h:710
Anope::string realname
Definition: users.h:71
bool oper_only
Definition: bots.h:41
Anope::string nick
Definition: users.h:62
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
CoreExport Anope::string strftime(time_t t, const NickCore *nc=NULL, bool short_output=false)
Definition: misc.cpp:356
Serialize::Reference< BotInfo > bi
Definition: regchannel.h:82
const Anope::string GetDesc(CommandSource &source) const anope_override
Definition: bs_info.cpp:117
#define _(x)
Definition: services.h:50
static BotInfo * Find(const Anope::string &nick, bool nick_only=false)
Definition: bots.cpp:249
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: bs_info.cpp:105
CommandBSInfo commandbsinfo
Definition: bs_info.cpp:125