]>
jfr.im git - irc/quakenet/newserv.git/blob - qabot/qabot_chancommands.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_dochananswer ( void * np
, int cargc
, char ** cargv
) {
17 nick
* sender
= ( nick
*) np
;
18 qab_bot
* bot
= qabot_getcurrentbot ();
19 channel
* cp
= qabot_getcurrentchannel ();
25 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !answer <id> <answer>" );
29 id
= strtol ( cargv
[ 0 ], NULL
, 10 );
32 if (( id
< 1 ) || ( id
> bot
-> lastquestionID
)) {
33 sendnoticetouser ( bot
-> np
, sender
, "Invalid question ID %d ." , id
);
37 for ( q
= bot
-> questions
[ id
% QUESTIONHASHSIZE
]; q
; q
= q
-> next
)
42 sendnoticetouser ( bot
-> np
, sender
, "Can't find question %d ." , id
);
46 switch ( q
-> flags
& QAQ_QSTATE
) {
48 sendnoticetouser ( bot
-> np
, sender
, "Question %d has already been answered." , id
);
52 sendnoticetouser ( bot
-> np
, sender
, "Question %d has been marked as off-topic." , id
);
56 sendnoticetouser ( bot
-> np
, sender
, "Question %d has been marked as spam." , id
);
63 q
-> flags
= (( q
-> flags
) & ~ QAQ_QSTATE
) | QAQ_ANSWERED
;
64 q
-> answer
= strdup ( ch
);
68 if (! bot
-> nextspam
&& ! bot
-> micnumeric
) {
69 sendmessagetochannel ( bot
-> np
, bot
-> public_chan
-> channel
, " %s asked: %s " , q
-> nick
, q
-> question
);
70 sendmessagetochannel ( bot
-> np
, bot
-> public_chan
-> channel
, " %s answers: %s " , sender
-> nick
, ch
);
75 a
= ( qab_answer
*) malloc ( sizeof ( qab_answer
));
77 strncpy ( a
-> nick
, sender
-> nick
, NICKLEN
);
78 a
-> nick
[ NICKLEN
] = '\0' ;
79 a
-> next
= bot
-> answers
;
82 sendnoticetouser ( bot
-> np
, sender
, "Can't send your answer right now. Answer was stored and will be sent later on." );
86 sendnoticetouser ( bot
-> np
, sender
, "Answer to question %d has been sent and stored." , id
);
91 int qabot_dochanblock ( void * np
, int cargc
, char ** cargv
) {
92 nick
* sender
= ( nick
*) np
;
93 qab_bot
* bot
= qabot_getcurrentbot ();
94 channel
* cp
= qabot_getcurrentchannel ();
98 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !block [-q|-t] <account|mask>" );
103 if (! ircd_strncmp ( cargv
[ 0 ], "-q" , 2 )) {
105 char * target
= cargv
[ 1 ];
107 if (* target
== '#' ) {
110 if ( strchr ( target
, '*' ) || strchr ( target
, '?' )) {
111 sendnoticetouser ( bot
-> np
, sender
, "Wildcard account blocks are not supported." );
118 if (!( tnick
= getnickbynick ( target
))) {
119 sendnoticetouser ( bot
-> np
, sender
, "Couldn't find user %s ." , target
);
123 if (! IsAccount ( tnick
)) {
124 sendnoticetouser ( bot
-> np
, sender
, " %s is not authed." , tnick
-> nick
);
128 target
= tnick
-> authname
;
131 b
= ( qab_block
*) malloc ( sizeof ( qab_block
));
132 b
-> type
= QABBLOCK_ACCOUNT
;
133 b
-> created
= time ( 0 );
134 strncpy ( b
-> creator
, IsAccount ( sender
) ? sender
-> authname
: "UNKNOWN" , ACCOUNTLEN
);
135 b
-> creator
[ ACCOUNTLEN
] = '\0' ;
136 b
-> blockstr
= strdup ( target
);
138 b
-> next
= bot
-> blocks
;
140 bot
-> blocks
-> prev
= b
;
144 sendnoticetouser ( bot
-> np
, sender
, "Now blocking all messages from users with accountname %s ." , target
);
146 if ( bot
-> flags
& QAB_BLOCKMARK
) {
148 int i
, spamqcount
= 0 ;
151 for ( i
= 0 ; i
< QUESTIONHASHSIZE
; i
++) {
152 for ( q
= bot
-> questions
[ i
]; q
; q
= q
-> next
) {
153 if (( q
-> flags
& QAQ_QSTATE
) != QAQ_NEW
)
156 if (!( qnick
= getnickbynumeric ( q
-> numeric
)))
159 if (! IsAccount ( qnick
))
162 if ( ircd_strcmp ( qnick
-> authname
, b
-> blockstr
))
165 q
-> flags
= (( q
-> flags
) & ~ QAQ_QSTATE
) | QAQ_SPAM
;
170 sendnoticetouser ( bot
-> np
, sender
, "Block caused %d message %s to be marked as spam." , spamqcount
, ( spamqcount
== 1 ) ? "" : "s" );
173 else if (! ircd_strncmp ( cargv
[ 0 ], "-t" , 2 )) {
175 char * mask
= cargv
[ 1 ];
177 b
= ( qab_block
*) malloc ( sizeof ( qab_block
));
178 b
-> type
= QABBLOCK_TEXT
;
179 b
-> created
= time ( 0 );
180 strncpy ( b
-> creator
, sender
-> authname
, ACCOUNTLEN
);
181 b
-> creator
[ ACCOUNTLEN
] = '\0' ;
182 b
-> blockstr
= strdup ( mask
);
184 b
-> next
= bot
-> blocks
;
186 bot
-> blocks
-> prev
= b
;
190 sendnoticetouser ( bot
-> np
, sender
, "Now blocking all questions which match %s ." , mask
);
192 if ( bot
-> flags
& QAB_BLOCKMARK
) {
194 int i
, spamqcount
= 0 ;
196 for ( i
= 0 ; i
< QUESTIONHASHSIZE
; i
++) {
197 for ( q
= bot
-> questions
[ i
]; q
; q
= q
-> next
) {
198 if (( q
-> flags
& QAQ_QSTATE
) != QAQ_NEW
)
201 if ( match ( b
-> blockstr
, q
-> question
))
204 q
-> flags
= (( q
-> flags
) & ~ QAQ_QSTATE
) | QAQ_SPAM
;
209 sendnoticetouser ( bot
-> np
, sender
, "Block caused %d message %s to be marked as spam." , spamqcount
, ( spamqcount
== 1 ) ? "" : "s" );
213 sendnoticetouser ( bot
-> np
, sender
, "Invalid flag." );
219 char * mask
= cargv
[ 0 ];
221 if (! strchr ( mask
, '@' ) || ! strchr ( mask
, '!' )) {
222 sendnoticetouser ( bot
-> np
, sender
, " %s is not a valid hostmask." , mask
);
226 b
= ( qab_block
*) malloc ( sizeof ( qab_block
));
227 b
-> type
= QABBLOCK_HOST
;
228 b
-> created
= time ( 0 );
229 strncpy ( b
-> creator
, sender
-> authname
, ACCOUNTLEN
);
230 b
-> creator
[ ACCOUNTLEN
] = '\0' ;
231 b
-> blockstr
= strdup ( mask
);
233 b
-> next
= bot
-> blocks
;
235 bot
-> blocks
-> prev
= b
;
239 sendnoticetouser ( bot
-> np
, sender
, "Now blocking all messages from users with a hostmask matching %s ." , mask
);
241 if ( bot
-> flags
& QAB_BLOCKMARK
) {
243 int i
, spamqcount
= 0 ;
245 char hostbuf
[ NICKLEN
+ USERLEN
+ HOSTLEN
+ 3 ];
247 for ( i
= 0 ; i
< QUESTIONHASHSIZE
; i
++) {
248 for ( q
= bot
-> questions
[ i
]; q
; q
= q
-> next
) {
249 if (( q
-> flags
& QAQ_QSTATE
) != QAQ_NEW
)
252 if (!( qnick
= getnickbynumeric ( q
-> numeric
)))
255 sprintf ( hostbuf
, " %s ! %s @ %s " , qnick
-> nick
, qnick
-> ident
, qnick
-> host
-> name
-> content
);
257 if ( match ( b
-> blockstr
, hostbuf
))
260 q
-> flags
= (( q
-> flags
) & ~ QAQ_QSTATE
) | QAQ_SPAM
;
265 sendnoticetouser ( bot
-> np
, sender
, "Block caused %d message %s to be marked as spam." , spamqcount
, ( spamqcount
== 1 ) ? "" : "s" );
272 int qabot_dochanclear ( void * np
, int cargc
, char ** cargv
) {
273 nick
* sender
= ( nick
*) np
;
274 qab_bot
* bot
= qabot_getcurrentbot ();
275 channel
* cp
= qabot_getcurrentchannel ();
281 for ( s
= bot
-> nextspam
; s
; s
= ns
) {
287 bot
-> nextspam
= bot
-> lastspam
= 0 ;
289 sendmessagetochannel ( bot
-> np
, cp
, "Cleared message buffer." );
290 if ( bot
-> micnumeric
) {
292 sendmessagetochannel ( bot
-> np
, cp
, "Mic deactivated." );
298 int qabot_dochanclosechan ( void * np
, int cargc
, char ** cargv
) {
299 nick
* sender
= ( nick
*) np
;
300 qab_bot
* bot
= qabot_getcurrentbot ();
301 channel
* cp
= qabot_getcurrentchannel ();
304 localsetmodeinit (& changes
, bot
-> public_chan
-> channel
, bot
-> np
);
305 localdosetmode_simple (& changes
, CHANMODE_INVITEONLY
, 0 );
306 localsetmodeflush (& changes
, 1 );
307 sendnoticetouser ( bot
-> np
, sender
, "Public channel has been closed." );
312 int qabot_dochanconfig ( void * np
, int cargc
, char ** cargv
) {
313 nick
* sender
= ( nick
*) np
;
314 qab_bot
* bot
= qabot_getcurrentbot ();
315 channel
* cp
= qabot_getcurrentchannel ();
320 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !config <option> [<value>]" );
321 sendnoticetouser ( bot
-> np
, sender
, "Displays or sets configuration option. Valid options are:" );
322 sendnoticetouser ( bot
-> np
, sender
, "blockcontrol - Block questions containing control chars." );
323 sendnoticetouser ( bot
-> np
, sender
, "blockcolour - Block questions containing colour." );
324 sendnoticetouser ( bot
-> np
, sender
, "blockmark - Mark questions affected by blocks as spam." );
325 sendnoticetouser ( bot
-> np
, sender
, "authedonly - Accept questions from authed users only." );
326 sendnoticetouser ( bot
-> np
, sender
, "linebreak - Separate questions with line breaks." );
327 sendnoticetouser ( bot
-> np
, sender
, "flooddetect - Attempt to detect floodclone spam." );
328 sendnoticetouser ( bot
-> np
, sender
, "floodblock - Automatically block floodclone spam." );
329 sendnoticetouser ( bot
-> np
, sender
, "spamint - Text spam interval." );
330 sendnoticetouser ( bot
-> np
, sender
, "nickblockint - Time to wait before sending another question." );
331 sendnoticetouser ( bot
-> np
, sender
, "queuedqint - Queued answer spam interval." );
332 sendnoticetouser ( bot
-> np
, sender
, "mictimeout - Idle time before mic is automatically disabled." );
342 if (! ircd_strcmp ( opt
, "blockcontrol" )) {
344 if (! ircd_strcmp ( value
, "on" )) {
345 bot
-> flags
|= QAB_CONTROLCHAR
;
346 sendnoticetouser ( bot
-> np
, sender
, "Questions containing control characters will now be blocked." );
348 else if (! ircd_strcmp ( value
, "off" )) {
349 bot
-> flags
&= (~ QAB_CONTROLCHAR
);
350 sendnoticetouser ( bot
-> np
, sender
, "Questions containing control characters will no longer be blocked." );
353 sendnoticetouser ( bot
-> np
, sender
, "Invalid option. Valid options are 'on' or 'off'." );
356 sendnoticetouser ( bot
-> np
, sender
, "Control characters are currently %s blocked." , ( bot
-> flags
& QAB_CONTROLCHAR
) ? "being" : "not being" );
358 else if (! ircd_strcmp ( opt
, "blockcolour" )) {
360 if (! ircd_strcmp ( value
, "on" )) {
361 bot
-> flags
|= QAB_COLOUR
;
362 sendnoticetouser ( bot
-> np
, sender
, "Questions containing colour will now be blocked." );
364 else if (! ircd_strcmp ( value
, "off" )) {
365 bot
-> flags
&= (~ QAB_COLOUR
);
366 sendnoticetouser ( bot
-> np
, sender
, "Questions containing colour will no longer be blocked." );
369 sendnoticetouser ( bot
-> np
, sender
, "Invalid option. Valid options are 'on' or 'off'." );
372 sendnoticetouser ( bot
-> np
, sender
, "Colours are currently %s blocked." , ( bot
-> flags
& QAB_COLOUR
) ? "being" : "not being" );
374 else if (! ircd_strcmp ( opt
, "blockmark" )) {
376 if (! ircd_strcmp ( value
, "on" )) {
377 bot
-> flags
|= QAB_BLOCKMARK
;
378 sendnoticetouser ( bot
-> np
, sender
, "New blocks will automatically mark affected questions as spam." );
380 else if (! ircd_strcmp ( value
, "off" )) {
381 bot
-> flags
&= (~ QAB_BLOCKMARK
);
382 sendnoticetouser ( bot
-> np
, sender
, "New blocks will no longer automatically mark affected questions as spam." );
385 sendnoticetouser ( bot
-> np
, sender
, "Invalid option. Valid options are 'on' or 'off'." );
388 sendnoticetouser ( bot
-> np
, sender
, "Blocks are currently %s marking affected questions as spam." , ( bot
-> flags
& QAB_BLOCKMARK
) ? "" : "not " );
390 else if (! ircd_strcmp ( opt
, "authedonly" )) {
392 if (! ircd_strcmp ( value
, "on" )) {
393 bot
-> flags
|= QAB_AUTHEDONLY
;
394 sendnoticetouser ( bot
-> np
, sender
, "Questions from unauthed users will now be blocked." );
396 else if (! ircd_strcmp ( value
, "off" )) {
397 bot
-> flags
&= (~ QAB_AUTHEDONLY
);
398 sendnoticetouser ( bot
-> np
, sender
, "Questions from unauthed users will no longer be blocked." );
401 sendnoticetouser ( bot
-> np
, sender
, "Invalid option. Valid options are 'on' or 'off'." );
404 sendnoticetouser ( bot
-> np
, sender
, "Unauthed users may currently %s send questions." , ( bot
-> flags
& QAB_AUTHEDONLY
) ? "NOT " : "" );
406 else if (! ircd_strcmp ( opt
, "linebreak" )) {
408 if (! ircd_strcmp ( value
, "on" )) {
409 bot
-> flags
|= QAB_LINEBREAK
;
410 sendnoticetouser ( bot
-> np
, sender
, "Line breaks are now enabled." );
412 else if (! ircd_strcmp ( value
, "off" )) {
413 bot
-> flags
&= (~ QAB_LINEBREAK
);
414 sendnoticetouser ( bot
-> np
, sender
, "Line breaks are now disabled." );
417 sendnoticetouser ( bot
-> np
, sender
, "Invalid option. Valid options are 'on' or 'off'." );
420 sendnoticetouser ( bot
-> np
, sender
, "Line breaks are currently %s ." , ( bot
-> flags
& QAB_LINEBREAK
) ? "enabled" : "disabled" );
422 else if (! ircd_strcmp ( opt
, "flooddetect" )) {
424 if (! ircd_strcmp ( value
, "on" )) {
425 bot
-> flags
|= QAB_FLOODDETECT
;
426 sendnoticetouser ( bot
-> np
, sender
, "Flood detection is now enabled." );
428 else if (! ircd_strcmp ( value
, "off" )) {
429 bot
-> flags
&= (~ QAB_FLOODDETECT
);
430 sendnoticetouser ( bot
-> np
, sender
, "Flood detection is now disabled." );
433 sendnoticetouser ( bot
-> np
, sender
, "Invalid option. Valid options are 'on' or 'off'." );
436 sendnoticetouser ( bot
-> np
, sender
, "Flood detection is currently %s ." , ( bot
-> flags
& QAB_FLOODDETECT
) ? "enabled" : "disabled" );
438 else if (! ircd_strcmp ( opt
, "floodblock" )) {
440 if (! ircd_strcmp ( value
, "on" )) {
441 bot
-> flags
|= QAB_FLOODSTOP
;
442 sendnoticetouser ( bot
-> np
, sender
, "Flood blocking is now enabled." );
444 else if (! ircd_strcmp ( value
, "off" )) {
445 bot
-> flags
&= (~ QAB_FLOODSTOP
);
446 sendnoticetouser ( bot
-> np
, sender
, "Flood blocking is now disabled." );
449 sendnoticetouser ( bot
-> np
, sender
, "Invalid option. Valid options are 'on' or 'off'." );
452 sendnoticetouser ( bot
-> np
, sender
, "Flood blocking is currently %s ." , ( bot
-> flags
& QAB_FLOODSTOP
) ? "enabled" : "disabled" );
454 else if (! ircd_strcmp ( opt
, "mictimeout" )) {
456 int v
= ( int ) strtol ( value
, NULL
, 10 );
458 if (( v
< 0 ) || ( v
> 300 )) {
459 sendnoticetouser ( bot
-> np
, sender
, "Value must be between 0 (off) and 300." );
463 bot
-> mic_timeout
= v
;
464 sendnoticetouser ( bot
-> np
, sender
, "Value set." );
467 if ( bot
-> mic_timeout
)
468 sendnoticetouser ( bot
-> np
, sender
, "Mic timeout is currently %d second %s ." , bot
-> mic_timeout
, ( bot
-> mic_timeout
== 1 ) ? "" : "s" );
470 sendnoticetouser ( bot
-> np
, sender
, "Mic timeout is currently disabled." );
473 else if (! ircd_strcmp ( opt
, "spamint" )) {
475 int v
= ( int ) strtol ( value
, NULL
, 10 );
477 if (( v
< 1 ) || ( v
> 30 )) {
478 sendnoticetouser ( bot
-> np
, sender
, "Value must be between 1 and 30." );
482 bot
-> spam_interval
= v
;
483 sendnoticetouser ( bot
-> np
, sender
, "Value set." );
486 sendnoticetouser ( bot
-> np
, sender
, "Spam interval is currently %d second %s ." , bot
-> spam_interval
, ( bot
-> spam_interval
== 1 ) ? "" : "s" );
488 else if (! ircd_strcmp ( opt
, "nickblockint" )) {
490 int v
= ( int ) strtol ( value
, NULL
, 10 );
492 if (( v
< 1 ) || ( v
> 300 )) {
493 sendnoticetouser ( bot
-> np
, sender
, "Value must be between 1 and 300." );
498 sendnoticetouser ( bot
-> np
, sender
, "Value set." );
501 sendnoticetouser ( bot
-> np
, sender
, "Nick block interval is currently %d second %s ." , bot
-> ask_wait
, ( bot
-> ask_wait
== 1 ) ? "" : "s" );
503 else if (! ircd_strcmp ( opt
, "queuedqint" )) {
505 int v
= ( int ) strtol ( value
, NULL
, 10 );
507 if (( v
< 1 ) || ( v
> 20 )) {
508 sendnoticetouser ( bot
-> np
, sender
, "Value must be between 1 and 20." );
512 bot
-> queued_question_interval
= v
;
513 sendnoticetouser ( bot
-> np
, sender
, "Value set." );
516 sendnoticetouser ( bot
-> np
, sender
, "Queued question interval is currently %d second %s ." , bot
-> queued_question_interval
, ( bot
-> queued_question_interval
== 1 ) ? "" : "s" );
519 sendnoticetouser ( bot
-> np
, sender
, "Invalid configuration option." );
524 int qabot_dochanhelp ( void * np
, int cargc
, char ** cargv
) {
525 nick
* sender
= ( nick
*) np
;
526 qab_bot
* bot
= qabot_getcurrentbot ();
527 channel
* cp
= qabot_getcurrentchannel ();
536 if (! ircd_strcmp ( ch
, "mic" )) {
537 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !mic" );
538 sendnoticetouser ( bot
-> np
, sender
, "Turn the microphone on or off. When turned on, anything said by the microphone holder is relayed to %s ." , bot
-> public_chan
-> name
-> content
);
540 else if (! ircd_strcmp ( ch
, "clear" )) {
541 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !clear" );
542 sendnoticetouser ( bot
-> np
, sender
, "Clear currently queued text to relay, and turn off the microphone." );
544 else if (! ircd_strcmp ( ch
, "ping" )) {
545 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !ping" );
546 sendnoticetouser ( bot
-> np
, sender
, "Pings the bot." );
548 else if (! ircd_strcmp ( ch
, "config" )) {
549 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !config <option|help> [<value>]" );
550 sendnoticetouser ( bot
-> np
, sender
, "Display or set bot configuration options." );
552 else if (! ircd_strcmp ( ch
, "answer" )) {
553 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !answer <id> <answer>" );
554 sendnoticetouser ( bot
-> np
, sender
, "Answer a question." );
556 else if (! ircd_strcmp ( ch
, "block" )) {
557 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !block [<-q|-t>] <mask>" );
558 sendnoticetouser ( bot
-> np
, sender
, "Add a block, where:" );
559 sendnoticetouser ( bot
-> np
, sender
, "-q: blocks a Q account." );
560 sendnoticetouser ( bot
-> np
, sender
, "-t: blocks question text." );
561 sendnoticetouser ( bot
-> np
, sender
, "No flag results in a hostmask block." );
563 else if (! ircd_strcmp ( ch
, "listblocks" )) {
564 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !listblocks" );
565 sendnoticetouser ( bot
-> np
, sender
, "View the currently added blocks." );
567 else if (! ircd_strcmp ( ch
, "spam" )) {
568 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !spam <id>" );
569 sendnoticetouser ( bot
-> np
, sender
, "Mark a question as spam. This stops it being answered." );
571 else if (! ircd_strcmp ( ch
, "offtopic" )) {
572 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !offtopic <id>" );
573 sendnoticetouser ( bot
-> np
, sender
, "Mark a question as off-topic. This stops it being answered." );
575 else if (! ircd_strcmp ( ch
, "unblock" )) {
576 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !unblock [<-q|-t>] <mask>" );
577 sendnoticetouser ( bot
-> np
, sender
, "Removes a block. See \" !help block \" for a description of the flags." );
579 else if (! ircd_strcmp ( ch
, "reset" )) {
580 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !reset <all|questions|blocks|stats>" );
581 sendnoticetouser ( bot
-> np
, sender
, "Reset the questions, blocks or both; or the stats." );
583 else if (! ircd_strcmp ( ch
, "closechan" )) {
584 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !closechan" );
585 sendnoticetouser ( bot
-> np
, sender
, "Closes the public channel." );
587 else if (! ircd_strcmp ( ch
, "openchan" )) {
588 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !openchan" );
589 sendnoticetouser ( bot
-> np
, sender
, "Opens the public channel." );
591 else if (! ircd_strcmp ( ch
, "status" )) {
592 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !status" );
593 sendnoticetouser ( bot
-> np
, sender
, "Displays some status information and statistics." );
595 else if (! ircd_strcmp ( ch
, "help" )) {
596 sendnoticetouser ( bot
-> np
, sender
, "Syntax !help [<command>]" );
597 sendnoticetouser ( bot
-> np
, sender
, "List available commands or view help for a particular command." );
600 sendnoticetouser ( bot
-> np
, sender
, "No help available for ' %s '." , ch
);
604 sendnoticetouser ( bot
-> np
, sender
, "The following channel commands are recognised:" );
605 sendnoticetouser ( bot
-> np
, sender
, "!answer - Answer a question." );
606 sendnoticetouser ( bot
-> np
, sender
, "!block - Block a hostmask, account or string." );
607 sendnoticetouser ( bot
-> np
, sender
, "!clear - Clear currently queued text to spam." );
608 sendnoticetouser ( bot
-> np
, sender
, "!closechan - Close the public channel." );
609 sendnoticetouser ( bot
-> np
, sender
, "!config - Display or set bot configuration options." );
610 sendnoticetouser ( bot
-> np
, sender
, "!help - List commands or view the help for a command" );
611 sendnoticetouser ( bot
-> np
, sender
, "!listblocks - List currently added blocks." );
612 sendnoticetouser ( bot
-> np
, sender
, "!mic - Turn the microphone on or off." );
613 sendnoticetouser ( bot
-> np
, sender
, "!offtopic - Mark a question or questions as off-topic." );
614 sendnoticetouser ( bot
-> np
, sender
, "!openchan - Open the public channel." );
615 sendnoticetouser ( bot
-> np
, sender
, "!ping - Ping the bot." );
616 sendnoticetouser ( bot
-> np
, sender
, "!reset - Clear all blocks, questions or both." );
617 sendnoticetouser ( bot
-> np
, sender
, "!spam - Mark a question or questions as spam." );
618 sendnoticetouser ( bot
-> np
, sender
, "!status - Display some status statistics." );
619 sendnoticetouser ( bot
-> np
, sender
, "!unblock - Remove a block." );
620 sendnoticetouser ( bot
-> np
, sender
, "End of list." );
626 int qabot_dochanlistblocks ( void * np
, int cargc
, char ** cargv
) {
627 nick
* sender
= ( nick
*) np
;
628 qab_bot
* bot
= qabot_getcurrentbot ();
629 channel
* cp
= qabot_getcurrentchannel ();
632 if (!( b
= bot
-> blocks
)) {
633 sendnoticetouser ( bot
-> np
, sender
, "There are no blocks currently added." );
637 sendnoticetouser ( bot
-> np
, sender
, "Type: Hostmask/Account/Textmask:" );
639 for (; b
; b
= b
-> next
) {
640 if ( b
-> type
== QABBLOCK_ACCOUNT
)
641 sendnoticetouser ( bot
-> np
, sender
, "A %s " , b
-> blockstr
);
642 else if ( b
-> type
== QABBLOCK_HOST
)
643 sendnoticetouser ( bot
-> np
, sender
, "H %s " , b
-> blockstr
);
645 sendnoticetouser ( bot
-> np
, sender
, "T %s " , b
-> blockstr
);
648 sendnoticetouser ( bot
-> np
, sender
, "End of list." );
653 int qabot_dochanmic ( void * np
, int cargc
, char ** cargv
) {
654 nick
* sender
= ( nick
*) np
;
655 qab_bot
* bot
= qabot_getcurrentbot ();
656 channel
* cp
= qabot_getcurrentchannel ();
658 if ( bot
-> micnumeric
) {
659 if ( bot
-> micnumeric
== sender
-> numeric
) {
661 sendmessagetochannel ( bot
-> np
, cp
, "Mic deactivated." );
663 qabot_spamstored (( void *) bot
);
666 bot
-> lastmic
= time ( NULL
);
667 bot
-> micnumeric
= sender
-> numeric
;
668 sendmessagetochannel ( bot
-> np
, cp
, " %s now has the mic. Anything said by %s will be relayed in %s ." ,
669 sender
-> nick
, sender
-> nick
, bot
-> public_chan
-> name
-> content
);
670 deleteschedule ( 0 , qabot_spamstored
, ( void *) bot
);
674 bot
-> lastmic
= time ( NULL
);
675 bot
-> micnumeric
= sender
-> numeric
;
676 sendmessagetochannel ( bot
-> np
, cp
, "Mic activated. Anything said by %s will be relayed in %s ." ,
677 sender
-> nick
, bot
-> public_chan
-> name
-> content
);
678 deleteschedule ( 0 , qabot_spamstored
, ( void *) bot
);
684 int qabot_dochanmoo ( void * np
, int cargc
, char ** cargv
) {
685 nick
* sender
= ( nick
*) np
;
686 qab_bot
* bot
= qabot_getcurrentbot ();
687 channel
* cp
= qabot_getcurrentchannel ();
689 int i
, moocount
= 5 + ( rand () % 40 );
692 for ( i
= 1 ; i
< moocount
; i
++)
693 moostr
[ i
] = (( rand () % 100 ) > 50 ) ? 'o' : '0' ;
696 sendmessagetochannel ( bot
-> np
, cp
, " %s " , moostr
);
701 int qabot_dochanofftopic ( void * np
, int cargc
, char ** cargv
) {
702 nick
* sender
= ( nick
*) np
;
703 qab_bot
* bot
= qabot_getcurrentbot ();
704 channel
* cp
= qabot_getcurrentchannel ();
710 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !spam <id> [<id> ... <id>]" );
714 for ( i
= 0 ; i
< cargc
; i
++) {
715 id
= strtol ( cargv
[ i
], NULL
, 10 );
717 if (( id
< 1 ) || ( id
> bot
-> lastquestionID
)) {
718 sendnoticetouser ( bot
-> np
, sender
, "Invalid question ID %d ." , id
);
722 for ( q
= bot
-> questions
[ id
% QUESTIONHASHSIZE
]; q
; q
= q
-> next
)
727 sendnoticetouser ( bot
-> np
, sender
, "Can't find question %d ." , id
);
731 switch ( q
-> flags
& QAQ_QSTATE
) {
733 sendnoticetouser ( bot
-> np
, sender
, "Question %d has already been answered." , id
);
737 sendnoticetouser ( bot
-> np
, sender
, "Question %d has already been marked as off-topic." , id
);
741 sendnoticetouser ( bot
-> np
, sender
, "Question %d has already been marked as spam." , id
);
748 q
-> flags
= (( q
-> flags
) & ~ QAQ_QSTATE
) | QAQ_OFFTOPIC
;
749 sendnoticetouser ( bot
-> np
, sender
, "Question %d has been marked as off-topic." , id
);
755 int qabot_dochanopenchan ( void * np
, int cargc
, char ** cargv
) {
756 nick
* sender
= ( nick
*) np
;
757 qab_bot
* bot
= qabot_getcurrentbot ();
758 channel
* cp
= qabot_getcurrentchannel ();
761 localsetmodeinit (& changes
, bot
-> public_chan
-> channel
, bot
-> np
);
762 localdosetmode_simple (& changes
, CHANMODE_MODERATE
| CHANMODE_DELJOINS
, CHANMODE_INVITEONLY
);
763 localsetmodeflush (& changes
, 1 );
764 sendnoticetouser ( bot
-> np
, sender
, "Public channel has been opened." );
769 int qabot_dochanping ( void * np
, int cargc
, char ** cargv
) {
770 nick
* sender
= ( nick
*) np
;
771 qab_bot
* bot
= qabot_getcurrentbot ();
772 channel
* cp
= qabot_getcurrentchannel ();
774 sendmessagetochannel ( bot
-> np
, cp
, "pong!" );
779 int qabot_dochanreset ( void * np
, int cargc
, char ** cargv
) {
780 nick
* sender
= ( nick
*) np
;
781 qab_bot
* bot
= qabot_getcurrentbot ();
782 channel
* cp
= qabot_getcurrentchannel ();
786 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !reset <blocks|questions|stats|all>" );
790 if (! ircd_strcmp ( cargv
[ 0 ], "blocks" ))
792 else if (! ircd_strcmp ( cargv
[ 0 ], "questions" ))
794 else if (! ircd_strcmp ( cargv
[ 0 ], "stats" ))
796 else if (! ircd_strcmp ( cargv
[ 0 ], "all" ))
799 sendnoticetouser ( bot
-> np
, sender
, "Unknown parameter: %s ." , cargv
[ 0 ]);
806 while ( bot
-> blocks
) {
808 bot
-> blocks
= bot
-> blocks
-> next
;
814 bot
-> block_count
= 0 ;
816 sendnoticetouser ( bot
-> np
, sender
, "Reset (blocks): Done." );
823 for ( i
= 0 ; i
< QUESTIONHASHSIZE
; i
++) {
824 while ( bot
-> questions
[ i
]) {
825 q
= bot
-> questions
[ i
];
826 bot
-> questions
[ i
] = bot
-> questions
[ i
]-> next
;
835 bot
-> lastquestionID
= 0 ;
838 sendnoticetouser ( bot
-> np
, sender
, "Reset (questions): Done." );
844 sendnoticetouser ( bot
-> np
, sender
, "Reset (stats): Done." );
850 int qabot_dochanspam ( void * np
, int cargc
, char ** cargv
) {
851 nick
* sender
= ( nick
*) np
;
852 qab_bot
* bot
= qabot_getcurrentbot ();
853 channel
* cp
= qabot_getcurrentchannel ();
859 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !spam <id> [<id> ... <id>]" );
863 for ( i
= 0 ; i
< cargc
; i
++) {
864 id
= strtol ( cargv
[ i
], NULL
, 10 );
866 if (( id
< 1 ) || ( id
> bot
-> lastquestionID
)) {
867 sendnoticetouser ( bot
-> np
, sender
, "Invalid question ID %d ." , id
);
871 for ( q
= bot
-> questions
[ id
% QUESTIONHASHSIZE
]; q
; q
= q
-> next
)
876 sendnoticetouser ( bot
-> np
, sender
, "Can't find question %d ." , id
);
880 switch ( q
-> flags
& QAQ_QSTATE
) {
882 sendnoticetouser ( bot
-> np
, sender
, "Question %d has already been answered." , id
);
886 sendnoticetouser ( bot
-> np
, sender
, "Question %d has already been marked as off-topic." , id
);
890 sendnoticetouser ( bot
-> np
, sender
, "Question %d has already been marked as spam." , id
);
897 q
-> flags
= (( q
-> flags
) & ~ QAQ_QSTATE
) | QAQ_SPAM
;
898 sendnoticetouser ( bot
-> np
, sender
, "Question %d has been marked as spam." , id
);
904 int qabot_dochanstatus ( void * np
, int cargc
, char ** cargv
) {
905 nick
* sender
= ( nick
*) np
;
906 qab_bot
* bot
= qabot_getcurrentbot ();
907 channel
* cp
= qabot_getcurrentchannel ();
909 sendnoticetouser ( bot
-> np
, sender
, "Lines spammed: %d " , bot
-> spammed
);
910 sendnoticetouser ( bot
-> np
, sender
, "Questions asked: %d " , bot
-> lastquestionID
);
911 sendnoticetouser ( bot
-> np
, sender
, "Questions answered: %d " , bot
-> answered
);
912 sendnoticetouser ( bot
-> np
, sender
, "Blocks: %d " , bot
-> block_count
);
913 /*sendnoticetouser(bot->np, sender, "Question interval: %d seconds", bot->question_interval);*/
914 sendnoticetouser ( bot
-> np
, sender
, "Spam interval: %d seconds" , bot
-> spam_interval
);
915 sendnoticetouser ( bot
-> np
, sender
, "Nick block interval: %d seconds" , bot
-> ask_wait
);
916 sendnoticetouser ( bot
-> np
, sender
, "Queued question interval: %d seconds" , bot
-> queued_question_interval
);
917 sendnoticetouser ( bot
-> np
, sender
, "Block control chars: %s " , ( bot
-> flags
& QAB_CONTROLCHAR
) ? "Yes" : "No" );
918 sendnoticetouser ( bot
-> np
, sender
, "Block colour: %s " , ( bot
-> flags
& QAB_COLOUR
) ? "Yes" : "No" );
919 sendnoticetouser ( bot
-> np
, sender
, "Authed users only: %s " , ( bot
-> flags
& QAB_AUTHEDONLY
) ? "Yes" : "No" );
920 sendnoticetouser ( bot
-> np
, sender
, "Line break: %s " , ( bot
-> flags
& QAB_LINEBREAK
) ? "Yes" : "No" );
921 sendnoticetouser ( bot
-> np
, sender
, "Question flood detection: %s " , ( bot
-> flags
& QAB_FLOODDETECT
) ? "Yes" : "No" );
922 sendnoticetouser ( bot
-> np
, sender
, "Question flood blocking: %s " , ( bot
-> flags
& QAB_FLOODSTOP
) ? "Yes" : "No" );
923 sendnoticetouser ( bot
-> np
, sender
, "Blocks mark as spam: %s " , ( bot
-> flags
& QAB_BLOCKMARK
) ? "Yes" : "No" );
924 if ( bot
-> micnumeric
) {
925 nick
* mnick
= getnickbynumeric ( bot
-> micnumeric
);
927 sendnoticetouser ( bot
-> np
, np
, "Mic: Enabled ( %s )" , mnick
? mnick
-> nick
: "UNKNOWN" );
930 sendnoticetouser ( bot
-> np
, np
, "Mic: Disabled" );
931 sendnoticetouser ( bot
-> np
, sender
, "Mic timeout: %d " , bot
-> mic_timeout
);
932 /*sendnoticetouser(bot->np, sender, "");*/
937 int qabot_dochanunblock ( void * np
, int cargc
, char ** cargv
) {
938 nick
* sender
= ( nick
*) np
;
939 qab_bot
* bot
= qabot_getcurrentbot ();
940 channel
* cp
= qabot_getcurrentchannel ();
946 sendnoticetouser ( bot
-> np
, sender
, "Syntax: !unblock [-q|-t] <account|mask>" );
951 if (! ircd_strncmp ( cargv
[ 0 ], "-q" , 2 )) {
952 type
= QABBLOCK_ACCOUNT
;
958 else if (! ircd_strncmp ( cargv
[ 0 ], "-t" , 2 )) {
959 type
= QABBLOCK_TEXT
;
963 sendnoticetouser ( bot
-> np
, sender
, "Invalid flag." );
968 type
= QABBLOCK_HOST
;
972 for ( b
= bot
-> blocks
; b
; b
= b
-> next
) {
976 if (! ircd_strcmp ( b
-> blockstr
, ch
)) {
978 b
-> next
-> prev
= b
-> prev
;
980 b
-> prev
-> next
= b
-> next
;
982 bot
-> blocks
= b
-> next
;
989 sendnoticetouser ( bot
-> np
, sender
, "Block removed." );
994 sendnoticetouser ( bot
-> np
, sender
, "No such block." );