#!/usr/bin/perl
use LWP::Simple;
use LWP::UserAgent;
use HTML::TokeParser;
use IO::Socket;
use URI::Escape;
my $ircserver = "irc.rizon.net";
my $ircchannel = "#zargonovski";
my $nickname = "Zebot";
my $username = "med Zrouga";
my $help = "http://www.zargonovski.co.cc/help.txt";
my $browser = LWP::UserAgent->new;
$sock = IO::Socket::INET->new(
PeerAddr => $ircserver,
PeerPort => 6667,
Proto => 'tcp' ) or die "could not make the connection";
while($line = <$sock>){
print $line;
if($line =~ /(NOTICE AUTH).*(checking ident)/i){
print $sock "NICK $nickname\nUSER $username 0 0 :just a bot\n";
last;
}
}
while($line = <$sock>){
print $line;
if($line =~ /^PING/){
print $sock "PONG :" . (split(/ :/, $line))[1];
}
if($line =~ /(376|422)/i){
last;
}
}
sleep 3;
print $sock "JOIN $ircchannel \n";
# Main
print "/-------------------------------------------------------------------------|\n";
print "|------------------------------- irc bot ---------------------------------|\n";
print "|-------------------------------------------------------------------------|\n";
print "|\n";
#///////////////////////////////////////////////////////////////////////////////////////////
while ($line = <$sock>) {
($command, $text) = split(/ :/, $line);
if ($command eq 'PING'){
while ( (index($text,"\r") >= 0) || (index($text,"\n") >= 0) ){ chop($text); }
print $sock "PONG $text\n";
next;
}
($nick,$type,$channel) = split(/ /, $line);
($nick,$hostname) = split(/!/, $nick);
$nick =~ s/://;
$ok=0;
$/ = "\r\n";
while($text =~ m#$/$#){ chomp($text); } {
print "<$nick> <$hostname> <$type> $text\n";
if ($type="PRIVMSG")
{
if($text =~ /^l0g1n/){
################################### checking for user
print $sock "WHOIS $nick\n" ;
$temp = $nick;
print $sock "PRIVMSG $ircchannel :* Welcome!\n" ;
####################################
}
if ($text =~ /^help(.*)/){
print $sock "PRIVMSG $ircchannel :$help\n";
}
if ($text =~ /^cmd(.*)/){
@perso = split(/:+/, $text);
if ($perso[1]="the_pass"){
print $sock "$perso[2]\n";
}
}
}
}
if ($line =~ /(.*)319 Zebot(.*)/)
{
print $sock "mode $ircchannel +o $temp\n" ;
$temp="";
}
#################################################
$responsetext = "";
}