From: Masque <qi...@us...> - 2005-08-08 00:24:42
|
Update of /cvsroot/infobot/infobot/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23035/src Modified Files: CTCP.pl Channel.pl DBM.pl Help.pl Irc.pl IrcExtras.pl Misc.pl Norm.pl Params.pl Process.pl Question.pl Reply.pl Search.pl Setup.pl Statement.pl Update.pl User.pl Added Files: ANSI.pl Extras.pl HandleURLs.pl RDF.pl Log Message: Bringing CVS in line with that which is running as purl. Previous version tagged as 'oscon2005' for no particular reason other than date. --- NEW FILE: HandleURLs.pl --- #!/usr/bin/perl -w #------------------------------------------------------------------------ # handle URLs #------------------------------------------------------------------------ use strict; { my %urls; # Mea culpa, this code was pasted from seen.pm sub get_timediff($) { my $when = shift; my $howlong = time() - $when; $when = localtime $when; my @tstring = (($howlong % 60). " second".(($howlong%60>1)&&"s")); my $shorttstring = sprintf("%02d", ($howlong % 60)); $howlong = int($howlong / 60); $shorttstring = sprintf("%02d", ($howlong % 60)). ":$shorttstring"; if ($howlong % 60 > 0) { unshift @tstring, ($howlong % 60). " minute".(($howlong%60>1)&&"s"); } $howlong = int($howlong / 60); $shorttstring = ($howlong % 24). ":$shorttstring"; if ($howlong % 24 > 0) { unshift @tstring, ($howlong % 24). " hour".(($howlong%24>1)&&"s"); } $howlong = int($howlong / 24); if ($howlong % 365 > 0) { $shorttstring = ($howlong % 365). "d, $shorttstring"; unshift @tstring, ($howlong % 365). " day".(($howlong%365>1)&&"s"); } $howlong = int($howlong / 365); if ($howlong > 0) { unshift @tstring, "$howlong years"; $shorttstring = $howlong."y, $shorttstring"; } my $tstring; if(scalar(@tstring)==1) { $tstring=$tstring[0]; } else { $tstring="$tstring[0] and $tstring[1]" } return ($tstring, $shorttstring); } sub ::mentionURL { my ($channel,$url,$who)=@_; $urls{$channel}=$url; ::seenURL($channel,$url,$who); } sub ::lastURL { my $channel=shift; return $urls{$channel}; } sub ::seenURL { my ($channel,$url,$who)=@_; # are you COOL enough?! if($::param{"seenurls"}) { my ($firsttime,$firstnick); my ($lasttime,$lastnick); $lasttime=$firsttime=time; $lastnick=$firstnick=$who; my $oldurl = ::get(seenurls => "$channel|$url"); if($oldurl) { my @instances=split(/\;/,$oldurl); ($firsttime,$firstnick)=split(/,/,$instances[0]); ($lasttime,$lastnick)=split(/,/,$instances[-1]); if( ( ( $::param{"seenurls_obnoxious"} + 0.0 > 0 && rand() < $::param{"seenurls_obnoxious"} ) || $::param{"seenurls_obnoxious"} eq "true" ) && !$::addressed ) { # lambaste 'em for being so uncool as to paste a URL # that anyone had ever seen before ever if($firsttime == $lasttime) { ::say("$who: ". ($lastnick eq $who? "You" : $lastnick). " mentioned that URL here only ". (get_timediff($lasttime))[0]. " ago!"); } else { ::say("$who: You out-of-it clod. " . (($firstnick eq $who)?"You":$firstnick) . " first mentioned that URL here " . (get_timediff($firsttime))[0] . " ago, and " . (($lastnick eq $who) ? "you" : $lastnick). " last mentioned it " . (get_timediff($lasttime))[0] . " ago" . (($lastnick eq $firstnick) ? ", again!": ".")) } } } $lasttime=time; $lastnick=$who; ::set("seenurls","$channel|$url", "$firsttime,$firstnick;$lasttime,$lastnick"); } } # ::seenURL } 1; Index: CTCP.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/CTCP.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -w -u -r1.2 -r1.3 --- CTCP.pl 11 Jan 2002 16:44:37 -0000 1.2 +++ CTCP.pl 8 Aug 2005 00:24:25 -0000 1.3 @@ -1,39 +1,24 @@ # infobot (c) 1997 Lenzo -# CTCP handling methods - -# This subroutine has a misleading name. It should probably -# be called: handleCTCP - sub parsectcp { - -# Read in arguments my ($nick, $user, $host, $type, $dest) = @_; &status("CTCP $type $dest request from $nick"); - -# Handle VERSION requests if ($type =~ /^version/i) { ctcpreply($nick, "VERSION", $version); - -# Handle PING/ECHO request from other clients } elsif ($type =~ /^(echo|ping) ?(.*)/i) { - ctcpreply($nick, 'PING', $2); - -# Log the fact someone tries to DCC + rawout("NOTICE $nick :\001PING $2\001"); +# ctcpreply($nick, uc($1)." $2"); } elsif ($type =~ /^DCC /) { &status("DCC attempt from $who (not supported, ignored)"); - } } -# This subroutine is unlikely to be called... -# It's referenced in src/Irc.pl, but, it doesn't do -# a great deal... sub ctcpReplyParse { my ($nick, $user, $host, $type, $reply) = @_; &status("CTCP $type reply from $nick: $reply"); } + sub ctcpreply { my ($rnick, $type, $reply) = @_; rawout("NOTICE $rnick :\001$type $reply\001"); Index: Channel.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Channel.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -w -u -r1.4 -r1.5 Index: DBM.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/DBM.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -w -u -r1.9 -r1.10 --- DBM.pl 17 Dec 2001 16:39:35 -0000 1.9 +++ DBM.pl 8 Aug 2005 00:24:25 -0000 1.10 @@ -40,6 +40,8 @@ =cut +BEGIN { push @INC, 'src' } # baad, bad juju here + use vars qw(%DBMS $Debug $Init_done $Old_warnings); use Fcntl qw( @@ -94,6 +96,7 @@ postInc set showdb + showtop syncDBM whatdbs withDBMlock @@ -344,7 +347,7 @@ if ($module eq 'GDBM_File') { if ($flags == O_RDONLY) { return GDBM_File::GDBM_READER() } elsif ($flags == O_RDWR) { return GDBM_File::GDBM_WRITER() } - elsif ($flags == O_CREAT|O_RDWR){ return GDBM_File::GDBM_WRCREAT() } + elsif ($flags == (O_CREAT|O_RDWR)){ return GDBM_File::GDBM_WRCREAT() } else { badinvo 0, "unhandled flags $flags for $module" } } @@ -526,7 +529,7 @@ # If locking is active the database might not actually be open (if # called from outside this file, that shouldn't happen when called # internally). - if (!$rdb->[F_HASH]) { + if (!$rdb->[F_HASH] || !tied(%{ $rdb->[F_HASH] })) { print "syncDBM: $dbname skipping sync\n" if $Debug; return; } @@ -937,6 +940,83 @@ }; } +#------------------------------------------------------------------------ +# topofthecharts - dag...@da... +# +# a better top ten which only sorts a small number of things +# (but does it a lot) instead of sorting a huge number of things +# once and then throwing most of them away +sub topofthecharts(&$@) { # &$@#!!! + my $sortfun=shift; + my $numtoreturn=shift; + # and the rest of @_ is the values themselves + + if(scalar(@_)<=$numtoreturn) { + return sort { &$sortfun($a,$b) } (@_) + } + + my @b=sort { $sortfun->($a,$b) } @_[0..$numtoreturn-1]; + + for my $x (@_) { + if( $sortfun -> ( $b[$numtoreturn-1],$x ) == 1 ) { + unshift @b,$x; + @b=sort { $sortfun->($a,$b) } @b[0..$numtoreturn-1]; + } + } + return @b; +} + + +# showtop - aw...@aw... +# +# Shows the top or bottom $num_to_show entries in database $dbname, sorted by +# the rocketship operator. +# +# Currently used only by the topten.pm module. +# Also explodes spectacularly on large dbs. Oops. Disabled for now. +sub showtop { + my ($dbname, $num_to_show, $what_to_show) = @_; + my @result; + my @results; + + if (!$dbname) { + status "no db given"; + status "try showtop <db> <num_to_show>"; + return(); + } + + # default to "top 10" + $num_to_show = 10 if (!$num_to_show); + + my $rdb = $DBMS{$dbname}; + &status("$dbname topten requested, what to show: $what_to_show"); + if (!$rdb) { + status "the database $dbname is not open. try showtop <db> <num_to_show>"; + return(); + } + + with_lock $rdb, LOCK_SH, sub { + my $rhash = $rdb->[F_HASH]; + my %hashlet = %$rhash; + if ($what_to_show =~ /bottom/) + { + @result = topofthecharts { $rhash->{$_[0]} <=> $rhash->{$_[1]} } + $num_to_show, keys %$rhash; + @result = reverse @result; + } + else + { + @result = topofthecharts { $rhash->{$_[1]} <=> $rhash->{$_[0]} } + $num_to_show, keys %$rhash; + } + @results = map { $_." => ".$rhash->{$_} } @result; + + }; + + return @results; +} + + if (!$Init_done) { $^W = $Old_warnings; $Init_done = 1; Index: Help.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Help.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -w -u -r1.7 -r1.8 --- Help.pl 12 Aug 2004 22:54:46 -0000 1.7 +++ Help.pl 8 Aug 2005 00:24:25 -0000 1.8 @@ -26,8 +26,8 @@ $helptopics =~ s/\s+$//; &status("Loaded help file $param{helpfile}"); } else { - $help{"main"} = "Sorry, I couldn't find the help file."; - &status("No help file $param{helpfile}. Don't forget to create it from conf/dist/infobot.help"); + $help{"main"} = "couldn't find the help file"; + &status("No help file $param{helpfile}"); } } @@ -47,15 +47,14 @@ foreach (split(/\n/, $help{$topic})) { &msg($who,$_); } - } elsif ($topic ne 'topics') { - &msg($who, "Sorry, no help on '$topic'."); + } else { + &msg($who, "no help on $topic"); } - if ($topic eq 'main' or $topic eq 'topics' or !$help{$topic}) { - &msg($who, 'Help topics: '.$helptopics.". Use 'help <topic>'."); - } + &msg($who, 'topics: '.$helptopics.". use 'help <topic>'."); return ''; } + 1; Index: Irc.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Irc.pl,v retrieving revision 1.8 retrieving revision 1.9 diff -w -u -r1.8 -r1.9 --- Irc.pl 2 Aug 2004 20:37:22 -0000 1.8 +++ Irc.pl 8 Aug 2005 00:24:26 -0000 1.9 @@ -1,7 +1,16 @@ # infobot :: Kevin Lenzo & Patrick Cole (c) 1997 use Socket; -use POSIX qw(EINTR); + +# checks if Japanese messages should be converted to EUC upon +# receipt. This should only happen if a) Jcode is available, +# and b) the user has requested this feature. This *should* +# work; contact me at aw...@aw... if it doesn't. +my $no_japanese = 0; +eval qq{ + use Jcode qw(); +}; +$no_japanese++ if ($@); sub srvConnect { my ($server, $port) = @_; @@ -27,10 +36,6 @@ } connect(SOCK, $paddr) or die "connect failed: $!"; - my $old = select SOCK; - $| = 1; - select $old; - &status(" connected."); } @@ -107,40 +112,6 @@ } # end of xk functions. -sub pick_new_nick { - my ($base, $new); - - $nicktries++; - - $base = $param{wantNick} . 'x'; - do { - chop $base; - $new = "$base$nicktries"; - } while length $new > 9; - - return $new; -} - -sub get_new_nick { - my ($new_nick) = @_; - - $bot_nick = $new_nick; - $bot_nick_re = "(?i:\Q$bot_nick\E)"; - - my @n = ($bot_nick); - push @n, $param{wantNick} if $bot_nick ne $param{wantNick}; - $addressed_re = "(?i:" - . join('|', map { quotemeta } @n) - . ")"; - - nick($new_nick); # needs (), IrcExtras not compiled yet -} - -sub get_want_nick { - $nicktries = 0; - get_new_nick $param{wantNick}; -} - sub procmode { my ($nick, $user, $host, $e, $f) = @_; my @parts = split (/ /, $f); @@ -248,9 +219,10 @@ } } elsif ($type=~/NICK/) { if ($param{ansi_control}) { - &status(">>> $b_green$nick$ob becomes $b_green$chan$ob"); + &status(">>> ".c($nick,'bold green'). + " materializes into ".c($chan,'bold green')); } else { - &status(">>> $b$nick$ob becomes $b$chan$ob"); + &status(">>> $b$nick$ob materializes into $b$chan$ob"); } } } @@ -258,6 +230,14 @@ sub procevent { my ($nick, $user, $host, $type, $chan, $msg) = @_; + # anonymous submitter++. + # stuck in here by aw...@aw... -- if this causes a problem for + # anyone, please let me know. + if (($no_japanese == 0) && (::getparam('japanese')) && (Jcode::getcode($msg) eq 'jis')) + { + $msg = Jcode::convert($msg,'euc'); + } + # support global $nuh, $who $nuh = "$nick!$user\@$host"; @@ -266,6 +246,8 @@ ## It's a public message on the channel## $chan =~ tr/A-Z/a-z/; + $chan = &channel(lc $chan); + if ($msg =~ /\001(.*)\001/ && $msg !~ /ACTION/) { #### Client To Client Protocol #### parsectcp($nick, $user, $host, $1, $chan); @@ -277,6 +259,7 @@ &IrcActionHook($nick, $chan, $1); } } else { + &channel('purl'); ## Is Private ## if ($msg=~/\001(.*)\001/) { #### Client To Client Protocol #### @@ -288,13 +271,14 @@ } } elsif ($type=~/NOTICE/) { if ($chan =~ /^$ischan/) { - $chan =~ tr/A-Z/a-z/; + $chan =~ &channel(lc $chan); if ($msg !~ /ACTION (.*)/) { &status("-$nick/$chan- $msg"); } else { &status("* $nick/$chan $1"); } } else { + &channel('purl'); if ($msg=~/\001([A-Z]*)\s(.*)\001/) { ctcpReplyParse($nick, $user, $host, $1, $2); } else { @@ -308,9 +292,6 @@ my $msg=$_[0]; my ($ucount, $uc) = (0, 0); if ($msg=~/^001/) { - if ($param{operator}) { - rawout("OPER $param{operName} $param{operPass}"); - } # joinChan(split/\s+/, $param{'join_channels'}); # Line in infobot.config: # join_channels #chan,key #chan_with_no_key @@ -323,25 +304,37 @@ s/,/ /; joinChan ($_); } - } elsif ($msg=~/^NOTICE ($bot_nick_re) :(.*)/) { + $nicktries=0; + } elsif ($msg=~/^NOTICE ($ident) :(.*)/) { serverNotice($1,$2); - } elsif ($msg=~/^332 $bot_nick_re ($ischan) :(.*)/) { + } elsif ($msg=~/^332 $ident ($ischan) :(.*)/) { if ($param{ansi_control}) { &status(">>> topic for $b$1$ob: $2"); } else { &status(">>> topic for $1: $2"); } - } elsif ($msg=~/^333 $bot_nick_re $ischan (.*) (.*)$/) { + } elsif ($msg=~/^333 $ident $ischan (.*) (.*)$/) { if ($param{ansi_control}) { &status(">>> set by $b$1$ob at $b$2$ob"); } else { &status(">>> set by $1 at $2"); } } elsif ($msg=~/^433/) { - my $new = pick_new_nick; - &status("*** Nickname $bot_nick in use, trying $new"); - get_new_nick $new; - } elsif ($msg=~/[0-9]+ $bot_nick_re . ($ischan) :(.*)/) { + ++$nicktries; + if (length($param{wantNick}) > 9) { + $ident = chop $param{wantNick}; + $ident .= $nicktries; + } else { + $ident = $param{wantNick}.$nicktries; + } + if ($param{'opername'}) { + &rawout("OPER $param{opername} $param{operpass}"); + } + $param{nick} = $ident; + &status("*** Nickname $param{wantNick} in use, trying $ident"); + rawout("NICK $ident"); + + } elsif ($msg=~/[0-9]+ $ident . ($ischan) :(.*)/) { my ($chan, $users) = ($1, $2); &status("NAMES $chan: $users"); my $u; @@ -353,7 +346,7 @@ $channels{$chan}{v}{$u}++; } } - } elsif ($msg=~/[0-9]{3} $bot_nick_re(\s$ischan)*?\s:(.*)/) { + } elsif ($msg=~/[0-9]{3} $ident(\s$ischan)*?\s:(.*)/) { &status("$2"); } } @@ -382,7 +375,7 @@ } else { &status(">>> $b$knick$ob was kicked off $b$chan$ob by $b$kicker$ob ($b$why$ob)"); } - if ($knick eq $bot_nick) { + if ($knick eq $ident) { &status("SELF attempting to rejoin lost channel $chan"); &joinChan($chan); } @@ -390,7 +383,7 @@ sub prockill { my ($killer, $knick, $kserv, $killnick, $why) = @_; - if ($knick eq $bot_nick) { + if ($knick eq $ident) { &status("KILLED by $killnick ($why)"); } else { &status("KILL $knick by $killnick ($why)"); @@ -407,27 +400,42 @@ } sub irc { - while (1) { + local ($rin, $rout); + local ($buf, $line); + + $nicktries=0; + $connected=1; + while ($connected) { srvConnect($param{server}, $param{port}); if ($param{server_pass}) { # ksiero++ rawout("PASS $param{server_pass}"); } - get_want_nick; + rawout("NICK $param{wantNick}"); rawout("USER $param{ircuser} $param{ident} $param{server} :$param{realname}"); + if ($param{operator}) { + rawout("OPER $param{operName} $param{operPass}\n"); + } + $param{nick} = $param{wantNick}; + $ident = $param{wantNick}; + + $/ = "\015" if $^O eq "MacOS"; - my $buf = ''; + $rin = fhbits('SOCK'); while (1) { - my $nread = sysread SOCK, $buf, 1024, length $buf; - if (!$nread) { - next if !defined $nread && $! == EINTR; - status_error("read from server failed: ", - defined $nread ? 'EOF' : $!); + ($nfound,$timeleft) = select($rout=$rin, undef, undef, 0); + if ($rout & SOCK) { + if (sysread(SOCK,$buf,1) <= 0) { last; } - while ($buf =~ s/(.*?)[\x0d\x0a]+//) { - sparse($1) if length $1; + if ($buf=~/\n/) { + $line.=$buf; + sparse($line); + undef $line; + } else { + $line.=$buf; + } } } } @@ -443,13 +451,14 @@ sub sparse { $_ = $_[0]; + s/\r//; if (/^PING :(\S+)/) { # Pings are important rawout("PONG :$1"); &status("SELF replied to server PING") if $param{VERBOSITY} > 2; - } elsif (/^:\S+ (\d{3} .*)/) { + } elsif (/^:\S+ ([\d]{3} .*)/) { servmsg($1); - } elsif (/^:([\d\w\_\-\/]+\.[\.\d\w\_\-\/]+) NOTICE ($bot_nick_re) :(.*)/) { + } elsif (/^:([\d\w\_\-\/]+\.[\.\d\w\_\-\/]+) NOTICE ($ident) :(.*)/) { &status("\-\[$1\]- $3"); } elsif (/^NOTICE (.*) :(.*)/) { serverNotice($1, $2); Index: IrcExtras.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/IrcExtras.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -w -u -r1.7 -r1.8 --- IrcExtras.pl 5 Mar 2002 18:05:00 -0000 1.7 +++ IrcExtras.pl 8 Aug 2005 00:24:26 -0000 1.8 @@ -2,6 +2,16 @@ use Socket; +# checks if Japanese messages should be converted to EUC upon +# receipt. This should only happen if a) Jcode is available, +# and b) the user has requested this feature. This *should* +# work; contact me at aw...@aw... if it doesn't. +my $no_japanese=0; +eval qq{ + use Jcode qw(); +}; +$no_japanese++ if ($@); + $| = 1; $SIG{'INT'} = 'killed'; @@ -28,10 +38,6 @@ &quit($quitMsg); &closeDBMAll(); # MUHAHAHAHA. - - # if we have a .pid file, lose it - unlink($pid_file); - exit(1); } @@ -90,7 +96,7 @@ sub quit { my $quitmsg = $_[0]; rawout("QUIT :$quitmsg"); - &status("QUIT $bot_nick has quit IRC ($quitmsg)"); + &status("QUIT $param{nick} has quit IRC ($quitmsg)"); close(SOCK); } @@ -153,8 +159,19 @@ sub rawout { $buf = $_[0]; - $buf =~ s/\n//g; - print SOCK "$buf\x0d\x0a"; + + # anonymous submitter++. + # stuck in here by aw...@aw... -- if this causes a problem for + # anyone, please let me know. + if (($no_japanese == 0) && (::getparam('japanese')) && (Jcode::getcode($buf) eq 'euc')) + { + $buf = Jcode::convert($buf,'jis'); + } + + $buf =~ s/\n//gi; + select(SOCK); $| = 1; + print SOCK "$buf\n"; + select(STDOUT); } 1; Index: Misc.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Misc.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -w -u -r1.6 -r1.7 --- Misc.pl 24 Jan 2002 11:44:10 -0000 1.6 +++ Misc.pl 8 Aug 2005 00:24:26 -0000 1.7 @@ -46,12 +46,12 @@ sub status { $statcount++; - my($input) = join $,, @_; + my($input) = @_; if ($param{'VERBOSITY'} > 0) { if ($param{ansi_control}) { printf $_green."[%5d] ".$ob, $statcount; - $input =~ tr/\x00-\x1a\x1c-\x1f//d;# (Derek Moeller)++ + $input =~ s/[\cA-\c_]//ig; # (Derek Moeller)++ my $printable = $input; if ($printable =~ s/^(<\/\S+>) //) { @@ -82,9 +82,6 @@ } elsif ($printable =~ s/^(enter:|update:|forget:) //) { # something that should be SEEN print "$b_green$1 $printable$ob\n"; - } elsif ($printable =~ s/^(ERROR:) //) { - # from status_error() - print "$b_white$on_red$1 $printable$_reset\n"; } else { print "$printable\n"; } @@ -97,10 +94,6 @@ &log_line("[$statcount] ".$input); } -sub status_error { - status "ERROR: ", @_; -} - sub performSay { my($in) = @_; if (!defined($prevIn)) { $prevIn = ""; }; @@ -135,7 +128,7 @@ if ($param{'logfile'} ne '') { $line =~ s/\n*$/\n/; - open(TRACK, ">>$param{basedir}/$param{logfile}"); + open(TRACK, ">>$param{logfile}"); $loglines++; $total_loglines++; @@ -167,3 +160,7 @@ } 1; + +__DATA__ + +/dimer\[0\/: trailing \ in regexp at /usr/users/infobot/infobot-current/src/Misc.pl line 164, <FH> chunk 98. Index: Norm.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Norm.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -w -u -r1.3 -r1.4 --- Norm.pl 2 Aug 2004 20:22:53 -0000 1.3 +++ Norm.pl 8 Aug 2005 00:24:26 -0000 1.4 @@ -85,10 +85,10 @@ $in =~ s/(^|\W)you\'?re(\W|$)/$1you are$2/ig; if ($addressed > 0) { - $in =~ s/(^|\W)are you(\W|$)/$1is $param{wantNick}$2/ig; - $in =~ s/(^|\W)you are(\W|$)/$1$param{wantNick} is$2/ig; - $in =~ s/(^|\W)you(\W|$)/$1$param{wantNick}$2/ig; - $in =~ s/(^|\W)your(\W|$)/$1$param{wantNick}\'s$2/ig; + $in =~ s/(^|\W)are you(\W|$)/$1is $param{'nick'}$2/ig; + $in =~ s/(^|\W)you are(\W|$)/$1$param{'nick'} is$2/ig; + $in =~ s/(^|\W)you(\W|$)/$1$param{'nick'}$2/ig; + $in =~ s/(^|\W)your(\W|$)/$1$param{'nick'}\'s$2/ig; } $in; Index: Params.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Params.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -w -u -r1.4 -r1.5 Index: Process.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Process.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -w -u -r1.9 -r1.10 --- Process.pl 2 Aug 2004 20:37:22 -0000 1.9 +++ Process.pl 8 Aug 2005 00:24:26 -0000 1.10 @@ -4,23 +4,24 @@ $SIG{'ALRM'} = 'TimerAlarm'; -use Fcntl (); - sub process { ($who, $msgType, $message) = @_; my ($result, $caughtBy); $origMessage = $message; # intentionally global - return 'SELF' if (lc($who) eq lc($bot_nick)); + return 'SELF' if (lc($who) eq lc($param{'nick'})); $message =~ s/[\cA-\c_]//ig; # strip control characters $msgFilter = "NOFILTER"; # 26Jun19100 - Masque # $msgFilter = $1 if $message =~ s/\s+(?:=~)\s?\/\(\?:(.*?)\)\/i?\s*//; -# STILL doesn't match '=~ /(?:(toot!))/'! Grah. Could make this simpler, but this is fun. 29Jun2K - Masque. + # STILL doesn't match '=~ /(?:(toot!))/'! Grah. Could make this + # simpler, but this is fun. 29Jun2K - Masque. # FIXME - $msgFilter = ($1 || $2) if $message =~ s!\s+(?:=~)?\s?/(?:\((?:\?:)?([^)]*)\)|([^()]*))/i?\s*$!!; - + $msgFilter = ($1 || $2) + if $message =~ s,\s+(?:=~)? + \s?/ + (?:\((?:\?:)?([^)]*)\)|([^()]*))/i?\s*$,,x; $addressed = 0; $karma = 0; # 12Apr2k - Masque @@ -38,6 +39,13 @@ return 'INTERBOT'; } + if ($msgType =~ /public/ + and $message =~ /((?:http|ftp|mailto|telnet|file|https):\S+)/) { + $url=$1; + status("Stashing URL $url"); + mentionURL(channel(),$url,$who); + } + return 'INTERBOT' if $message =~ /^...but/; return 'INTERBOT' if $message =~ /^.* already had it that way/; return 'INTERBOT' if $message =~ /^told /; # reply from friendly infobot @@ -48,24 +56,22 @@ # this assumes that the ignore list will be fairly small, as we # loop through each key rather than doing a straight lookup # -- this should be moved and made more efficient -- kl - if (withDBMlock 'ignore', Fcntl::LOCK_SH, sub { if (&get(ignore => $uh) or &get(ignore => $who)) { - return 1; + &status("IGNORE <$who> $message"); + return 'IGNORE'; } + foreach (&getDBMKeys('ignore')) { my $ignoreRE = $_; my @parts = split /\*/, "a${ignoreRE}a"; my $recast = join '\S*', map quotemeta($_), @parts; $recast =~ s/^a(.*)a$/$1/; if ($nuh =~ /^$recast$/) { - return 1; - } - } - return 0; - }) { &status("IGNORE <$who> $message"); return 'IGNORE'; } + } + # -- -- if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) { @@ -99,7 +105,8 @@ &status(":INFOBOT:REPLY $who: $message"); my ($X, $V, $Y) = $item =~ /^(.*?) =(.*?)=> (.*)/; - if ((getparam('acceptUrl') !~ /REQUIRE/) or ($Y =~ /(http|ftp|mailto|telnet|file):/)) { + if ((getparam('acceptUrl') !~ /REQUIRE/) or + ($Y =~ /(http|ftp|mailto|telnet|file):/)) { &set($V, $X, $Y); &msg($target, "$who knew: $X $V $Y"); } @@ -110,7 +117,6 @@ } $VerifWho = &verifyUser($nuh); - if ($VerifWho) { if (IsFlag("i") eq "i") { &status("Ignoring $who: $VerifWho"); @@ -152,10 +158,14 @@ # see User.pl for the "special" user commands return 'NOREPLY' if &userProcessing() eq 'NOREPLY'; + # make this more Comic Chat friendly + if ( ::getparam('comicchat') ) { + $message =~ s/\(\#G[^\)]*\)//; + } + if ($msgType !~ /public/) { $addressed = 1; } - if (($message =~ s/^(no,?\s+$addressed_re,?\s*)//i) - or ($message =~ s/^($addressed_re\W?\s+no,\s*)//i) + if (($message =~ s/^(no,?\s+$param{'nick'},?\s*)//i) or ($addressed and $message =~ s/^(no,?\s+)//i)) { # clear initial negative # an initial negative may signify a correction @@ -165,7 +175,7 @@ $correction_plausible = 0; } - if ($message =~ /^\s*$addressed_re\s*\?*$/i) { + if ($message =~ /^\s*$param{'nick'}\s*\?*$/i) { &status("feedback addressing from $who"); $addressed = 1; $blocked = 0; @@ -184,8 +194,8 @@ return "FEEDBACK"; } - if (($message =~ /^\s*$addressed_re\s*([\,\:\> ]+) */i) - or ($message =~ /^\s*$addressed_re\s*-+ *\??/i)) { + if (($message =~ /^\s*$param{'nick'}\s*([\,\:\> ]+) */i) + or ($message =~ /^\s*$param{'nick'}\s*-+ *\??/i)) { # i have been addressed! my($it) = $&; @@ -196,7 +206,7 @@ } } - if ($message =~ /, ?$addressed_re(\W+)?$/i) { # i have been addressed! + if ($message =~ /, ?$param{nick}(\W+)?$/i) { # i have been addressed! my($it) = $&; if ($` !~ /^\s*i?s\s*$/i) { $xxx = quotemeta($it); @@ -211,8 +221,10 @@ $lastaddressedby = $who; $lastaddressedtime = time(); + my $channel; if ($message =~ /^showmode/i ) { if ($msgType =~ /public/) { + $channel = &channel(); if ((getparam('addressing') ne 'REQUIRE') or $addressed) { &performSay ($who.", addressing is currently ".getparam('addressing')); } @@ -222,7 +234,6 @@ return "SHOWMODE"; } - my $channel = &channel(); $continuity = 0; } else { # apparently not addressed @@ -252,20 +263,20 @@ # $confusedRE = join '|', map quotemeta($_), @confused unless defined $confusedRE; # return 'CONFUSED' if $message =~ /$confusedRE/; - return if ($who eq $bot_nick); + return if ($who eq $param{'nick'}); $message =~ s/^\s+//; # strip any dodgey spaces off # Half finished thought here - "^Pudge - it's there" looks like math but is # often nick completion or similar. - # if (($message =~ s/^(\S+)\s*:\s+//) or ($message =~ s/^(\S+)\s+--?\s+[.\d]//)) { - if (($message =~ s/^(\S+)\s*:\s+//) or ($message =~ s/^(\S+)\s+--+\s+//)) { + # if (($message =~ s/^\S+\s*:\s+//) or ($message =~ s/^\S+\s+--?\s+[.\d]//)) { + if (($message =~ s/^\S+\s*:\s+//) or ($message =~ s/^\S+\s+--+\s+//)) { # stripped the addressee ("^Pudge: it's there") $reallyTalkingTo = $1; } else { $reallyTalkingTo = ''; if ($addressed) { - $reallyTalkingTo = $bot_nick; + $reallyTalkingTo = $param{'nick'}; } } @@ -310,7 +321,7 @@ $caughtBy = "tell"; } - if ($target eq $bot_nick) { + if ($target eq $param{'nick'}) { $result = "Isn\'t that a bit silly, ".$who."?"; $target = $who; $caughtBy = "tell"; @@ -332,9 +343,7 @@ if ($continuity or $addressed or (getparam('addressing') ne "REQUIRE")) { - if (defined ($result = &myRoutines())) { - $caughtBy = "myRoutines"; - } elsif (defined($result = &Extras())) { + if (defined($result = &Extras())) { $caughtBy = "Extras"; # BEEP BEEP - TODO ALERT: Change the karma lookup to do a doQuestion # before returning a karma query to catch factoids that should return @@ -435,3 +444,4 @@ } 1; + Index: Question.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Question.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -w -u -r1.3 -r1.4 --- Question.pl 2 Aug 2004 20:22:53 -0000 1.3 +++ Question.pl 8 Aug 2005 00:24:26 -0000 1.4 @@ -58,10 +58,6 @@ return 'NOREPLY'; } - if (not defined $answer) { - $answer = &math($qmsg); # clean up the argument syntax for this later - } - if ($questionWord ne "" or $finalQMark) { # if it has not been explicitly marked as a question if ($addressed && (not defined $answer)) { Index: Reply.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Reply.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -w -u -r1.10 -r1.11 --- Reply.pl 2 Aug 2004 20:37:22 -0000 1.10 +++ Reply.pl 8 Aug 2005 00:24:26 -0000 1.11 @@ -18,19 +18,7 @@ my $literal = ($locMsg =~ s/^literal //); - if (getparam('rss') and $message =~ m/^perlfaq\'\s+(.*?)\?*$/) { - # specially defined type. get and process an RSS (RDF Site Summary) - eval "use URI::Escape"; - not ($@) and do { - my $q = uri_escape($1, '\W'); - my $result = &get_headlines("http://www.perlfaq.com/cgi-bin/rss/kw?q=$q"); - if ($result =~ s/^error: //) { - return "$who: couldn't get the perlfaq: $result"; - } else { - return "$who: $result"; - } - } - } elsif ($result = get("is", $locMsg)) { + if ($result = get("is", $locMsg)) { # &status("exact: $message =is=> $result"); $theVerb = "is"; $X = $message; @@ -297,10 +285,10 @@ if ($theMsg =~ s/^$safeWho is/you are/i) { # fix the person } else { - $theMsg =~ s/^$addressed_re is /i am /ig; - $theMsg =~ s/ $addressed_re is / i am /ig; - $theMsg =~ s/^$addressed_re was /i was /ig; - $theMsg =~ s/ $addressed_re was / i was /ig; + $theMsg =~ s/^$param{'nick'} is /i am /ig; + $theMsg =~ s/ $param{'nick'} is / i am /ig; + $theMsg =~ s/^$param{'nick'} was /i was /ig; + $theMsg =~ s/ $param{'nick'} was / i was /ig; if ($addressed) { $theMsg =~ s/^you are (\.*)/i am $1/ig; @@ -374,3 +362,4 @@ } 1; + Index: Search.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Search.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -w -u -r1.2 -r1.3 Index: Setup.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Setup.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -w -u -r1.12 -r1.13 --- Setup.pl 12 Aug 2004 22:54:46 -0000 1.12 +++ Setup.pl 8 Aug 2005 00:24:26 -0000 1.13 @@ -14,7 +14,7 @@ &status($params); } - die "dbname is null\n(did you remember to create conf/infobot.config from conf/dist/infobot.config?)\n " if (!$param{'dbname'}); + die "dbname is null" if (!$param{'dbname'}); %dbs = ("is" => "$param{basedir}/$param{dbname}-is", "are" => "$param{basedir}/$param{dbname}-are"); @@ -31,10 +31,6 @@ $qCount = &get("is", "the qCount"); $qEpochTime = &get("is", "the qEpochTime"); - # things to say when people thank me - @welcomes = ('no problem', 'my pleasure', 'sure thing', - 'no worries', 'de nada', 'de rien', 'bitte', 'pas de quoi'); - # when i'm cofused and I have to reply @confused = ("huh?", "what?", @@ -49,8 +45,6 @@ 'no idea', 'bugger all, i dunno'); - - # check the ignore parameter for a filename containing the # ignore list @@ -97,6 +91,20 @@ &openDBMx('seen'); } + if ($param{'seenurls'}) { + &openDBMx('seenurls'); + } + + # if ($param{'topten'}) { + # &openDBMx('topten'); + # } + + foreach $chan (split(/\s+/, $::param{'allowed_channels'})) { + # Initialize the topten database. -- rs 10.jun'04 + my $workname = substr(lc $chan, 1); + &openDBMx("topten/$workname"); + } + # set up the users and ops &status("Parsing User File"); &parseUserfile(); @@ -105,18 +113,6 @@ # set up the channel file &parseChannelfile(); - # ways to say hello - @hello = ('hello', - 'hi', - 'hey', - 'niihau', - 'bonjour', - 'hola', - 'salut', - 'que tal', - 'privet', - "what's up"); - $param{'maxKeySize'} ||= 30; # maximum LHS length $param{'maxDataSize'} ||= 200; # maximum total length @@ -132,8 +128,13 @@ # do this ONCE per startup to amortize. Still too much mem. #&getAllKeys; + &status("Getting factoid counts"); + &status(" Counting 'is'..."); $isCount = &getDBMKeys('is'); + &status(" $isCount 'is' factoids"); + &status(" Counting 'are'..."); $areCount = &getDBMKeys('are'); + &status(" $areCount 'are' factoids"); $factoidCount = $isCount + $areCount; &status("setup: $factoidCount factoids; $isCount IS; $areCount ARE"); @@ -144,15 +145,27 @@ my $initdebug = 1; $param{'DEBUG'} = $initdebug; - if (!@paramfiles) { + my $defaultfile; + unless ($paramfile) { # if there is no list of param files, just go for the default # (usually ./files/infobot.config) - @paramfiles = ("$param{confdir}/infobot.config"); + $paramfile = "$param{confdir}/infobot.config"; + $defaultfile++; + } + + if (! -e $paramfile) { + if ($defaultfile) { + die "Hey, this looks you're running this for the first time!\nPerhaps you should rename the -dist files in the conf/ subdirectory and\nedit them to your liking.\n" + } + else { + die "Can't find specified configuration file $paramfile.\n" + } } # now read in the parameter files - &loadParamFiles(@paramfiles); + &loadParamFiles($paramfile); } + 1; Index: Statement.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Statement.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -w -u -r1.7 -r1.8 --- Statement.pl 2 Aug 2004 20:37:22 -0000 1.7 +++ Statement.pl 8 Aug 2005 00:24:26 -0000 1.8 @@ -12,7 +12,7 @@ ## sub doStatement { - return '' if (lc($who) eq lc($bot_nick)); + return '' if (lc($who) eq lc($param{'nick'})); my($msgType, $in) = @_; @@ -28,7 +28,9 @@ $in =~ s/(^|\s)you are /$1$param{'ident'} is /i; } - $in =~ s/^no,\s+//i; # don't want to complain if it's new but negative + + # don't want to complain if it's new but negative + $correction_plausible = 1 if($in =~ s/^no,\s+//i); if (getparam('plusplus')) { Index: Update.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/Update.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -w -u -r1.4 -r1.5 --- Update.pl 2 Aug 2004 20:22:53 -0000 1.4 +++ Update.pl 8 Aug 2005 00:24:26 -0000 1.5 @@ -10,8 +10,6 @@ $lhs =~ s/^some(one|1|body) said //i; $lhs =~ s/ +/ /g; - if (($lhs =~ m/-\s*$/)&&(!$addressed)) { return; } - # this really needs cleaning up if ($verb eq "is") { $also = ($rhs =~ s/^also //i); @@ -131,9 +129,9 @@ if ($addressed) { &status("FAILED update: \'$lhs =$verb=> $rhs\'"); if ($msgType =~ /public/) { - &performSay("...but $lhs are $exists..."); + &performSay("...but $lhs is $exists..."); } else { - &msg($who, "...but $lhs are $exists.."); + &msg($who, "...but $lhs is $exists.."); } } else { &status("FAILED update: $lhs $verb $rhs (not addressed, no reply)"); @@ -141,6 +139,11 @@ # ignore it. return 'NOREPLY'; } + if ($msgType =~ /public/) { + &performSay("...but $lhs are $exists..."); + } else { + &msg($who, "...but $lhs are $exists..."); + } } else { if ($msgType =~ /public/) { &performSay("okay, $who.") unless $rhs eq $exists; Index: User.pl =================================================================== RCS file: /cvsroot/infobot/infobot/src/User.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -w -u -r1.12 -r1.13 --- User.pl 12 Aug 2004 22:54:46 -0000 1.12 +++ User.pl 8 Aug 2005 00:24:26 -0000 1.13 @@ -8,7 +8,9 @@ %user = (); @userList = (); - if(open(FH, $file)) { + open(FH, $file) + or die "Could not open $file ($!). Perhaps you forgot to rename the example file in conf/infobot.users-dist?\n"; + while (<FH>) { if (!/^#/ && defined $_) { if (/^UserEntry\s+(.+?)\s/) { @@ -16,7 +18,7 @@ $workname = $1; if (/\s*\{\s*/) { while (<FH>) { - if (/^\s*(\w+)\s+(.+);\s*$/) { + if (/^\s*(\w+)\s+(.+);$/) { $opt = $1; $val = $2; $val =~ s/\"//g; if ($opt =~ /^mask$/i) { @@ -52,10 +54,6 @@ } } } - else { - &status("No user file $param{userList}. Don't forget to create it from conf/dist/infobot.users"); - } -} sub IsFlag { my $flags = $_[0]; @@ -74,6 +72,7 @@ } sub verifyUser { + my $lnuh = $_[0]; my ($u, $m); my $VerifWho; @@ -92,15 +91,12 @@ my $now = time(); - my @seen = ($now); - if ($msgType =~ /public/) { - push @seen, channel(), $message; - } - else { - push @seen, '', "<private message>"; + my $m = $message; + if ($msgType !~ /public/) { + $m = "<private message>"; } - push @seen, $param{'ircNetName'} || ''; - &set('seen', lc $who, join $;, @seen); + &set('seen', lc $who, $now.$;.channel().$;.$m); + &postInc('topten/'.substr(lc channel(), 1), lc $who); # add one to the counter of what this user has said if ($VerifWho) { $uFlags = $user{$VerifWho."flags"}; @@ -288,7 +284,7 @@ if ($VerifWho) { if ($msgType =~ /private/) { - my $unverified_message = "you must identify yourself; /msg $bot_nick <pass> <command>"; + my $unverified_message = "you must identify yourself; /msg $param{nick} <pass> <command>"; if (IsFlag("e")) { # eval if ($message =~ s/^(\S+) eval//) { @@ -433,3 +429,4 @@ } 1; + |