1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
/* BotServ core functions
*
* (C) 2003-2013 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
*
*/
/*************************************************************************/
#include "module.h"
class CommandBSInfo : public Command
{
private:
void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi)
{
Anope::string buf;
for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
const ChannelInfo *ci = it->second;
if (ci->bi == bi)
{
buf += " " + ci->name + " ";
if (buf.length() > 300)
{
buffers.push_back(buf);
buf.clear();
}
}
}
if (!buf.empty())
buffers.push_back(buf);
}
void CheckOptStr(Anope::string &buf, const Anope::string &flag, const char *option, Extensible *flags, const NickCore *nc)
{
if (flags->HasExt(flag))
{
if (!buf.empty())
buf += ", ";
buf += Language::Translate(nc, option);
}
}
public:
CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1)
{
this->SetDesc(_("Allows you to see BotServ information about a channel or a bot"));
this->SetSyntax(_("{\037chan\037|\037nick\037}"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
const Anope::string &query = params[0];
const BotInfo *bi = BotInfo::Find(query, true);
ChannelInfo *ci;
InfoFormatter info(source.nc);
if (bi)
{
source.Reply(_("Information for bot \002%s\002:"), bi->nick.c_str());
info[_("Mask")] = bi->GetIdent() + "@" + bi->host;
info[_("Real name")] = bi->realname;
info[_("Created")] = Anope::strftime(bi->created);
info[_("Options")] = bi->oper_only ? _("Private") : _("None");
info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)";
std::vector<Anope::string> replies;
info.Process(replies);
for (unsigned i = 0; i < replies.size(); ++i)
source.Reply(replies[i]);
if (source.HasPriv("botserv/administration"))
{
std::vector<Anope::string> buf;
this->send_bot_channels(buf, bi);
for (unsigned i = 0; i < buf.size(); ++i)
source.Reply(buf[i]);
}
}
else if ((ci = ChannelInfo::Find(query)))
{
if (!source.AccessFor(ci).HasPriv("INFO") && !source.HasPriv("botserv/administration"))
{
source.Reply(ACCESS_DENIED);
return;
}
source.Reply(CHAN_INFO_HEADER, ci->name.c_str());
info[_("Bot nick")] = ci->bi ? ci->bi->nick : "not assigned yet";
Anope::string enabled = Language::Translate(source.nc, _("Enabled"));
Anope::string disabled = Language::Translate(source.nc, _("Disabled"));
if (ci->HasExt("BS_KICK_BADWORDS"))
{
if (ci->ttb[TTB_BADWORDS])
info[_("Bad words kicker")] = Anope::printf("%s (%d kick(s) to ban)", enabled.c_str(), ci->ttb[TTB_BADWORDS]);
else
info[_("Bad words kicker")] = enabled;
}
else
info[_("Bad words kicker")] = disabled;
if (ci->HasExt("BS_KICK_BOLDS"))
{
if (ci->ttb[TTB_BOLDS])
info[_("Bolds kicker")] = Anope::printf("%s (%d kick(s) to ban)", enabled.c_str(), ci->ttb[TTB_BOLDS]);
else
info[_("Bolds kicker")] = enabled;
}
else
info[_("Bolds kicker")] = disabled;
if (ci->HasExt("BS_KICK_CAPS"))
{
if (ci->ttb[TTB_CAPS])
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);
else
info[_("Caps kicker")] = Anope::printf(_("%s (minimum %d/%d%%)"), enabled.c_str(), ci->capsmin, ci->capspercent);
}
else
info[_("Caps kicker")] = disabled;
if (ci->HasExt("BS_KICK_COLORS"))
{
if (ci->ttb[TTB_COLORS])
info[_("Colors kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_COLORS]);
else
info[_("Colors kicker")] = enabled;
}
else
info[_("Colors kicker")] = disabled;
if (ci->HasExt("BS_KICK_FLOOD"))
{
if (ci->ttb[TTB_FLOOD])
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);
else
info[_("Flood kicker")] = Anope::printf(_("%s (%d lines in %ds)"), enabled.c_str(), ci->floodlines, ci->floodsecs);
}
else
info[_("Flood kicker")] = disabled;
if (ci->HasExt("BS_KICK_REPEAT"))
{
if (ci->ttb[TTB_REPEAT])
info[_("Repeat kicker")] = Anope::printf(_("%s (%d kick(s) to ban; %d times)"), enabled.c_str(), ci->ttb[TTB_REPEAT], ci->repeattimes);
else
info[_("Repeat kicker")] = Anope::printf(_("%s (%d times)"), enabled.c_str(), ci->repeattimes);
}
else
info[_("Repeat kicker")] = disabled;
if (ci->HasExt("BS_KICK_REVERSES"))
{
if (ci->ttb[TTB_REVERSES])
info[_("Reverses kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_REVERSES]);
else
info[_("Reverses kicker")] = enabled;
}
else
info[_("Reverses kicker")] = disabled;
if (ci->HasExt("BS_KICK_UNDERLINES"))
{
if (ci->ttb[TTB_UNDERLINES])
info[_("Underlines kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_UNDERLINES]);
else
info[_("Underlines kicker")] = enabled;
}
else
info[_("Underlines kicker")] = disabled;
if (ci->HasExt("BS_KICK_ITALICS"))
{
if (ci->ttb[TTB_ITALICS])
info[_("Italics kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_ITALICS]);
else
info[_("Italics kicker")] = enabled;
}
else
info[_("Italics kicker")] = disabled;
if (ci->HasExt("BS_KICK_AMSGS"))
{
if (ci->ttb[TTB_AMSGS])
info[_("AMSG kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), ci->ttb[TTB_AMSGS]);
else
info[_("AMSG kicker")] = enabled;
}
else
info[_("AMSG kicker")] = disabled;
Anope::string flags;
CheckOptStr(flags, "BS_DONTKICKOPS", _("Ops protection"), ci, source.nc);
CheckOptStr(flags, "BS_DONTKICKVOICES", _("Voices protection"), ci, source.nc);
CheckOptStr(flags, "BS_FANTASY", _("Fantasy"), ci, source.nc);
CheckOptStr(flags, "BS_GREET", _("Greet"), ci, source.nc);
CheckOptStr(flags, "BS_NOBOT", _("No bot"), ci, source.nc);
info[_("Options")] = flags.empty() ? _("None") : flags;
std::vector<Anope::string> replies;
info.Process(replies);
for (unsigned i = 0; i < replies.size(); ++i)
source.Reply(replies[i]);
}
else
source.Reply(_("\002%s\002 is not a valid bot or registered channel."), query.c_str());
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("Allows you to see %s information about a channel or a bot.\n"
"If the parameter is a channel, then you'll get information\n"
"such as enabled kickers. If the parameter is a nick,\n"
"you'll get information about a bot, such as creation\n"
"time or number of channels it is on."), source.service->nick.c_str());
return true;
}
};
class BSInfo : public Module
{
CommandBSInfo commandbsinfo;
public:
BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
commandbsinfo(this)
{
this->SetAuthor("Anope");
}
};
MODULE_INIT(BSInfo)
|