]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include <time.h> | |
3 | ||
4 | #include "../nick/nick.h" | |
5 | #include "../localuser/localuserchannel.h" | |
6 | #include "../core/hooks.h" | |
7 | #include "../core/schedule.h" | |
8 | #include "../lib/array.h" | |
9 | #include "../lib/base64.h" | |
10 | #include "../lib/irc_string.h" | |
11 | #include "../lib/splitline.h" | |
12 | ||
13 | #include "qabot.h" | |
14 | ||
15 | int qabot_doshowcommands(void* sender, int cargc, char** cargv) { | |
16 | nick* np = (nick*)sender; | |
17 | Command* cmdlist[150]; | |
18 | int i, j; | |
19 | ||
20 | sendnoticetouser(qabot_nick, np, "The following commands are registered at present:"); | |
21 | for (i = 0, j = getcommandlist(qabot_commands, cmdlist, 150); i < j; i++) { | |
22 | if (cmdlist[i]->level) | |
23 | sendnoticetouser(qabot_nick, np, "%s (%s)", cmdlist[i]->command->content, qabot_uflagtostr(cmdlist[i]->level)); | |
24 | else | |
25 | sendnoticetouser(qabot_nick, np, "%s", cmdlist[i]->command->content); | |
26 | } | |
27 | sendnoticetouser(qabot_nick, np, "End of list."); | |
28 | ||
29 | return CMD_OK; | |
30 | } | |
31 | ||
32 | int qabot_dohelp(void* sender, int cargc, char** cargv) { | |
33 | nick* np = (nick*)sender; | |
34 | ||
35 | if (cargc < 1) { | |
36 | sendnoticetouser(qabot_nick, np, "Syntax: help <command>"); | |
37 | return CMD_ERROR; | |
38 | } | |
39 | ||
40 | return qabot_showhelp(np, cargv[0]); | |
41 | } | |
42 | ||
43 | int qabot_dohello(void* sender, int cargc, char** cargv) { | |
44 | nick* np = (nick*)sender; | |
45 | ||
46 | if (!IsOper(np)) { | |
47 | sendnoticetouser(qabot_nick, np, "You must be opered to use this command."); | |
48 | return CMD_ERROR; | |
49 | } | |
50 | ||
51 | if (qabot_users) { | |
52 | sendnoticetouser(qabot_nick, np, "This command cannot be used once the initial account has been created."); | |
53 | return CMD_ERROR; | |
54 | } | |
55 | ||
56 | qabot_adduser(np->authname, QAUFLAG_STAFF|QAUFLAG_ADMIN|QAUFLAG_DEVELOPER, time(0)); | |
57 | qabot_savedb(); | |
58 | sendnoticetouser(qabot_nick, np, "An account has been created with admin privileges."); | |
59 | ||
60 | return CMD_OK; | |
61 | } | |
62 | ||
63 | int qabot_dosave(void* sender, int cargc, char** cargv) { | |
64 | nick* np = (nick*)sender; | |
65 | ||
66 | sendnoticetouser(qabot_nick, np, "Saving..."); | |
67 | qabot_savedb(); | |
68 | sendnoticetouser(qabot_nick, np, "Done."); | |
69 | ||
70 | return CMD_OK; | |
71 | } | |
72 | ||
73 | int qabot_dolistbots(void* sender, int cargc, char** cargv) { | |
74 | nick* np = (nick*)sender; | |
75 | qab_bot* b; | |
76 | ||
77 | if (!qab_bots) { | |
78 | sendnoticetouser(qabot_nick, np, "There are no bots currently added."); | |
79 | return CMD_OK; | |
80 | } | |
81 | ||
82 | sendnoticetouser(qabot_nick, np, "The following bots are added:"); | |
83 | for (b = qab_bots; b; b = b->next) | |
84 | sendnoticetouser(qabot_nick, np, "%s (%s@%s)", b->nick, b->user, b->host); | |
85 | sendnoticetouser(qabot_nick, np, "End of list."); | |
86 | ||
87 | return CMD_OK; | |
88 | } | |
89 | ||
90 | int qabot_dolistusers(void* sender, int cargc, char** cargv) { | |
91 | nick* np = (nick*)sender; | |
92 | qab_user* u; | |
93 | ||
94 | if (!qabot_users) { | |
95 | sendnoticetouser(qabot_nick, np, "There are no users currently added."); | |
96 | return CMD_OK; | |
97 | } | |
98 | ||
99 | sendnoticetouser(qabot_nick, np, "The following users are added:"); | |
100 | for (u = qabot_users; u; u = u->next) | |
101 | sendnoticetouser(qabot_nick, np, "%-15s (%s)", u->authname, qabot_uflagtostr(u->flags)); | |
102 | sendnoticetouser(qabot_nick, np, "End of list."); | |
103 | ||
104 | return CMD_OK; | |
105 | } | |
106 | ||
107 | int qabot_doshowbot(void* sender, int cargc, char** cargv) { | |
108 | nick* np = (nick*)sender; | |
109 | qab_bot* bot; | |
110 | nick* botnick; | |
111 | ||
112 | if (cargc < 1) { | |
113 | sendnoticetouser(qabot_nick, np, "Syntax: showbot <nick>"); | |
114 | return CMD_ERROR; | |
115 | } | |
116 | ||
117 | if (!(botnick = getnickbynick(cargv[0]))) { | |
118 | sendnoticetouser(qabot_nick, np, "No such nickname."); | |
119 | return CMD_ERROR; | |
120 | } | |
121 | ||
122 | bot = botnick->exts[qabot_nickext]; | |
123 | if (!bot) { | |
124 | sendnoticetouser(qabot_nick, np, "%s is not a QABot.", botnick->nick); | |
125 | return CMD_ERROR; | |
126 | } | |
127 | ||
128 | sendnoticetouser(qabot_nick, np, "- Information for %s ---", bot->nick); | |
129 | sendnoticetouser(qabot_nick, np, "User: %s", bot->user); | |
130 | sendnoticetouser(qabot_nick, np, "Host: %s", bot->host); | |
131 | sendnoticetouser(qabot_nick, np, "Public chan: %s", bot->public_chan->name->content); | |
132 | sendnoticetouser(qabot_nick, np, "Question chan: %s", bot->question_chan->name->content); | |
133 | sendnoticetouser(qabot_nick, np, "Staff chan: %s", bot->staff_chan->name->content); | |
134 | sendnoticetouser(qabot_nick, np, "Spam interval: %d", bot->spam_interval); | |
135 | sendnoticetouser(qabot_nick, np, "Nick block interval: %d", bot->ask_wait); | |
136 | sendnoticetouser(qabot_nick, np, "Queued question interval: %d", bot->queued_question_interval); | |
137 | sendnoticetouser(qabot_nick, np, "Lines spammed: %d", bot->spammed); | |
138 | sendnoticetouser(qabot_nick, np, "Questions asked: %d", bot->lastquestionID); | |
139 | sendnoticetouser(qabot_nick, np, "Questions answered: %d", bot->answered); | |
140 | sendnoticetouser(qabot_nick, np, "Blocks: %d", bot->block_count); | |
141 | sendnoticetouser(qabot_nick, np, "Block control chars: %s", (bot->flags & QAB_CONTROLCHAR) ? "Yes" : "No"); | |
142 | sendnoticetouser(qabot_nick, np, "Block colour: %s", (bot->flags & QAB_COLOUR) ? "Yes" : "No"); | |
143 | sendnoticetouser(qabot_nick, np, "Authed users only: %s", (bot->flags & QAB_AUTHEDONLY) ? "Yes" : "No"); | |
144 | sendnoticetouser(qabot_nick, np, "Line break: %s", (bot->flags & QAB_LINEBREAK) ? "Yes" : "No"); | |
145 | sendnoticetouser(qabot_nick, np, "Question flood detection: %s", (bot->flags & QAB_FLOODDETECT) ? "Yes" : "No"); | |
146 | sendnoticetouser(qabot_nick, np, "Question flood blocking: %s", (bot->flags & QAB_FLOODSTOP) ? "Yes" : "No"); | |
147 | sendnoticetouser(qabot_nick, np, "Blocks mark as spam: %s", (bot->flags & QAB_BLOCKMARK) ? "Yes" : "No"); | |
148 | if (bot->micnumeric) { | |
149 | nick* mnick = getnickbynumeric(bot->micnumeric); | |
150 | ||
151 | sendnoticetouser(qabot_nick, np, "Mic: Enabled (%s)", mnick ? mnick->nick : "UNKNOWN"); | |
152 | } | |
153 | else | |
154 | sendnoticetouser(qabot_nick, np, "Mic: Disabled"); | |
155 | sendnoticetouser(qabot_nick, sender, "Mic timeout: %d", bot->mic_timeout); | |
156 | sendnoticetouser(qabot_nick, np, "End of list."); | |
157 | ||
158 | return CMD_OK; | |
159 | } | |
160 | ||
161 | int qabot_doaddbot(void* sender, int cargc, char** cargv) { | |
162 | nick* np = (nick*)sender; | |
163 | ||
164 | if (cargc < 3) { | |
165 | sendnoticetouser(qabot_nick, np, "Syntax: addbot <nick> <user> <host> <public channel> <question channel> <staff channel>"); | |
166 | return CMD_ERROR; | |
167 | } | |
168 | ||
169 | if (!IsOper(np)) { | |
170 | sendnoticetouser(qabot_nick, np, "You must be opered to use this command."); | |
171 | return CMD_ERROR; | |
172 | } | |
173 | ||
174 | if (!qabot_addbot(cargv[0], cargv[1], cargv[2], cargv[3], cargv[4], cargv[5], DEFAULTBOTFLAGS, SPAMINTERVAL, ASKWAIT, QUEUEDQUESTIONINTERVAL, np)) | |
175 | return CMD_ERROR; | |
176 | ||
177 | sendnoticetouser(qabot_nick, np, "Created %s!%s@%s (%s, %s, %s).", cargv[0], cargv[1], cargv[2], cargv[3], cargv[4], cargv[5]); | |
178 | ||
179 | return CMD_OK; | |
180 | } | |
181 | ||
182 | int qabot_dodelbot(void* sender, int cargc, char** cargv) { | |
183 | nick* np = (nick*)sender; | |
184 | nick* botnick; | |
185 | qab_bot* bot; | |
186 | ||
187 | if (cargc < 1) { | |
188 | sendnoticetouser(qabot_nick, np, "Syntax: delbot <nick>"); | |
189 | return CMD_ERROR; | |
190 | } | |
191 | ||
192 | if (!IsOper(np)) { | |
193 | sendnoticetouser(qabot_nick, np, "You must be opered to use this command."); | |
194 | return CMD_ERROR; | |
195 | } | |
196 | ||
197 | if (!(botnick = getnickbynick(cargv[0]))) { | |
198 | sendnoticetouser(qabot_nick, np, "No such nickname."); | |
199 | return CMD_ERROR; | |
200 | } | |
201 | ||
202 | bot = botnick->exts[qabot_nickext]; | |
203 | if (!bot) { | |
204 | sendnoticetouser(qabot_nick, np, "%s is not a QABot.", botnick->nick); | |
205 | return CMD_ERROR; | |
206 | } | |
207 | ||
208 | qabot_delbot(bot); | |
209 | sendnoticetouser(qabot_nick, np, "Bot deleted."); | |
210 | ||
211 | return CMD_OK; | |
212 | } | |
213 | ||
214 | int qabot_doadduser(void* sender, int cargc, char** cargv) { | |
215 | nick* np = (nick*)sender; | |
216 | char* ch; | |
217 | flag_t flags = 0; | |
218 | char* victim; | |
219 | ||
220 | if (cargc < 2) { | |
221 | sendnoticetouser(qabot_nick, np, "Syntax: adduser <nick> <flags>"); | |
222 | return CMD_ERROR; | |
223 | } | |
224 | ||
225 | if (!(victim = qabot_getvictim(np, cargv[0]))) | |
226 | return CMD_ERROR; | |
227 | ||
228 | if (qabot_getuser(victim)) { | |
229 | sendnoticetouser(qabot_nick, np, "Account %s already exists.", victim); | |
230 | return CMD_ERROR; | |
231 | } | |
232 | ||
233 | for (ch = cargv[1]; *ch; ch++) { | |
234 | switch (*ch) { | |
235 | case '+': | |
236 | break; | |
237 | ||
238 | case 'a': | |
239 | flags |= (QAUFLAG_ADMIN|QAUFLAG_STAFF); | |
240 | break; | |
241 | ||
242 | case 'd': | |
243 | flags |= (QAUFLAG_DEVELOPER|QAUFLAG_ADMIN|QAUFLAG_STAFF); | |
244 | ||
245 | case 's': | |
246 | flags |= QAUFLAG_STAFF; | |
247 | break; | |
248 | ||
249 | default: | |
250 | sendnoticetouser(qabot_nick, np, "Unknown flag '%c'.", *ch); | |
251 | return CMD_ERROR; | |
252 | } | |
253 | } | |
254 | ||
255 | qabot_adduser(victim, flags, time(0)); | |
256 | sendnoticetouser(qabot_nick, np, "Account created."); | |
257 | ||
258 | return CMD_OK; | |
259 | } | |
260 | ||
261 | int qabot_dodeluser(void* sender, int cargc, char** cargv) { | |
262 | nick* np = (nick*)sender; | |
263 | qab_user* u; | |
264 | char* victim; | |
265 | ||
266 | if (cargc < 1) { | |
267 | sendnoticetouser(qabot_nick, np, "Syntax: <account>"); | |
268 | return CMD_ERROR; | |
269 | } | |
270 | ||
271 | if (!(victim = qabot_getvictim(np, cargv[0]))) | |
272 | return CMD_ERROR; | |
273 | ||
274 | if (!(u = qabot_getuser(victim))) { | |
275 | sendnoticetouser(qabot_nick, np, "Account does not exist."); | |
276 | return CMD_ERROR; | |
277 | } | |
278 | ||
279 | if (!ircd_strcmp(u->authname, np->authname)) { | |
280 | sendnoticetouser(qabot_nick, np, "You cannot delete your own account."); | |
281 | return CMD_ERROR; | |
282 | } | |
283 | ||
284 | qabot_squelchuser(u); | |
285 | sendnoticetouser(qabot_nick, np, "Account deleted."); | |
286 | ||
287 | return CMD_OK; | |
288 | } | |
289 | ||
290 | int qabot_dochangelev(void* sender, int cargc, char** cargv) { | |
291 | nick* np = (nick*)sender; | |
292 | char* victim; | |
293 | qab_user* u; | |
294 | ||
295 | if (cargc < 1) { | |
296 | sendnoticetouser(qabot_nick, np, "Syntax: changelev <nick|#authname> <flags>"); | |
297 | return CMD_ERROR; | |
298 | } | |
299 | ||
300 | if (!(victim = qabot_getvictim(np, cargv[0]))) | |
301 | return CMD_ERROR; | |
302 | ||
303 | if (!(u = qabot_getuser(victim))) { | |
304 | sendnoticetouser(qabot_nick, np, "Account does not exist."); | |
305 | return CMD_ERROR; | |
306 | } | |
307 | ||
308 | sendnoticetouser(qabot_nick, np, "TODO: Finish this! :)"); | |
309 | ||
310 | return CMD_OK; | |
311 | } | |
312 | ||
313 | int qabot_dowhois(void* sender, int cargc, char** cargv) { | |
314 | nick* np = (nick*)sender; | |
315 | char* victim; | |
316 | qab_user* u; | |
317 | ||
318 | if (cargc < 1) { | |
319 | sendnoticetouser(qabot_nick, np, "Syntax: whois <nick|#authname>"); | |
320 | return CMD_ERROR; | |
321 | } | |
322 | ||
323 | if (!(victim = qabot_getvictim(np, cargv[0]))) | |
324 | return CMD_ERROR; | |
325 | ||
326 | if (!(u = qabot_getuser(victim))) { | |
327 | sendnoticetouser(qabot_nick, np, "Account does not exist."); | |
328 | return CMD_ERROR; | |
329 | } | |
330 | ||
331 | sendnoticetouser(qabot_nick, np, "Account: %s", u->authname); | |
332 | sendnoticetouser(qabot_nick, np, "Flags: %s", qabot_uflagtostr(u->flags)); | |
333 | sendnoticetouser(qabot_nick, np, "Created: %s", qabot_formattime(u->created)); | |
334 | ||
335 | return CMD_OK; | |
336 | } | |
337 | ||
338 | int qabot_dostatus(void* sender, int cargc, char** cargv) { | |
339 | nick* np = (nick*)sender; | |
340 | int botc = 0, blockc = 0, userc = 0, spamc = 0, qc = 0, qac = 0; | |
341 | qab_bot* b; | |
342 | qab_user* u; | |
343 | ||
344 | for (b = qab_bots; b; b = b->next) { | |
345 | botc++; | |
346 | blockc += b->block_count; | |
347 | spamc += b->spammed; | |
348 | qc += b->lastquestionID; | |
349 | qac += b->answered; | |
350 | } | |
351 | ||
352 | for (u = qabot_users; u; u = u->next) | |
353 | userc++; | |
354 | ||
355 | sendnoticetouser(qabot_nick, np, "Up since: %s", qabot_formattime(qab_startime)); | |
356 | sendnoticetouser(qabot_nick, np, "Bots: %d", botc); | |
357 | sendnoticetouser(qabot_nick, np, "Blocks: %d", blockc); | |
358 | sendnoticetouser(qabot_nick, np, "Users: %d", userc); | |
359 | sendnoticetouser(qabot_nick, np, "Total lines spammed: %d", spamc); | |
360 | sendnoticetouser(qabot_nick, np, "Total questions asked: %d", qc); | |
361 | sendnoticetouser(qabot_nick, np, "Total questions answered: %d", qac); | |
362 | ||
363 | return CMD_OK; | |
364 | } |