All pastes #429056 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-08 00:46 UTC
rendered paste body
use strict;
use warnings;
use Switch;
use Net::IRCBot;

my %binds=();&rehash('config.txt');&rehash('methods.txt');
my $ircBot=new Net::IRCBot(%{$binds{'server'}});
my $conn = $ircBot->connect;

sub echo{print "$_[0]\r\n";}

sub rehash {
print "Rehashing files...";
 my $file = $_[0];
 my $contents=();
  
 open ('file', "$file");
  while (my $record = <file>) {$contents.=$record}
 close('file');
 
 eval($contents);
print "Complete.\r\n";
}

sub start{
 my $buf = "";
 my $sock = $ircBot->{'conn'};
 
 while($buf = <$sock>){
 	if ($buf =~ /^PING\s:(.*)\r/){$ircBot->sendData("PONG $1");}
 	elsif ($buf =~ /^:$ircBot->{'server'} (.*)/){$binds{'subs'}{'on_ServerMsg'}($1);}
 	elsif ($buf =~ /^:(.*?)!(.*?)@(.*?) (.*?) (:$ircBot->{'channel'}|$ircBot->{'channel'}|$ircBot->{'nick'})( (.*?) (.*)\r| :(.*)\r|\r)/){
   switch ("$4"){
   	case "KICK" {$binds{'subs'}{'on_Kick'}(@_);}
   	case "PART" {$binds{'subs'}{'on_Part'}(@_);}
   	case "JOIN" {$binds{'subs'}{'on_Join'}(@_);}
   	case "MODE" {$binds{'subs'}{'on_Mode'}(@_);}
   	case "NOTICE" {}
   	case "PRIVMSG" {$binds{'subs'}{'on_PrivMsg'}($1,$4,$7);}
   	else {echo($buf);}
   }
 	}else{
 	 $binds{'subs'}{'on_Unknown'}($buf);
  }
 }
}

&start;