summaryrefslogtreecommitdiff
path: root/src/core/bs_info.c
blob: 985ff6dd3bf58fa499269314e76b24a0d2363a4e (plain)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/* BotServ core functions
 *
 * (C) 2003-2009 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.
 *
 * $Id$
 *
 */
/*************************************************************************/

#include "module.h"

int do_info(User * u);
void send_bot_channels(User * u, BotInfo * bi);
void myBotServHelp(User * u);

class BSInfo : public Module
{
 public:
	BSInfo(const std::string &modname, const std::string &creator) : Module(modname, creator)
	{
		Command *c;

		this->SetAuthor("Anope");
		this->SetVersion("$Id$");
		this->SetType(CORE);
		c = createCommand("INFO", do_info, NULL, BOT_HELP_INFO, -1, -1, -1, -1);
		this->AddCommand(BOTSERV, c, MOD_UNIQUE);

		this->SetBotHelp(myBotServHelp);
	}
};


/**
 * Add the help response to Anopes /bs help output.
 * @param u The user who is requesting help
 **/
void myBotServHelp(User * u)
{
	notice_lang(s_BotServ, u, BOT_HELP_CMD_INFO);
}

/**
 * The /bs info command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
int do_info(User * u)
{
	BotInfo *bi;
	ChannelInfo *ci;
	char *query = strtok(NULL, " ");

	int need_comma = 0, is_servadmin = is_services_admin(u);
	char buf[BUFSIZE], *end;
	const char *commastr = getstring(u->na, COMMA_SPACE);

	if (!query)
		syntax_error(s_BotServ, u, "INFO", BOT_INFO_SYNTAX);
	else if ((bi = findbot(query))) {
		struct tm *tm;

		notice_lang(s_BotServ, u, BOT_INFO_BOT_HEADER, bi->nick);
		notice_lang(s_BotServ, u, BOT_INFO_BOT_MASK, bi->user, bi->host);
		notice_lang(s_BotServ, u, BOT_INFO_BOT_REALNAME, bi->real);
		tm = localtime(&bi->created);
		strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
		notice_lang(s_BotServ, u, BOT_INFO_BOT_CREATED, buf);
		notice_lang(s_BotServ, u, BOT_INFO_BOT_OPTIONS,
					getstring(u->na,
							  (bi->
							   flags & BI_PRIVATE) ? BOT_INFO_OPT_PRIVATE :
							  BOT_INFO_OPT_NONE));
		notice_lang(s_BotServ, u, BOT_INFO_BOT_USAGE, bi->chancount);

		if (is_services_admin(u))
			send_bot_channels(u, bi);
	} else if ((ci = cs_findchan(query))) {
		if (!is_servadmin && !is_founder(u, ci)) {
			notice_lang(s_BotServ, u, PERMISSION_DENIED);
			return MOD_CONT;
		}
		if (ci->flags & CI_VERBOTEN) {
			notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, query);
			return MOD_CONT;
		}

		notice_lang(s_BotServ, u, BOT_INFO_CHAN_HEADER, ci->name);
		if (ci->bi)
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_BOT, ci->bi->nick);
		else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_BOT_NONE);

		if (ci->botflags & BS_KICK_BADWORDS) {
			if (ci->ttb[TTB_BADWORDS])
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_BADWORDS]);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS,
							getstring(u->na, BOT_INFO_ACTIVE));
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS,
						getstring(u->na, BOT_INFO_INACTIVE));
		if (ci->botflags & BS_KICK_BOLDS) {
			if (ci->ttb[TTB_BOLDS])
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_BOLDS]);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS,
							getstring(u->na, BOT_INFO_ACTIVE));
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS,
						getstring(u->na, BOT_INFO_INACTIVE));
		if (ci->botflags & BS_KICK_CAPS) {
			if (ci->ttb[TTB_CAPS])
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_CAPS], ci->capsmin,
							ci->capspercent);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_ON,
							getstring(u->na, BOT_INFO_ACTIVE), ci->capsmin,
							ci->capspercent);
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_OFF,
						getstring(u->na, BOT_INFO_INACTIVE));
		if (ci->botflags & BS_KICK_COLORS) {
			if (ci->ttb[TTB_COLORS])
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_COLORS]);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS,
							getstring(u->na, BOT_INFO_ACTIVE));
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS,
						getstring(u->na, BOT_INFO_INACTIVE));
		if (ci->botflags & BS_KICK_FLOOD) {
			if (ci->ttb[TTB_FLOOD])
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_FLOOD], ci->floodlines,
							ci->floodsecs);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_ON,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->floodlines, ci->floodsecs);
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_OFF,
						getstring(u->na, BOT_INFO_INACTIVE));
		if (ci->botflags & BS_KICK_REPEAT) {
			if (ci->ttb[TTB_REPEAT])
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_REPEAT], ci->repeattimes);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_ON,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->repeattimes);
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_OFF,
						getstring(u->na, BOT_INFO_INACTIVE));
		if (ci->botflags & BS_KICK_REVERSES) {
			if (ci->ttb[TTB_REVERSES])
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_REVERSES]);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES,
							getstring(u->na, BOT_INFO_ACTIVE));
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES,
						getstring(u->na, BOT_INFO_INACTIVE));
		if (ci->botflags & BS_KICK_UNDERLINES) {
			if (ci->ttb[TTB_UNDERLINES])
				notice_lang(s_BotServ, u,
							BOT_INFO_CHAN_KICK_UNDERLINES_BAN,
							getstring(u->na, BOT_INFO_ACTIVE),
							ci->ttb[TTB_UNDERLINES]);
			else
				notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_UNDERLINES,
							getstring(u->na, BOT_INFO_ACTIVE));
		} else
			notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_UNDERLINES,
						getstring(u->na, BOT_INFO_INACTIVE));

		end = buf;
		*end = 0;
		if (ci->botflags & BS_DONTKICKOPS) {
			end += snprintf(end, sizeof(buf) - (end - buf), "%s",
							getstring(u->na, BOT_INFO_OPT_DONTKICKOPS));
			need_comma = 1;
		}
		if (ci->botflags & BS_DONTKICKVOICES) {
			end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
							need_comma ? commastr : "",
							getstring(u->na, BOT_INFO_OPT_DONTKICKVOICES));
			need_comma = 1;
		}
		if (ci->botflags & BS_FANTASY) {
			end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
							need_comma ? commastr : "",
							getstring(u->na, BOT_INFO_OPT_FANTASY));
			need_comma = 1;
		}
		if (ci->botflags & BS_GREET) {
			end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
							need_comma ? commastr : "",
							getstring(u->na, BOT_INFO_OPT_GREET));
			need_comma = 1;
		}
		if (ci->botflags & BS_NOBOT) {
			end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
							need_comma ? commastr : "",
							getstring(u->na, BOT_INFO_OPT_NOBOT));
			need_comma = 1;
		}
		if (ci->botflags & BS_SYMBIOSIS) {
			end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
							need_comma ? commastr : "",
							getstring(u->na, BOT_INFO_OPT_SYMBIOSIS));
			need_comma = 1;
		}
		notice_lang(s_BotServ, u, BOT_INFO_CHAN_OPTIONS,
					*buf ? buf : getstring(u->na, BOT_INFO_OPT_NONE));

	} else
		notice_lang(s_BotServ, u, BOT_INFO_NOT_FOUND, query);
	return MOD_CONT;
}

void send_bot_channels(User * u, BotInfo * bi)
{
	int i;
	ChannelInfo *ci;
	char buf[307], *end;

	*buf = 0;
	end = buf;

	for (i = 0; i < 256; i++) {
		for (ci = chanlists[i]; ci; ci = ci->next) {
			if (ci->bi == bi) {
				if (strlen(buf) + strlen(ci->name) > 300) {
					notice_user(s_BotServ, u, "%s", buf);
					*buf = 0;
					end = buf;
				}
				end +=
					snprintf(end, sizeof(buf) - (end - buf), " %s ",
							 ci->name);
			}
		}
	}

	if (*buf)
		notice_user(s_BotServ, u, "%s", buf);
	return;
}

MODULE_INIT("bs_info", BSInfo)