]>
jfr.im git - irc/quakenet/newserv.git/blob - qabot/qabot_commands.c
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"
15 int qabot_doshowcommands(void* sender
, int cargc
, char** cargv
) {
16 nick
* np
= (nick
*)sender
;
17 Command
* cmdlist
[150];
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
));
25 sendnoticetouser(qabot_nick
, np
, "%s", cmdlist
[i
]->command
->content
);
27 sendnoticetouser(qabot_nick
, np
, "End of list.");
32 int qabot_dohelp(void* sender
, int cargc
, char** cargv
) {
33 nick
* np
= (nick
*)sender
;
36 sendnoticetouser(qabot_nick
, np
, "Syntax: help <command>");
40 return qabot_showhelp(np
, cargv
[0]);
43 int qabot_dohello(void* sender
, int cargc
, char** cargv
) {
44 nick
* np
= (nick
*)sender
;
47 sendnoticetouser(qabot_nick
, np
, "You must be opered to use this command.");
52 sendnoticetouser(qabot_nick
, np
, "This command cannot be used once the initial account has been created.");
56 qabot_adduser(np
->authname
, QAUFLAG_STAFF
|QAUFLAG_ADMIN
|QAUFLAG_DEVELOPER
, time(0));
58 sendnoticetouser(qabot_nick
, np
, "An account has been created with admin privileges.");
63 int qabot_dosave(void* sender
, int cargc
, char** cargv
) {
64 nick
* np
= (nick
*)sender
;
66 sendnoticetouser(qabot_nick
, np
, "Saving...");
68 sendnoticetouser(qabot_nick
, np
, "Done.");
73 int qabot_dolistbots(void* sender
, int cargc
, char** cargv
) {
74 nick
* np
= (nick
*)sender
;
78 sendnoticetouser(qabot_nick
, np
, "There are no bots currently added.");
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.");
90 int qabot_dolistusers(void* sender
, int cargc
, char** cargv
) {
91 nick
* np
= (nick
*)sender
;
95 sendnoticetouser(qabot_nick
, np
, "There are no users currently added.");
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.");
107 int qabot_doshowbot(void* sender
, int cargc
, char** cargv
) {
108 nick
* np
= (nick
*)sender
;
113 sendnoticetouser(qabot_nick
, np
, "Syntax: showbot <nick>");
117 if (!(botnick
= getnickbynick(cargv
[0]))) {
118 sendnoticetouser(qabot_nick
, np
, "No such nickname.");
122 bot
= botnick
->exts
[qabot_nickext
];
124 sendnoticetouser(qabot_nick
, np
, "%s is not a QABot.", botnick
->nick
);
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
);
151 sendnoticetouser(qabot_nick
, np
, "Mic: Enabled (%s)", mnick
? mnick
->nick
: "UNKNOWN");
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.");
161 int qabot_doaddbot(void* sender
, int cargc
, char** cargv
) {
162 nick
* np
= (nick
*)sender
;
165 sendnoticetouser(qabot_nick
, np
, "Syntax: addbot <nick> <user> <host> <public channel> <question channel> <staff channel>");
170 sendnoticetouser(qabot_nick
, np
, "You must be opered to use this command.");
174 if (!qabot_addbot(cargv
[0], cargv
[1], cargv
[2], cargv
[3], cargv
[4], cargv
[5], DEFAULTBOTFLAGS
, SPAMINTERVAL
, ASKWAIT
, QUEUEDQUESTIONINTERVAL
, np
))
177 sendnoticetouser(qabot_nick
, np
, "Created %s!%s@%s (%s, %s, %s).", cargv
[0], cargv
[1], cargv
[2], cargv
[3], cargv
[4], cargv
[5]);
182 int qabot_dodelbot(void* sender
, int cargc
, char** cargv
) {
183 nick
* np
= (nick
*)sender
;
188 sendnoticetouser(qabot_nick
, np
, "Syntax: delbot <nick>");
193 sendnoticetouser(qabot_nick
, np
, "You must be opered to use this command.");
197 if (!(botnick
= getnickbynick(cargv
[0]))) {
198 sendnoticetouser(qabot_nick
, np
, "No such nickname.");
202 bot
= botnick
->exts
[qabot_nickext
];
204 sendnoticetouser(qabot_nick
, np
, "%s is not a QABot.", botnick
->nick
);
209 sendnoticetouser(qabot_nick
, np
, "Bot deleted.");
214 int qabot_doadduser(void* sender
, int cargc
, char** cargv
) {
215 nick
* np
= (nick
*)sender
;
222 sendnoticetouser(qabot_nick
, np
, "Syntax: adduser <nick> <flags>");
226 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
229 if (qabot_getuser(victim
)) {
230 sendnoticetouser(qabot_nick
, np
, "Account %s already exists.", target
->authname
);
234 for (ch
= cargv
[1]; *ch
; ch
++) {
240 flags
|= (QAUFLAG_ADMIN
|QAUFLAG_STAFF
);
244 flags
|= (QAUFLAG_DEVELOPER
|QAUFLAG_ADMIN
|QAUFLAG_STAFF
);
247 flags
|= QAUFLAG_STAFF
;
251 sendnoticetouser(qabot_nick
, np
, "Unknown flag '%c'.", *ch
);
256 qabot_adduser(victim
, flags
, time(0));
257 sendnoticetouser(qabot_nick
, np
, "Account created.");
262 int qabot_dodeluser(void* sender
, int cargc
, char** cargv
) {
263 nick
* np
= (nick
*)sender
;
268 sendnoticetouser(qabot_nick
, np
, "Syntax: <account>");
272 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
275 if (!(u
= qabot_getuser(victim
))) {
276 sendnoticetouser(qabot_nick
, np
, "Account does not exist.");
280 if (!ircd_strcmp(u
->authname
, np
->authname
)) {
281 sendnoticetouser(qabot_nick
, np
, "You cannot delete your own account.");
285 qabot_squelchuser(u
);
286 sendnoticetouser(qabot_nick
, np
, "Account deleted.");
291 int qabot_dochangelev(void* sender
, int cargc
, char** cargv
) {
292 nick
* np
= (nick
*)sender
;
297 sendnoticetouser(qabot_nick
, np
, "Syntax: changelev <nick|#authname> <flags>");
301 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
304 if (!(u
= qabot_getuser(victim
))) {
305 sendnoticetouser(qabot_nick
, np
, "Account does not exist.");
309 sendnoticetouser(qabot_nick
, np
, "TODO: Finish this! :)");
314 int qabot_dowhois(void* sender
, int cargc
, char** cargv
) {
315 nick
* np
= (nick
*)sender
;
320 sendnoticetouser(qabot_nick
, np
, "Syntax: whois <nick|#authname>");
324 if (!(victim
= qabot_getvictim(np
, cargv
[0])))
327 if (!(u
= qabot_getuser(victim
))) {
328 sendnoticetouser(qabot_nick
, np
, "Account does not exist.");
332 sendnoticetouser(qabot_nick
, np
, "Account: %s", u
->authname
);
333 sendnoticetouser(qabot_nick
, np
, "Flags: %s", qabot_uflagtostr(u
->flags
));
334 sendnoticetouser(qabot_nick
, np
, "Created: %s", qabot_formattime(u
->created
));
339 int qabot_dostatus(void* sender
, int cargc
, char** cargv
) {
340 nick
* np
= (nick
*)sender
;
341 int botc
= 0, blockc
= 0, userc
= 0, spamc
= 0, qc
= 0, qac
= 0;
345 for (b
= qab_bots
; b
; b
= b
->next
) {
347 blockc
+= b
->block_count
;
349 qc
+= b
->lastquestionID
;
353 for (u
= qabot_users
; u
; u
= u
->next
)
356 sendnoticetouser(qabot_nick
, np
, "Up since: %s", qabot_formattime(qab_startime
));
357 sendnoticetouser(qabot_nick
, np
, "Bots: %d", botc
);
358 sendnoticetouser(qabot_nick
, np
, "Blocks: %d", blockc
);
359 sendnoticetouser(qabot_nick
, np
, "Users: %d", userc
);
360 sendnoticetouser(qabot_nick
, np
, "Total lines spammed: %d", spamc
);
361 sendnoticetouser(qabot_nick
, np
, "Total questions asked: %d", qc
);
362 sendnoticetouser(qabot_nick
, np
, "Total questions answered: %d", qac
);