-
Notifications
You must be signed in to change notification settings - Fork 2
/
QwizBot.pl
executable file
·1963 lines (1683 loc) · 77.7 KB
/
QwizBot.pl
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#=--------------------------------------=
# Qwizbot - QwizBot.pl
# Copyright (C) 2018 Rubin
# based on Truevia by Ed Halley and other authors.
#
# This program is free software. You may use, modify, and distribute it
# under the terms of the Perl Artistic license, avialible on the world
# wide web at:
# http://www.perl.com/pub/a/language/misc/Artistic.html
# and included in the file LICENSE.
#
# $Id: $
#
#=--------------------------------------=
# Configuration Section; Change the following
# variables to suit you.
# This is the bots default nickname, and how it refers to itself online.
# Change it to what you want your bots nick to be.
$botname = 'Qwizbot';
# actually the irc username sent to the server (ident
# depends on your identd install). set to $botname by
# default.
$ident = $botname;
# This is the bots 'real name' shown in /whois on IRC.
$realname = 'Qwizbot Trivia Bot';
# These are the usermodes the bot sets on itself.
# +i-d is a good default.
$botusermode = '+i-d';
# This password is used for nickserv/authserv login
# currently this is under construction.
#$sPassword = 'xyzpasswordpdq';
# This is the channel the bot will join and play trivia in
$botchan = '#computerquiz';
# The modes the bot will set in the channel.
# (TODO currently does not work, need to check when
# we get ops to do this)
$botchanmode = '+nt';
# The bot will respond to commands in channel that begin with this character
$cmdchar = '!';
# The bot will occationally tell people to visit here
# for information about your channel.
$homeurl = 'http://afternet.org/';
# The bot will kickban anyone who says anything matching the following
# regex:
$sCurses = '\b(bitch|cunt)';
# End of the configuration section. Edit code below
# only if you are making code modifications.
#----------------------------------------------------------------------------
$botnick = $botname;
$oldbotnick = '';
$botwantnick = $botnick;
if ($ARGV[0] eq 'test') {
$botchan .= $botchan.'-test';
&DEBUGMSG("Test BOT using $botchan.");
}
$serverfile = lc($botname . '.servers.txt');
$playerfile = lc($botname . '.players.txt');
$suggestionfile = lc($botname . '.suggestions.txt');
$nBackupSpan = (60*60*24*1);
# Thes arnt used anymore, see botname.servers.txt
$ircserver = '';
$ircport = '';
@servers = (
'youri-irc-server:6667',
);
#----------------------------------------------------------------------------
use FindBin;
use lib $FindBin::Bin;
require irc;
require prose;
require qwizgame;
require qwizplayer;
require qwizmail;
require qwizvote;
use POSIX;
#----------------------------------------------------------------------------
# channel police:
$bDebug = 1;
$bDebug = 1 if ($botchan =~ /test/i);
$bKickComics = 1;
$bKickGuests = 1;
$bKickCurses = 1;
$nTimeIdleWarning = (60*10);
$nTimeIdleKick = (60*25);
$joinsseen = 0;
$userjoins = 0;
$bankicks = 0;
$kicksseen = 0;
$tWhenLastReported = 0;
$nAntiFloodReport = 10;
$tCurseProbation = (60*60);
#----------------------------------------------------------------------------
# channel status;
$bQuit = 0;
$sForceTopic = '';
$bX2 = 0;
$bNickServ = 0;
$bChanServ = 1;
$bIRCop = 0;
$bServerOverride = 0;
$bNickChange = 1;
@modequeue = ();
#----------------------------------------------------------------------------
%send_timer = ();
$connected = 0;
sub initializebot()
{
&DEBUGMSG("Initializing bot.");
&DEBUGMSG(readservers($serverfile) . " servers on file");
initializegame();
&DEBUGMSG(readplayers() . " players on file");
%send_timer = ();
}
sub savebot
{
savegame();
&writeplayers();
}
$irc_housekeeping = 0;
sub initbot
{
ircsendline(S, "MODE $botnick $botusermode");
ircsendline(S, "JOIN $botchan");
$irc_housekeeping = time();
# uh. cant do this unless we have ops, so
# lets do it WHEN we get ops maybe?
#ircsendline(S, "MODE $botchan $botchanmode");
# these are things we might want to do after connecting..
#if ($bIRCop) { &OPER("$botnick $sPassword"); }
#if ($bX2) { &PRIVMSG('authserv', "$botchan LOGIN $botnick $sPassword"); }
#if ($bX2) { &PRIVMSG('x3', "up #core"); }
#if ($bNickServ) { &PRIVMSG('nickserv', "IDENTIFY $sPassword"); }
#if ($bNickServ) { &PRIVMSG('x3', "IDENTIFY $botchan $sPassword"); }
#if ($bChanServ) { &PRIVMSG('authserv', "auth $botnick $sPassword"); }
}
sub refreshbot
{
if($irc_housekeeping + 30 < time()) {
&DEBUGMSG("DEBUG: Running refreshbot housekeeping");
if($botnick ne $botwantnick) {
#$botnick = $botwantnick;
ircsendline(S, "NICK $botwantnick");
}
$irc_housekeeping = time();
}
}
sub quitbot
{
foreach $nick (keys %active)
{
&deactivateplayer($nick);
}
&QUIT();
$bQuit = 1;
}
#sub checknick
#{
# if ($botnick = $botname)
# {
# $bNickChange = 1;
# }
# else {$bNickChange = 0;}
#}
sub terminatebot
{
savebot();
&DEBUGMSG("Terminated bot.");
}
#----------------------------------------------------------------------------
sub readservers
{
local($filename) = @_;
if (!open(INFO, $filename))
{
&DEBUGMSG("Cannot read $filename.");
return 0;
}
@servers = ();
my $count = 0;
while (!eof(INFO))
{
$serversline = <INFO>;
$serversline =~ s/\n//;
$serversline =~ s/\r//;
if ($serversline =~ /^\s*\#/)
{ next; }
push(@servers, $serversline);
$count++;
}
close(INFO);
$count;
}
#----------------------------------------------------------------------------
#
# main loop
#
sub main
{
if ($bDebug != 0)
{
&DEBUGMSG("(----DEBUGGING DIAGNOSTICS ENABLED----)");
}
initializebot();
$retrytime = 0;
SERVERLOOP: while (!$bQuit)
{
savebot();
$retrytime += 1;
# pick $ircserver from a list, retry another server if fails to connect
# this can be overridden with a /msg bot /server command,
# but the bot still falls back to the list if that server fails
#
if (($retrytime % 3) == 0)
{
my ($head) = splice(@servers, 0, 1);
push(@servers, $head);
$bServerOverride = 0;
$retrytime = 0;
}
if ($bServerOverride == 0)
{
($ircserver, $ircport) = split(/:/, $servers[0]);
$bServerOverride = 0;
}
my $l = localtime();
&DEBUGMSG("Trying $ircserver... ($l)");
%active = ();
%authed = ();
%present = ();
# bind socket, connect.
{
$sockaddr = 'S n a4 x8';
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port) = getservbyname('6667', 'tcp');
($name, $aliases, $type, $len, $thataddr) = gethostbyname($ircserver);
$this = pack($sockaddr, 2, 0, $thisaddr);
$that = pack($sockaddr, 2, $ircport, $thataddr);
socket(S, 2, 1, $proto) || do { &DEBUGMSG("$! at socket() - retrying"); sleep(20); next SERVERLOOP; };
bind(S, $this) || do { &DEBUGMSG("$! at bind() - retrying"); sleep(20); next SERVERLOOP; };
&DEBUGMSG("Connecting to $ircserver...");
connect(S, $that) || do { &DEBUGMSG("$! at connect() - retrying"); sleep(20); next SERVERLOOP; };
&DEBUGMSG("Connected.");
$f = fileno(S);
# turn on output autoflushing:
select(S); $| = 1; select(STDOUT);
$connected = 1;
}
$conntime = time();
# establish IRC session
{
$botnick = $botwantnick;
ircsendline(S, "NICK $botnick");
# login on connect stuff.
ircsendline(S, "PASS /".$botnick."/".$sPassword);
ircsendline(S, "USER $ident zero zero :$realname");
while ($connected)
{
$_ = ircreadline(S, 1);
if(!defined($_) ) {
#TODO read timed out - check if we should give up
next;
}
if($_ eq EOF)
{
&DEBUGMSG("Error from socket, terminating reg loop");
$connected = 0;
last;
}
elsif ($_ eq '') {
# empty line, ignore
next;
}
elsif (/^PING (\S+)/i) {
&r_pong($1); next;
}
elsif (/:(\S+)\s+001\s+/) { # :Welcome to network.
if (lc($1) ne lc($ircserver)) {
&DEBUGMSG("Server name shift: $ircserver -> $1");
$ircserver = $1;
}
}
#:SVC-EU.AfterNET.Services 433 * triviabot :Nickname is already in use.
elsif (/:(\S+)\s+433\s+\S+\s+(\S+)/) {# :Nickname is already in use.
$botnick = $2 . "_";
ircsendline(S, "NICK $botnick");
#if ($botnick ne $botwantnick)
#{
# my @r = ('A', 'B', 'C', 'D', 'E', 'F');
# my $t = $r[int(rand()*($#r+1))];
# $botnick = $botwantnick . $t;
# ircsendline(S,"NICK $botnick");
#}
#else
#{
# $botnick .= '_';
# ircsendline(S, "NICK $botnick");
#}
}
elsif (/:(\S+)\s+(376|422)\s+/) {
last;
} # :End of MOTD
}
if($connected) {
&DEBUGMSG("Connected to $ircserver.");
}
}
if(!$connected) {
last;
}
$retrytime = 0;
# get back into the channel
{
initbot();
#&CHANACTION("is connecting from $ircserver:$ircport.");
# need to sleep while x3 gives us permission
#sleep 4;
}
$chantime = time();
&nextstate();
# server loop
#{
while (1)
{
$_ = ircreadline(S, 0);
if(!defined($_)) {
next;
}
elsif($_ eq EOF) {
&DEBUGMSG("DEBUG: Error from socket, exiting loop.");
$connected = 0;
last;
}
elsif ($_ eq '') {
next;
}
elsif ($_ =~ /\000/) {
&DEBUGMSG("-------------null on line\!");
next;
}
elsif (/^PING (\S+)/i) {
&r_pong($1);
next;
}
elsif (/^:(\S+)\!(\S+) PRIVMSG (\#\S+) :$cmdchar(.+)/i) {
&r_command($1,$2,$4,1); next;
}
elsif (/^:(\S+)\!(\S+) PRIVMSG $botnick :[$cmdchar]?(.+)/i) {
&r_command($1,$2,$3,0); next;
}
elsif (/^:(\S+)\!(\S+) PRIVMSG (\#\S+) :(.+)/i) {
&r_say($1,$2,$4); next;
}
elsif (/^:(\S+)\!(\S+) PRIVMSG $botnick :$__ctcp(.+)$__ctcp/i) {
&r_ctcpquery($1,$2,$3); next;
}
elsif (/^:(\S+)\!(\S+) PRIVMSG (\#\S+) :$__ctcp(.+)$__ctcp/i) {
&r_ctcpquery($1,$2,$4); next;
}
elsif (/^:(\S+)\!(\S+) NOTICE $botnick :$__ctcp(.+)$__ctcp/i) {
&r_ctcpreply($1,$2,$3); next;
}
elsif (/^:(\S+)\!(\S+) JOIN :(\S+)/i) {
&r_join($1,$2); next;
}
elsif (/^:(\S+) 353 [^:]*:(.+)$/i) {# 353 RPL_NAMREPLY
&r_names($2); next;
}
elsif (/^:(\S+) 302 (\S+) :(.+?)\=(\+|\-)?(\S+)$/i) {# 302 RPL_USERHOST
&r_join($3,$5); next;
}
elsif (/^:(\S+) (\S+) (\S+) :(\S+)\=(\+|\-)(\S+)/i) {
&r_join($4,$6); next;
}
elsif (/^:(\S+)\!(\S+) NICK :(\S+)/i) {
if (lc($1) ne lc($3)) {
#If Its me. upbate my botnick
if(lc($1) eq lc($botnick)) {
$botnick = $3;
}
else {
# shouldn't we just follow them??
&r_part($1);
&DEVOICE($3);
&r_join($3,$2);
}
}
next;
}
elsif (/^:(\S+)\!(\S+) PART (\S+)/i) {
&r_part($1); next;
}
elsif (/^:(\S+)\!(\S+) KICK (\S+) (\S+)/i) {
&r_part($4); next;
}
elsif (/^:(\S+)\!(\S+) QUIT/i) {
&r_part($1); next;
}
elsif (/:(\S+) 433 (\S+) (\S+)/) {# :Nickname is already in use.
# Nick change failed. Were back where we were.
$botnick = $2;
#if ($botnick ne $botwantnick)
#{
# my @r = ('A', 'B', 'C', 'D', 'E', 'F');
# my $t = $r[int(rand()*($#r+1))];
# $botnick = $botwantnick . $t;
# ircsendline(S, "NICK $botnick");
#}
next;
}
elsif (/^:\S+ TOPIC/i) {
next;
}
elsif (/^:\S+ MODE/i) {
next;
}
elsif (/^:\S+ 482/) {# 482 ERR_CHANOPRIVSNEEDED
next;
}
# Server notices (user notices caught above)
if (/^:\S+ NOTICE/i) {
next;
}
&DEBUGMSG("Line didn't match a rule, ignoring");
}
continue
{
#
# check the queue of bans to free
#
my $now = time();
# do basic housekeeping such as
# fixing wanted channels and nicks
refreshbot();
while (defined($bans[0]))
{
my @ban = split(/:/, $bans[0]);
if ($ban[0] > $now) { last; }
&DEBUGMSG("unbanning ($ban[1])");
&UNBAN($ban[1]);
splice(@bans, 0, 1);
}
#
# run the game
#
pumpgame();
}
#}
if(!$connected) {
last;
}
}
terminatebot();
}
#----------------------------------------------------------------------------
sub isauthed
{
local($nick) = @_;
$nick = lc($nick);
if (defined($authed{$nick}))
{ return 1; }
my @player = getplayer($nick);
if ($player[$sAuthPassword] eq '')
{ return 1; }
return 0;
}
sub isreportokay
{
my $now = time();
if ($tWhenLastReported + $nAntiFloodReport > $now) { return 0; }
$tWhenLastReported = $now;
return 1;
}
sub qwizkick
{
local($nick, $by, $reason) = @_;
&KICK($nick, $reason);
&DEBUGMSG("** Kicked $nick out, $by ($reason)");
$player[$nTimesKicked]++;
setplayer(@player);
deactivateplayer($player[$sNick]);
}
sub qwizban
{
local($nick, $host, $by, $reason, $duration) = @_;
$duration = 5*60*60 if (!defined($duration));
&DEBUGMSG("** Ban+Kicked $nick!$host out, $by ($reason)");
my $found = 0;
my $added = 0;
my $expires = $duration + time();
foreach $b (0 .. $#bans)
{
my @ban = split(/:/, $bans[$b]);
if ($ban[1] =~ /\Q$host\E/)
{
&DEBUGMSG("** $host already in ban queue");
$found = 1;
last;
}
if ($ban[0] >= $duration)
{
splice(@bans, $b, 0, "$expires:*\!$host");
$added = 1;
last;
}
}
if (!$found)
{ &BAN($nick, $host, "$reason (" . describetimespan($duration) . " ban)"); }
if (!$added)
{ push(@bans, "$expires:*\!$host"); }
deactivateplayer($nick);
}
sub idlecheck
{
foreach $nick (keys %active)
{
my @player = getplayer($nick);
if ($player[$sFlags] =~ /[dio]/) { next; }
my $a = (time() - $player[$tWhenMet]);
my $t = (time() - $player[$tWhenLastSaid]);
my $klimit = $nTimeIdleKick;
my $wlimit = $nTimeIdleWarning;
if ($a < ($klimit * 2) || ($player[$sFlags] !~ /f/))
{
$klimit = $klimit / 3;
$wlimit = $wlimit / 3;
}
# decreasing order of warning: kick, second warning, first warning
# (ensures you don't get lagged out and all three happen at once)
#
if ($t >= $klimit)
{
&DEBUGMSG("banning ($nick, $present{lc($nick)}, $botnick, \"Play, or chat, or leave, but don\'t idle in $botchan; thanks.\", 15)");
&qwizban($nick, $present{lc($nick)}, $botnick, "Play, or chat, or leave, but don't idle in $botchan; thanks.", 15);
}
elsif ($t >= (($wlimit+$klimit)/2) && ($warned{lc($nick)} < 2))
{
&DEBUGMSG("warning ($nick, \"$botchan does not allow idling; please participate in the channel, or leave it.\")");
$warned{lc($nick)} = 2;
&NOTICE($nick, "$botchan does not allow idling; please participate in the channel, or leave it.");
# noticeplayersbyflag('o', '', "Player $nick was just given their first idle warning.");
}
elsif ($t >= $wlimit && !defined($warned{lc($nick)}))
{
&DEBUGMSG("warning ($nick, \"$botnick and your fellow players would like you to contribute in $botchan.\")");
$warned{lc($nick)} = 1;
&NOTICE($nick, "$botnick and your fellow players would like you to contribute in $botchan.");
noticeplayersbyflag('o', '', "Player $nick was just given their second idle warning.");
}
}
}
#----------------------------------------------------------------------------
sub r_join
{
local($nick, $host) = @_;
if ($nick eq '' || $host eq '')
{
return;
}
$joinsseen = $joinsseen + 1;
$lastjoin = $nick;
$present{lc($nick)} = $host;
&activateplayer($nick, $host);
if (isactive($nick))
{
my @player = getplayer($nick);
$player[$tWhenLastSaid] = time();
setplayer(@player);
if (isgmailwaiting($nick))
{
&NOTICE($nick, "You have game mail waiting. Use !gmail to read it.");
}
}
}
sub r_names
{
local($nicklist) = @_;
my @nicks = split(/\s/, $nicklist);
my @users = ();
foreach $i (0 .. $#nicks)
{
my $nick = $nicks[$i];
if($nick =~ /^[+@]*([][A-Za-z0-9|^{}`_-]+)$/) {
my $user = $1;
if(lc($user) eq lc($botnick)) {
next; # ignore ourselves
}
#my ($user) = ($nick =~ /^[@+-]?(\S+)/);
#if ($user eq '') {
# next;
#}
&DEBUGMSG("Found user $nick = $user in names reply");
push (@users, $user);
}
else {
&DEBUGMSG("'$nick' didn't match names parser");
}
}
while ($#users >= 0)
{
my $a = shift(@users);
my @player = getplayer($a);
r_join($a, 'unknownhost');
if ($player[$sFlags] =~ /[ox]/)
{
# &USERHOST($a);
}
}
}
sub r_part
{
local($nick) = @_;
&deactivateplayer($nick);
delete $present{lc($nick)};
delete $active{lc($nick)};
delete $authed{lc($nick)};
if ($bX2 && lc($nick) eq 'X2')
{
foreach $p (keys %authed)
{
my @player = getplayer($p);
if ($player[$sFlags] =~ /o/) { &OPS($p); }
}
}
}
sub r_say
{
local($cmdnick,$cmdhost,$said) = @_;
if ($said eq '+') { return; }
ircmention($cmdnick,$cmdhost);
if ($cmdchan eq $botnick)
{ $cmdchan = $cmdnick; }
$said =~ s/\n//;
$said =~ s/\r//;
if (!isactive($cmdnick))
{
&DEBUGMSG("in r_say() activating $cmdnick ($cmdhost)");
activateplayer($cmdnick, $cmdhost);
if (!isactive($cmdnick)) {
&DEBUGMSG("$cmdnick still not active though!!");
return;
}
}
my @player = getplayer($cmdnick);
if ($player[$sFlags] =~ /[*d]/)
{ return; }
#
# recognize game answers
#
my $now = time();
if ($bKickComics)
{
if (($said =~ /^\# Appears as /) || ($said =~ /^\(#/))
{
&PRIVMSG($cmdnick,
"Comic Chat will not work with $botnick. Switch to Text Mode, and come back to $botchan. " .
"To use Text Mode, look under the View menu for Plain Text. Or, click the button on your toolbar labeled Text View.");
&PRIVMSG($cmdnick,
"The operators of $botchan suggest using mIRC instead of MSCHAT. See www.mirc.com for that shareware product.");
&KICK($cmdnick, " Come back in Text Mode. (See your private message to learn how.) ");
return;
}
}
if ($bKickGuests)
{
if ($cmdnick =~ /^Guest\d+/i)
{
&PRIVMSG($cmdnick,
"Guest nicknames will not work with $botnick. Choose a unique nickname, and come back to $botchan. " .
"To set a nickname, try typing /nick newname, or see your IRC program's online help about nicks.");
&KICK($cmdnick, " Come back with a personal nickname. (See your private message to learn how.) ");
return;
}
}
if ($bKickCurses)
{
#if (($player[$tWhenMet] + $tCurseProbation) > $now)
#{
if (($said =~ /$sCurses/i) ||
($cmdnick =~ /$sCurses/i) ||
($cmdhost =~ /$sCurses/i))
{
qwizban($cmdnick, $cmdhost, $botnick, "No profanity in the channel, please.", 60);
deactivateplayer($cmdnick);
return;
}
#}
}
gamesaid($cmdnick, $said, @player);
#
# all game processing of what they said is done; we can mangle $said now
#
@player = getplayer($cmdnick); # again!
$said =~ s/\://g;
$said =~ s/\t//g;
$said =~ s/\º//g;
$said =~ s/\|//g;
$said =~ s/[^\x20-\x7F]/\-/g;
my $t = ($now - $player[$tWhenLastSaid]);
if ($said eq $player[$sLastSaid] && $t < 10)
{
$player[$nTimesSaid]++;
}
else
{
$player[$nTimesSaid] = 1;
}
$player[$sLastSaid] = $said;
$player[$tWhenLastSaid] = time();
setplayer(@player);
if ($player[$sFlags] =~ /[fo]/)
{ return; }
if ($player[$nTimesSaid] > 2)
{
&NOTICE($player[$sNick], "You talk too much, and you're not being very entertaining.");
}
if ($player[$nTimesSaid] > 3)
{
qwizkick($cmdnick, $botnick, "I warned you, dumbass.");
deactivateplayer($player[$sNick]);
}
if ($player[$nTimesSaid] > 4)
{
qwizban($player[$sNick], $player[$sMask], $botnick, "Stop spamming now.");
deactivateplayer($player[$sNick]);
}
}
sub r_command
{
local($cmdnick,$cmdhost,$rcommand,$ispublic) = @_;
ircmention($cmdnick,$cmdhost);
if ($cmdchan eq $botnick)
{ $cmdchan = $cmdnick; }
$rcommand =~ s/\n//;
$rcommand =~ s/\r//;
@commandfields = split (/ /, $rcommand);
$thecommand = lc($commandfields[0]);
&DEBUGMSG("thecommand: $thecommand");
&DEBUGMSG("$cmdnick isactive:" . isactive($cmdnick) ." present: " . ircispresent($cmdnick));
#if (!isactive($cmdnick) && ircispresent($cmdnick) && $thecommand ne 'mask' && $thecommand ne 'help')
if (!isactive($cmdnick) && $thecommand ne 'mask' && $thecommand ne 'help')
{
&DEBUGMSG("Activating PLAYER in activate!");
activateplayer($cmdnick, $cmdhost);
if (!isactive($cmdnick)) {
&DEBUGMSG("Tried to activiate $cmdnick ($cmdhost) but it still isnt, so cant do command $thecommand");
return;
}
}
my @player = getplayer($cmdnick);
my $isop = (($player[$sFlags] =~ /[ox]/)? 1 : 0);
#
# non-ops can't whisper commands
#
if ($isop == 0 && $ispublic == 0 && $thecommand !~ /^(add|gmail|auth|setpass)$/) {
&DEBUGMSG("Non-op $cmdnick tried to do $thecommand, but they can't (because they arnt an op).");
return;
}
#
# until the bot is stable, no commands from non-ops
#
my $now = time();
if ($chantime + (60) > $now && $isop == 0) {
&DEBUGMSG("Channel not yet stable... now = $now chantime = $chantime : commands not allowed");
return;
}
#
# blacklisted folks and bots have NO commands
#
if ($player[$sFlags] =~ /[*d]/)
{ return; }
#
# auth command -------------------------------------------------------------
#
if ($thecommand eq 'auth')
{
&DEBUGMSG("In the authbit!!!");
#if (!ircispresent($cmdnick))
# { return; }
if ($ispublic != 0 || $commandfields[1] eq '')
{
&NOTICE($cmdnick, "To enter your password for authorization, you need to /msg $botnick auth <yourpassword>");
&NOTICE($cmdnick, "Do NOT type your password in the channel where others may see it. See !help auth");
return;
}
my $pw = $commandfields[1];
$pw =~ tr/a-zA-Z0-9_\\\`\|\^\[\]\{\}\-//cd;
if ($pw ne $player[$sAuthPassword])
{
&NOTICE($cmdnick, "That is not the correct password. Authorization failed.");
&DEBUGMSG("!! nick $cmdnick failed AUTH!");
$authfails{lc($cmdnick)}++;
if ($authfails{lc($cmdnick)} >= 3)
{
qwizban($cmdnick, $cmdhost, $botnick, "Authorization failed.", 15);
return;
}
&NOTICE($cmdnick, "Do NOT type your password in the channel where others may see it. See !help auth");
return;
}
&NOTICE($cmdnick, "Authorization successful.");
&DEBUGMSG("!! $cmdnick AUTHed successfully!");
delete $authfails{lc($cmdnick)};
$authed{lc($cmdnick)} = $cmdhost;
authplayer($cmdnick);
return;
}
if ($thecommand eq 'setpass')
{
#if (!ircispresent($cmdnick))
# { return; }
if ($ispublic != 0 || $commandfields[1] eq '')
{
&NOTICE($cmdnick, "To set your password, you need to /msg $botnick setpass <yourpassword>");
&NOTICE($cmdnick, "Do NOT type your password in the channel where others may see it. See !help auth");
return;
}
if (!isauthed($cmdnick))
{
&NOTICE($cmdnick, "You are not authorized to set your password. You must first enter your old password.");
&NOTICE($cmdnick, "Do NOT type your password in the channel where others may see it. See !help auth");
return;
}
my $pw = $commandfields[1];
$pw =~ tr/a-zA-Z0-9_\\\`\|\^\[\]\{\}\-//cd;
if (length($pw) < 3 || lc($pw) eq lc($cmdnick))
{
&NOTICE($cmdnick, "That password is not secure enough. Use more letters or digits, or pick another word.");
&NOTICE($cmdnick, "Do NOT type your password in the channel where others may see it. See !help auth");
return;
}
&NOTICE($cmdnick, "Your password has been updated to <$pw>.");