PDA

Visualizza la versione completa : [perl] Problema con Bot IRC


edo1493
24-04-2010, 15:43
#!/usr/bin/perl

use IO::Socket;
use LWP::UserAgent;
use warnings;
use diagnostics;



my $unick = 'lp-italia_bot';
my $server = 'irc.freenode.net';
my $chan = '#lp-italia';
my $bot = 'lp-italia_bot';
my $nick;
my $address;
my $target;
my $msg;



$sock = new IO::Socket::INET (
PeerAddr => $server,
PeerPort => 6667,
Proto => 'tcp'
) or die "Impossibile connettersi a $server\n";



start();



while($rcv = <$sock>) {

open(IMG, ">>", <edo_bot.txt>);
print IMG "$rcv\n";
close(IMG);

print $rcv;



if ($rcv =~ /^PING(.*)$/i) {



print $sock "PONG $1\r\n";

}
else {

print "$rcv\n";
}

if ($rcv =~ /^:(.+?)!(.+?@.+?) PRIVMSG (.+?) :(.*)$/i) {
my $nick = $1; my $address = $2; my $target = $3; my $msg = $4;


}

if($rcv =~ /!quit libreplanet/) {

exit();
}


if( $msg eq 'Ciao' || 'Buongiorno') {

if ( $target eq $chan) {

chan("Ciao $nick");
}

if ($target eq 'lp-italia_bot') {

priv("Ciao $nick");

}

}








if($msg =~ /((W|w)indows|(B|b)ill (G|g)ates)/ ) {

if($target eq $chan) {
chan("GNU/Linux Get Your Freedom: http://gnu.org" );
}

if($target eq 'lp-italia_bot') {

priv("Prova gNewSense: http://gnewsense.org");
}
}




if($rcv =~ /!time/) {

@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
$theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
chan("$theTime");

}


}



sub start() {
print $sock "NICK $unick\r\n";
print $sock "USER $unick 8 * :$bot\r\n";
print $sock "JOIN $chan\r\n";


}



sub exit() {
print $sock "QUIT \r\n";
}

sub chan() {
my $mes = shift;
print $sock "PRIVMSG $chan :$mes\r\n";
}

sub priv() {
my $mes = shift;
print $sock "PRIVMSG $nick :$mes\r\n";
}



Da poco sto studiando il Perl e sto sviluppando con l'aiuto di altri bot e guide, questo Bot che spero di rilasciare sto GPLv3 tra qualche tempo..

Lanciando l'interprete ottengo questo errore... Qualche idea?


Use of uninitialized value in string eq at edo1.pl line 68, <GEN0> line 3 (#3)
Use of uninitialized value in string eq at edo1.pl line 70, <GEN0> line 3 (#3)
Use of uninitialized value in string eq at edo1.pl line 75, <GEN0> line 3 (#3)
Use of uninitialized value in pattern match (m//) at edo1.pl line 90, <GEN0>

Loading