All pastes #840206 Raw Edit

Untitled

public text v1 · immutable
#840206 ·published 2007-12-31 16:29 UTC
rendered paste body
#!/usr/bin/perl
#use warnings;
#use strict;

###################### CONFIGURATION ###########################

package MyBot;
use base qw( Bot::BasicBot );

#sub chanjoin {
#       my ($self, $message) = @_;
#       if ($message->{who} =~ /timtux/) {
#               return "Välkommen min ärade mästare!"
#       }
#       return "Välkommen till $message->{channel}!";
#}

#sub chanpart {
#       my ($self, $message) = @_;
#       return "...ännu en förlorad själ."
#}

sub rand_q {
        use DBI;
        $dbh = DBI->connect( "dbi:SQLite:skogstokig.db" ) || die "Cannot connect: $DBI::errstr";
        my $count = $dbh->selectrow_array("SELECT COUNT(*) AS rows FROM insults");
        my $random_number = int(rand($count+1));
        my $insult = $dbh->selectrow_array("SELECT insult_text FROM insults WHERE id = '$random_number' LIMIT 1");
        $dbh->disconnect;
        return $insult;
}


sub said {
        my ($self, $message) = @_;

#       if ($message->{body} =~ /!nick \b/) {
#               $nick = $message->{body};
#               $nick =~ s/!nick //i;
#               #
#       }

        if ($message->{body} =~ /!help\b/) {
                return "!add <insult/quote>, !tell <nick>, or just talk to me :-)";
        }
        
        if ($message->{body} =~ /!tell \b/) {
                $nick = $message->{body};
                $nick =~ s/!tell //i;
                $self->say(     channel => $message->{channel},
                                body => "$nick: ".$self->rand_q."");
        }

        if ($message->{body} =~ /!uptime\b/) {
                $asd = `uptime`;
                $self->say(     channel => $message->{channel},
                                body => $asd);
        }       

        if ($message->{body} =~ /!add \b/) {
                use DBI;
                $insult = $message->{body};
                $insult =~ s/!add //i;
                $insult =~ s/'//;
                $dbh = DBI->connect( "dbi:SQLite:skogstokig.db" ) || die "Cannot connect: $DBI::errstr";
                $dbh->do( "INSERT INTO insults (insult_text) VALUES ( '".$insult."' ) ");
                $dbh->disconnect;
                $self->emote(   channel => $message->{channel},
                                body => "memorized \"$insult\" in hes little brain.");
        }

        if ($message->{address} =~ /\b$self->{nick}\b/) {
                return $self->rand_q;
        }
}

#sub emoted {
#       my ($self, $message) = @_;
#       return "tycker $message->{who} ska sluta rollspela...jävla idiot."
#}

my $bot1 = MyBot->new(
        server => "efnet.xs4all.nl",
        channels => [ '#telhack' ],
        nick => "skogstokig",
        no_run => 1,
);
        
my $bot2 = MyBot->new(
        server => "atluxity.no",
        channels => [ '#SABS' ],
        nick => "skogstokig",
        no_run => 1,
);

$bot1->run();
$bot2->run();

use POE;
$poe_kernel->run();