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