00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "module.h"
00016
00017 class CommandBSInfo : public Command
00018 {
00019 private:
00020 void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi)
00021 {
00022 Anope::string buf;
00023 for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
00024 {
00025 const ChannelInfo *ci = it->second;
00026
00027 if (ci->bi == bi)
00028 {
00029 buf += " " + ci->name + " ";
00030 if (buf.length() > 300)
00031 {
00032 buffers.push_back(buf);
00033 buf.clear();
00034 }
00035 }
00036 }
00037 if (!buf.empty())
00038 buffers.push_back(buf);
00039 }
00040
00041 void CheckOptStr(Anope::string &buf, const Anope::string &flag, const char *option, Extensible *flags, const NickCore *nc)
00042 {
00043 if (flags->HasExt(flag))
00044 {
00045 if (!buf.empty())
00046 buf += ", ";
00047 buf += Language::Translate(nc, option);
00048 }
00049 }
00050
00051 public:
00052 CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1)
00053 {
00054 this->SetDesc(_("Allows you to see BotServ information about a channel or a bot"));
00055 this->SetSyntax(_("{\037chan\037|\037nick\037}"));
00056 }
00057
00058 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00059 {
00060 const Anope::string &query = params[0];
00061
00062 const BotInfo *bi = BotInfo::Find(query, true);
00063 ChannelInfo *ci;
00064 InfoFormatter info(source.nc);
00065
00066 if (bi)
00067 {
00068 source.Reply(_("Information for bot \002%s\002:"), bi->nick.c_str());
00069 info[_("Mask")] = bi->GetIdent() + "@" + bi->host;
00070 info[_("Real name")] = bi->realname;
00071 info[_("Created")] = Anope::strftime(bi->created);
00072 info[_("Options")] = bi->oper_only ? _("Private") : _("None");
00073 info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)";
00074
00075 std::vector<Anope::string> replies;
00076 info.Process(replies);
00077
00078 for (unsigned i = 0; i < replies.size(); ++i)
00079 source.Reply(replies[i]);
00080
00081 if (source.HasPriv("botserv/administration"))
00082 {
00083 std::vector<Anope::string> buf;
00084 this->send_bot_channels(buf, bi);
00085 for (unsigned i = 0; i < buf.size(); ++i)
00086 source.Reply(buf[i]);
00087 }
00088
00089 }
00090 else if ((ci = ChannelInfo::Find(query)))
00091 {
00092 if (!source.AccessFor(ci).HasPriv("INFO") && !source.HasPriv("botserv/administration"))
00093 {
00094 source.Reply(ACCESS_DENIED);
00095 return;
00096 }
00097
00098 source.Reply(CHAN_INFO_HEADER, ci->name.c_str());
00099 info[_("Bot nick")] = ci->bi ? ci->bi->nick : "not assigned yet";
00100
00101 Anope::string enabled = Language::Translate(source.nc, _("Enabled"));
00102 Anope::string disabled = Language::Translate(source.nc, _("Disabled"));
00103
00104 if (ci->HasExt("BS_KICK_BADWORDS"))
00105 {
00106 if (ci->ttb[TTB_BADWORDS])
00107 info[_("Bad words kicker")] = Anope::printf("%s (%d kick(s) to ban)", enabled.c_str(), ci->ttb[TTB_BADWORDS]);
00108 else
00109 info[_("Bad words kicker")] = enabled;
00110 }
00111 else
00112 info[_("Bad words kicker")] = disabled;
00113
00114 if (ci->HasExt("BS_KICK_BOLDS"))
00115 {
00116 if (ci->ttb[TTB_BOLDS])
00117 info[_("Bolds kicker")] = Anope::printf("%s (%d kick(s) to ban)", enabled.c_str(), ci->ttb[TTB_BOLDS]);
00118 else
00119 info[_("Bolds kicker")] = enabled;
00120 }
00121 else
00122 info[_("Bolds kicker")] = disabled;
00123
00124 if (ci->HasExt("BS_KICK_CAPS"))
00125 {
00126 if (ci->ttb[TTB_CAPS])
00127 info[_("Caps kicker")] = Anope::printf(_("%s (%d kick(s) to ban; minimum %d/%d%%"), enabled.c_str(), ci->ttb[TTB_CAPS], ci->capsmin, ci->capspercent);
00128 else
00129 info[_("Caps kicker")] = Anope::printf(_("%s (minimum %d/%d%%)"), enabled.c_str(), ci->capsmin, ci->capspercent);
00130 }
00131 else
00132 info[_("Caps kicker")] = disabled;
00133
00134 if (ci->HasExt("BS_KICK_COLORS"))
00135 {
00136 if (ci->ttb[TTB_COLORS])
00137 info[_("Colors kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_COLORS]);
00138 else
00139 info[_("Colors kicker")] = enabled;
00140 }
00141 else
00142 info[_("Colors kicker")] = disabled;
00143
00144 if (ci->HasExt("BS_KICK_FLOOD"))
00145 {
00146 if (ci->ttb[TTB_FLOOD])
00147 info[_("Flood kicker")] = Anope::printf(_("%s (%d kick(s) to ban; %d lines in %ds"), enabled.c_str(), ci->ttb[TTB_FLOOD], ci->floodlines, ci->floodsecs);
00148 else
00149 info[_("Flood kicker")] = Anope::printf(_("%s (%d lines in %ds)"), enabled.c_str(), ci->floodlines, ci->floodsecs);
00150 }
00151 else
00152 info[_("Flood kicker")] = disabled;
00153
00154 if (ci->HasExt("BS_KICK_REPEAT"))
00155 {
00156 if (ci->ttb[TTB_REPEAT])
00157 info[_("Repeat kicker")] = Anope::printf(_("%s (%d kick(s) to ban; %d times)"), enabled.c_str(), ci->ttb[TTB_REPEAT], ci->repeattimes);
00158 else
00159 info[_("Repeat kicker")] = Anope::printf(_("%s (%d times)"), enabled.c_str(), ci->repeattimes);
00160 }
00161 else
00162 info[_("Repeat kicker")] = disabled;
00163
00164 if (ci->HasExt("BS_KICK_REVERSES"))
00165 {
00166 if (ci->ttb[TTB_REVERSES])
00167 info[_("Reverses kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_REVERSES]);
00168 else
00169 info[_("Reverses kicker")] = enabled;
00170 }
00171 else
00172 info[_("Reverses kicker")] = disabled;
00173
00174 if (ci->HasExt("BS_KICK_UNDERLINES"))
00175 {
00176 if (ci->ttb[TTB_UNDERLINES])
00177 info[_("Underlines kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_UNDERLINES]);
00178 else
00179 info[_("Underlines kicker")] = enabled;
00180 }
00181 else
00182 info[_("Underlines kicker")] = disabled;
00183
00184 if (ci->HasExt("BS_KICK_ITALICS"))
00185 {
00186 if (ci->ttb[TTB_ITALICS])
00187 info[_("Italics kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_ITALICS]);
00188 else
00189 info[_("Italics kicker")] = enabled;
00190 }
00191 else
00192 info[_("Italics kicker")] = disabled;
00193
00194 if (ci->HasExt("BS_KICK_AMSGS"))
00195 {
00196 if (ci->ttb[TTB_AMSGS])
00197 info[_("AMSG kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_AMSGS]);
00198 else
00199 info[_("AMSG kicker")] = enabled;
00200 }
00201 else
00202 info[_("AMSG kicker")] = disabled;
00203
00204 Anope::string flags;
00205 CheckOptStr(flags, "BS_DONTKICKOPS", _("Ops protection"), ci, source.nc);
00206 CheckOptStr(flags, "BS_DONTKICKVOICES", _("Voices protection"), ci, source.nc);
00207 CheckOptStr(flags, "BS_FANTASY", _("Fantasy"), ci, source.nc);
00208 CheckOptStr(flags, "BS_GREET", _("Greet"), ci, source.nc);
00209 CheckOptStr(flags, "BS_NOBOT", _("No bot"), ci, source.nc);
00210
00211 info[_("Options")] = flags.empty() ? _("None") : flags;
00212
00213 std::vector<Anope::string> replies;
00214 info.Process(replies);
00215
00216 for (unsigned i = 0; i < replies.size(); ++i)
00217 source.Reply(replies[i]);
00218 }
00219 else
00220 source.Reply(_("\002%s\002 is not a valid bot or registered channel."), query.c_str());
00221 }
00222
00223 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00224 {
00225 this->SendSyntax(source);
00226 source.Reply(" ");
00227 source.Reply(_("Allows you to see %s information about a channel or a bot.\n"
00228 "If the parameter is a channel, then you'll get information\n"
00229 "such as enabled kickers. If the parameter is a nick,\n"
00230 "you'll get information about a bot, such as creation\n"
00231 "time or number of channels it is on."), source.service->nick.c_str());
00232 return true;
00233 }
00234 };
00235
00236 class BSInfo : public Module
00237 {
00238 CommandBSInfo commandbsinfo;
00239
00240 public:
00241 BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00242 commandbsinfo(this)
00243 {
00244 this->SetAuthor("Anope");
00245
00246 }
00247 };
00248
00249 MODULE_INIT(BSInfo)