Home
About Me
Projects
Computers
Guestbook
Links
|
#!/usr/bin/perl
# Copyright (C) 2001 Misha Nasledov <misha@nasledov.com>
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
use Net::AOLIM;
use Chatbot::Eliza;
# Users' Settings
my($username) = "Eliza0";
my($password) = "CENSORED";
my($owner) = "misha0";
my($logdir) = "/home/misha/public_html/elizalog";
my($elizdir) = "/home/misha/programming/misc";
my($stdout_debug) = 1;
my($revenge) = 1;
my($RAND_MAX) = 2147483647;
my $chatbots;
my $banlist;
my $previous;
$SIG{TERM} = \&sighandler;
$SIG{INT} = \&sighandler;
&connect_func();
sub connect_func {
$sess = Net::AOLIM->new("username" => $username,
"password" => $password,
"callback" => \&callback,
"allow_srv_settings" => 0 );
$sess->add_buddies("friends", $username);
unless (defined($sess->signon)) {
die "Error number was: $IM_ERR";
}
&load_denies();
while (1) {
if(!defined($sess->ui_dataget(undef))) {
print "disconnected..sleeping for 5 secs...\n";
sleep(5);
&connect_func();
}
}
}
sub load_denies
{
$sess->add_im_permit_all;
if(-f "$elizdir/denies") {
open(DENY, "$elizdir/denies");
while(<DENY>) {
chomp;
$tmp = $_;
$tmp =~ tr/[A-Z]/[a-z]/;
$banlist{$tmp} = 1;
}
close(DENY);
}
}
$pid = 0;
sub callback {
my $type = shift @_;
if($type eq 'NICK') {
$username = $_[0];
}
elsif($type eq 'EVILED') {
if(! -f "$logdir/$_[1].html") {
open(LOG, ">$logdir/$_[1].html");
print LOG "<html><head><title>Log of $_[1]</title></head><h1>Log of $_[0]</h1><br><br>\n";
}
else {
open(LOG, ">>$logdir/$_[1].html");
}
print LOG "$_[1] has eviled you. Current evil: $_[0]<br>\n";
if($stdout_debug) {
print "$_[1] has eviled you. Current evil: $_[0]\n";
}
close(LOG);
for($i = 0; $i < 5; $i++) {
$sess->toc_evil($_[1], 0);
}
$tmp = $_[1];
$tmp =~ tr/[A-Z]/[a-z]/;
if(!$banlist{$tmp}) {
# loser is not banned...
# let's add him to our banlist
open(DENIES, ">>denies");
print DENIES "$_[1]\n";
close(DENIES);
# taunt the user
$sess->toc_send_im($sess->norm_uname($_[1]), "Thanks for eviling [warning] me. My author, Misha0, did not create me for idiots to warn. Warning is a pointless feature of AIM because AOL entrusts people like you with power. While warning does not do much damage, it is pretty annoying and it is not good for the bot when it talks to many people. Anyway, due to certain people really pissing my master, Misha0, off, Misha0 has added this message to me and I will now add you to my permanent ban [block in your language, I suppose] list. If you have any problems, take them up with Misha0 but he will probably just laugh at you.");
# and finally let's add him to our hash of banned users
$banlist{$tmp} = 1;
}
}
elsif($type eq 'IM_IN') {
my($delay) = 0;
my($lenmsg) = 0;
$previous = $_[0];
$previous =~ tr/[A-Z]/[a-z]/;
if($banlist{$previous}) {
# hmm this person is on our banlist and trying to talk to Eliza
# doesn't this person deserve more of our love?? aww yeah...
$sess->toc_evil($_[0], 0);
return;
}
if(! -f "$logdir/$_[0].html") {
open(LOG, ">$logdir/$_[0].html");
print LOG "<html><head><title>Log of $_[0]</title></head><h1>Log of $_[0]</h1><br><br>\n";
}
else {
open(LOG, ">>$logdir/$_[0].html");
}
# Filter out the garbage...
$_[2] =~ s/<([^>]|\n)*>//g;
$_[2] =~ s/\b(greets|greetings|hi|hey|yo|sup)\b/hello/gi;
$_[2] =~ s/\bu\b/you/gi;
$_[2] =~ s/\br\b/are/gi;
$_[2] =~ s/\b(ur|yer)\b/your/gi;
$_[2] =~ s/\bwut\b/what/gi;
$_[2] =~ s/\b(yea|yeah|yup)\b/yes/gi;
$_[2] =~ s/\bdunno\b/don\'t know/gi;
$_[2] =~ s/\ba\/s\/l\b/\. what is your age and sex\?/gi;
$_[2] =~ s/\bcuz\b/because/gi;
$_[2] =~ s/\bplz\b/please/gi;
$_[2] =~ s/\by\b/why/gi;
$_[2] =~ s/\bppl\b/people/gi;
$_[2] =~ s/\bwit\b/with/gi;
$_[2] =~ s/\bb4\b/before/gi;
$_[2] =~ s/\blol\b/i am laughing out loud\./;
$_[2] =~ s/\bbye\b/i am leaving now/;
$_[2] =~ s/\bbrb\b/i will be right back/;
$_[2] =~ s/\biz\b/is/;
# We need more filters to translate
# the garbage that AOL users say
print LOG "<font color=\"#FF0000\">$_[0]:</font> $_[2]<br>\n";
if($stdout_debug) {
print "$_[0]: $_[2]\n";
}
if(($_[1] eq 't') || ($_[1] eq 'T')) {
return;
}
if($_[0] eq $owner) {
$cmd = 0;
if($_[2] eq "quit") {
exit(0);
}
if($_[2] =~ /intro (.*)/) {
# Let's go bug $1
$text = "Hello. What seems to be your problem?";
$sess->toc_send_im($sess->norm_uname($1), $text, 0);
$cmd = 1;
}
close(LOG) && return if $cmd;
}
if(!$chatbots{$_[0]}) {
# Create a new session if doesn't exist.
$chatbots{$_[0]} = new Chatbot::Eliza;
}
srand(time^($$+($$<<15)));
$reply = $chatbots{$_[0]}->transform($_[2]);
print LOG "<font color=\"#0000FF\">$username:</font>$reply<br>\n";
close(LOG);
if($stdout_debug) {
print "$username: $reply\n";
}
# Human typing emulation
# if($pid) {
# sleep(3);
# }
# if(($tpid = fork())) {
$pid = $tipd;
# sleep(1);
# }
# elsif(!$tpid) {
$lenmsg = length($reply);
if((1+(rand()*((8-1)/$RAND_MAX))) <= 3) {
$delay += 2+(rand()*((5-2)/$RAND_MAX));
}
$delay += ((1000+(rand()*((1500-1000)/$RAND_MAX)))/7000)*$lenmsg;
sleep($delay);
$sess->toc_send_im($sess->norm_uname($_[0]), $reply, 0);
# exit(0);
# }
}
elsif ($type eq 'ERROR') {
$err = $NET::AOLIM::ERROR_MSGS{$_[0]};
$err =~ s/\$ERR_ARG/$_[1]/g;
print "Error: $err";
}
}
sub sighandler {
# note: do something here
exit(0);
}
|