# DreamBot - An Experimental IRC Bot written in Perl. # Copyright (C) 1999-2002 Osman "spectre" Keskin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA sub parser { my ($line) = $_[0]; if ($line =~ /^ERROR :Closing Link: (.*)/) { console("*** ERROR: $1\n"); close($sock); serverconnect(); return; } elsif ($line =~ /^PING [:]?(.*)/) { sockwrite($sock, "PONG :$1"); } elsif ($line =~ /^:([^: ]*)!([^: ]*) PRIVMSG ([^: ]+) :(.*)$/) { $unick = $1; $uhost = $2; $uchan = $3; $utext = $4; $uhost =~ /(.*)\@(.*)/; $uident = $1; $uaddy = $2; $query = false; if (lc($uchan) eq lc($nick)) { $uchan = $unick; $query = true; } $nnick = checkhost(lc($unick), $uhost); if ($utext =~ /^\x01PING (.*)\x01/) { console("[$unick] PING\n"); sockwrite($sock, "NOTICE $unick :\x01PING $1\x01"); foreach $logfile (values %logfiles) { chanlog($logfile, "[$unick] PING\n"); } } elsif ($utext =~ /^\x01VERSION\x01/) { console("[$unick] VERSION\n"); sockwrite($sock, "NOTICE $uchan :\x01VERSION $version\x01"); foreach $logfile (values %logfiles) { chanlog($logfile, "[$unick] VERSION\n"); } } elsif ($utext =~ /^\x01ACTION (.*)\x01/) { console("[$uchan] $unick $1\n"); if ($logging{lc($uchan)} eq true) { chanlog($logfiles{lc($uchan)}, "* $unick $1\n"); } } else { console("\[$uchan\] <$unick> $utext\n"); if ($logging{lc($uchan)} eq true) { chanlog($logfiles{lc($uchan)}, "<$unick> $utext\n"); } if ($query ne true) { if ($nnick ne false) { $tnick = $nnick; } else { $tnick = $unick; } $talkers{lc($tnick)} += length($utext); } if (defined($on_msg_handler)) { &$on_msg_handler($uchan, $nnick, $unick, $uident, $uaddy, $utext); } if ($learning{lc($uchan)} eq true) { @sentences = split (/\. /, $utext); foreach $sentence (@sentences) { if ($sentence =~ /^(?i:$nick)?[,:\-\; ]*(.*)(?: is| are|\'s|\'re) (.*)/i || $sentence =~ /^(?i:$nick)?[,:\-\; ]*(.*)(?: =| ->) (.*)/i) { $key = lc($1); $val = $2; if ($key !~ /^(what|that|it|these|those|he|she|who|where|how)$/i && $nick ne $unick && !defined($facts{$key})) { if (substr($val, 0, 7) ne "") { $val =~ s/your/my/gi; $val =~ s/you/I/gi; } $key =~ s/your/my/gi; $key =~ s/you/I/gi; console("*** learning: $key -> $val\n"); open(FILE, ">>$datadir/facts"); printf FILE "%s: %s -> %s\n", $unick, $key, $val; close(FILE); $facts{$key} = "$unick: $val"; } } } } } if ($utext =~ /^(?i:$nick)[,:\-\; ]*how (are|r) (you|ya|u)[ \?!]*/i) { privmsg($uchan, "I'm ok, $unick."); } elsif ($utext =~ /^(?i:$nick)?[,:\-\; ]*(?:fm|fresh|freshmeat)(?: news| headlines)?[ \?!]*$/i) { if ($public_fm{lc($uchan)} ne true && $query ne true) { privmsg($uchan, "$unick, use query for freshmeat"); } elsif (!fork()) { $data = httpget("www.freshmeat.net", 80, "/backend/fm.rdf"); if ($data ne "") { $ndata = backend($data); privmsg($uchan, "Freshmeat: $ndata"); } else { privmsg($uchan, "$unick, an error occured... (that's all i can say)"); } exit(0); } } elsif ($utext =~ /^(?i:$nick)?[,:\-\; ]*(?:\/\.|slash|slashdot)(?: news| headlines)?[ \?!]*$/i) { if ($public_sd{lc($uchan)} ne true && $query ne true) { privmsg($uchan, "$unick, use query for slashdot"); } elsif (!fork()) { $data = httpget("www.slashdot.org", 80, "/slashdot.rdf"); if ($data ne "") { $ndata = backend($data); privmsg($uchan, "Slashdot: $ndata"); } else { privmsg($uchan, "$unick, an error occured... (that's all i can say)"); } exit(0); } } elsif ($utext =~ /^(?i:$nick)?[,:\-\; ]*(?:translate|xlat|xlate|xl) (to|from) ([^ :;,\-]*)[ :;,\-]*(.*)$/i) { if (!fork()) { if ($1 eq "to") { $lang = "en_" . $2; } else { $lang = $2 . "_en"; } $string = urlencode($3); undef($data); $data = httppost("babel.altavista.com", 80, "/tr", "doit=done&tt=urltext&urltext=$string&url=http%3A%2F%2F&lp=$lang"); if ($data ne "" && ($data =~ /