]>
jfr.im git - irc/quakenet/newserv.git/blob - qabot/qabot_commands.c
5 #include "../nick/nick.h"
6 #include "../localuser/localuserchannel.h"
7 #include "../core/hooks.h"
8 #include "../core/schedule.h"
9 #include "../lib/array.h"
10 #include "../lib/base64.h"
11 #include "../lib/irc_string.h"
12 #include "../lib/splitline.h"
16 int qabot_doshowcommands(void* sender
, int cargc
, char** cargv
) {
17 nick
* np
= (nick
*)sender
;
18 Command
* cmdlist
[150];
21 sendnoticetouser(qabot_nick
, np
, "The following commands are registered at present:");
22 for (i
= 0, j
= getcommandlist(qabot_commands
, cmdlist
, 150); i
< j
; i
++) {
23 if (cmdlist
[i
]->level
)
24 sendnoticetouser(qabot_nick
, np
, "%s (%s)", cmdlist
[i
]->command
->content
, qabot_uflagtostr(cmdlist
[i
]->level
));
26 sendnoticetouser(qabot_nick
, np
, "%s", cmdlist
[i
]->command
->content
);
28 sendnoticetouser(qabot_nick
, np
, "End of list.");
33 int qabot_dohelp(void* sender
, int cargc
, char** cargv
) {
34 nick
* np
= (nick
*)sender
;
37 sendnoticetouser(qabot_nick
, np
, "Syntax: help <command>");
41 return qabot_showhelp(np
, cargv
[0]);
44 int qabot_dohello(void* sender
, int cargc
, char** cargv
) {
45 nick
* np
= (nick
*)sender
;
48 sendnoticetouser(qabot_nick
, np
, "You must be opered to use this command.");
53 sendnoticetouser(qabot_nick
, np
, "This command cannot be used once the initial account has been created.");
57 qabot_adduser(np
->authname
, QAUFLAG_STAFF
|QAUFLAG_ADMIN
|QAUFLAG_DEVELOPER
, time(0));
59 sendnoticetouser(qabot_nick
, np
, "An account has been created with admin privileges.");
64 int qabot_dosave(void* sender
, int cargc
, char** cargv
) {
65 nick
* np
= (nick
*)sender
;
67 sendnoticetouser(qabot_nick
, np
, "Saving...");
69 sendnoticetouser(qabot_nick
, np
, "Done.");
74 int qabot_dolistbots(void* sender
, int cargc
, char** cargv
) {
75 nick
* np
= (nick
*)sender
;
79 sendnoticetouser(qabot_nick
, np
, "There are no bots currently added.");
83 sendnoticetouser(qabot_nick
, np
, "The following bots are added:");
84 for (b
= qab_bots
; b
; b
= b
->next
)
85 sendnoticetouser(qabot_nick
, np
, "%s (%s@%s)", b
->nick
, b
->user
, b
->host
);
86 sendnoticetouser(qabot_nick
, np
, "End of list.");
89 int qabot_dolistusers(void* sender
, int cargc
, char** cargv
) {
90 nick
* np
= (nick
*)sender
;
94 sendnoticetouser(qabot_nick
, np
, "There are no users currently added.");
98 sendnoticetouser(qabot_nick
, np
, "The following users are added:");
99 for (u
= qabot_users
; u
; u
= u
->next
)
100 sendnoticetouser(qabot_nick
, np
, "%-15s (%s)", u
->authname
, qabot_uflagtostr(u
->flags
));
101 sendnoticetouser(qabot_nick
, np
, "End of list.");
104 int qabot_doshowbot(void* sender
, int cargc
, char** cargv
) {
105 nick
* np
= (nick
*)sender
;
110 sendnoticetouser(qabot_nick
, np
, "Syntax: showbot <nick>");
114 if (!(botnick
= getnickbynick(cargv
[0]))) {
115 sendnoticetouser(qabot_nick
, np
, "No such nickname.");
119 bot
= botnick
->exts
[qabot_nickext
];
121 sendnoticetouser(qabot_nick
, np
, "%s is not a QABot.", botnick
->nick
);
125 sendnoticetouser(qabot_nick
, np
, "- Information for %s ---", bot
->nick
);
126 sendnoticetouser(qabot_nick
, np
, "User: %s", bot
->user
);
127 sendnoticetouser(qabot_nick
, np
, "Host: %s", bot
->host
);
128 sendnoticetouser(qabot_nick
, np
, "Public chan: %s", bot
->public_chan
->name
->content
);
129 sendnoticetouser(qabot_nick
, np
, "Question chan: %s", bot
->question_chan
->name
->content
);
130 sendnoticetouser(qabot_nick
, np
, "Staff chan: %s", bot
->staff_chan
->name
->content
);
131 sendnoticetouser(qabot_nick
, np
, "Spam interval: %d", bot
->spam_interval
);
132 sendnoticetouser(qabot_nick
, np
, "Nick block interval: %d", bot
->ask_wait
);
133 sendnoticetouser(qabot_nick
, np
, "Queued question interval: %d", bot
->queued_question_interval
);
134 sendnoticetouser(qabot_nick
, np
, "Lines spammed: %d", bot
->spammed
);
135 sendnoticetouser(qabot_nick
, np
, "Questions asked: %d", bot
->lastquestionID
);
136 sendnoticetouser(qabot_nick
, np
, "Questions answered: %d", bot
->answered
);
137 sendnoticetouser(qabot_nick
, np
, "Blocks: %d", bot
->block_count
);
138 sendnoticetouser(qabot_nick
, np
, "Block control chars: %s", (bot
->flags
& QAB_CONTROLCHAR
) ? "Yes" : "No");
139 sendnoticetouser(qabot_nick
, np
, "Block colour: %s", (bot
->flags
& QAB_COLOUR
) ? "Yes" : "No");
140 sendnoticetouser(qabot_nick
, np
, "Authed users only: %s", (bot
->flags
& QAB_AUTHEDONLY
) ? "Yes" : "No");
141 sendnoticetouser(qabot_nick
, np
, "Line break: %s", (bot
->flags
& QAB_LINEBREAK
) ? "Yes" : "No");
142 sendnoticetouser(qabot_nick
, np
, "Question flood detection: %s", (bot
->flags
& QAB_FLOODDETECT
) ? "Yes" : "No");
143 sendnoticetouser(qabot_nick
, np
, "Question flood blocking: %s", (bot
->flags
& QAB_FLOODSTOP
) ? "Yes" : "No");
144 sendnoticetouser(qabot_nick
, np
, "Blocks mark as spam: %s", (bot
->flags
& QAB_BLOCKMARK
) ? "Yes" : "No");
145 if (bot
->micnumeric
) {
146 nick
* mnick
= getnickbynumeric(bot
->micnumeric
);
148 sendnoticetouser(qabot_nick
, np
, "Mic: Enabled (%s)", mnick
? mnick
->nick
: "UNKNOWN");
151 sendnoticetouser(qabot_nick
, np
, "Mic: Disabled");
152 sendnoticetouser(qabot_nick
, sender
, "Mic timeout: %d", bot
->mic_timeout
);
153 sendnoticetouser(qabot_nick
, np
, "End of list.");
158 int qabot_doaddbot(void* sender
, int cargc
, char** cargv
) {
159 nick
* np
= (nick
*)sender
;
164 sendnoticetouser(qabot_nick
, np
, "Syntax: addbot <nick> <user> <host> <public channel> <question channel> <staff channel>");
169 sendnoticetouser(qabot_nick
, np
, "You must be opered to use this command.");
173 if (!qabot_addbot(cargv
[0], cargv
[1], cargv
[2], cargv
[3], cargv
[4], cargv
[5], DEFAULTBOTFLAGS
, SPAMINTERVAL
, ASKWAIT
, QUEUEDQUESTIONINTERVAL
, np
))
176 sendnoticetouser(qabot_nick
, np
, "Created %s!%s@%s (%s, %s, %s).", cargv
[0], cargv
[1], cargv
[2], cargv
[3], cargv
[4], cargv
[5]);
181 int qabot_dodelbot(void* sender
, int cargc
, char** cargv
) {
182 nick
* np
= (nick
*)sender
;
187 sendnoticetouser(qabot_nick
, np
, "Syntax: delbot <nick>");
192 sendnoticetouser(qabot_nick
, np
, "You must be opered to use this command.");
196 if (!(botnick
= getnickbynick(cargv
[0]))) {
197 sendnoticetouser(qabot_nick
, np
, "No such nickname.");
201 bot
= botnick
->exts
[qabot_nickext
];
203 sendnoticetouser(qabot_nick
, np
, "%s is not a QABot.", botnick
->nick
);
208 sendnoticetouser(qabot_nick
, np
, "Bot deleted.");
213 int qabot_doadduser(void* sender
, int cargc
, char** cargv
) {
214 nick
* np
= (nick
*)sender
;
221 sendnoticetouser(qabot_nick
, np
, "Syntax: adduser <nick> <flags>");
225 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
228 if (qabot_getuser(victim
)) {
229 sendnoticetouser(qabot_nick
, np
, "Account %s already exists.", target
->authname
);
233 for (ch
= cargv
[1]; *ch
; ch
++) {
239 flags
|= (QAUFLAG_ADMIN
|QAUFLAG_STAFF
);
243 flags
|= (QAUFLAG_DEVELOPER
|QAUFLAG_ADMIN
|QAUFLAG_STAFF
);
246 flags
|= QAUFLAG_STAFF
;
250 sendnoticetouser(qabot_nick
, np
, "Unknown flag '%c'.", *ch
);
255 qabot_adduser(victim
, flags
, time(0));
256 sendnoticetouser(qabot_nick
, np
, "Account created.");
261 int qabot_dodeluser(void* sender
, int cargc
, char** cargv
) {
262 nick
* np
= (nick
*)sender
;
267 sendnoticetouser(qabot_nick
, np
, "Syntax: <account>");
271 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
274 if (!(u
= qabot_getuser(victim
))) {
275 sendnoticetouser(qabot_nick
, np
, "Account does not exist.");
279 if (!ircd_strcmp(u
->authname
, np
->authname
)) {
280 sendnoticetouser(qabot_nick
, np
, "You cannot delete your own account.");
284 qabot_squelchuser(u
);
285 sendnoticetouser(qabot_nick
, np
, "Account deleted.");
290 int qabot_dochangelev(void* sender
, int cargc
, char** cargv
) {
291 nick
* np
= (nick
*)sender
;
296 sendnoticetouser(qabot_nick
, np
, "Syntax: changelev <nick|#authname> <flags>");
300 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
303 if (!(u
= qabot_getuser(victim
))) {
304 sendnoticetouser(qabot_nick
, np
, "Account does not exist.");
308 sendnoticetouser(qabot_nick
, np
, "TODO: Finish this! :)");
313 int qabot_dowhois(void* sender
, int cargc
, char** cargv
) {
314 nick
* np
= (nick
*)sender
;
319 sendnoticetouser(qabot_nick
, np
, "Syntax: whois <nick|#authname>");
323 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
326 if (!(u
= qabot_getuser(victim
))) {
327 sendnoticetouser(qabot_nick
, np
, "Account does not exist.");
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
));
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;
344 for (b
= qab_bots
; b
; b
= b
->next
) {
346 blockc
+= b
->block_count
;
348 qc
+= b
->lastquestionID
;
352 for (u
= qabot_users
; u
; u
= u
->next
)
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
);