Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Perl IRC Bot, Version 4 skeleton.
- use lib '/Users/Caaz/lib';
- use POE::Component::IRC;
- use POE;
- $Bot{"Path"} = "/Users/Caaz/Desktop/Perl/"; # The only variable you'll need to edit. This file must be in the folder spesified, and must be named Bot.pl
- open DATA, "<".$Bot{"Path"}."Data.txt" or warn "This must is your first time running this bot, you should use the DefSet command, and set Default variables for running the bot. Then use Addserv for adding servers.\n";
- @Dat = <DATA>;
- close DATA;
- if($Dat[0] =~ /^$/) {
- print "Adding default settings for first start up.\n";
- open DATA, ">".$Bot{"Path"}."Data.txt";
- print DATA "MyBot:Perl bot, Version 4:Perl:Password:Caaz\nirc.purplesurge.com";
- close DATA;
- open DATA, "<".$Bot{"Path"}."Data.txt";
- @Dat = <DATA>;
- close DATA;
- }
- if($ARGV[0] =~ /^$/) {
- print "\nSet up mode.\n\n";
- print "\tCommands\nEnd - Exits.\nDefSet - Sytax : NICK:NAME:IDENT:NICKSERVPASS:OWNER\nAddserv - Syntax : SERVER:PORT*:NICK*:NAME*:IDENT*:NICKSERVPASSWORD*:SERVERPASSWORD*\nRun - Runs the bot.\n\n";
- while (<STDIN>) {
- if (/^END$|^Exit$|^Close$/i) {
- print "Closing...\n";
- exit 0;
- }
- elsif (/^DefSet(.*)/i) {
- ($s = $1) =~ s/^ //gs;
- @erv = split /:/, $s;
- if($erv[4] =~ /^$/) {
- print "Error, not all areas are properly set up. \nExample : "."MyBot:Perl bot, Version ".$Bot{"Version"}.":Perl:Password:Caaz\n";
- }
- else {
- print "Saving.\n";
- shift(@Dat);
- open DATA, ">".$Bot{"Path"}."Data.txt";
- print DATA $s."\n".(join "", @Dat);
- close DATA;
- open DATA, "<".$Bot{"Path"}."Data.txt";
- @Dat = <DATA>;
- close DATA;
- }
- }
- elsif (/^Serv(.*)/i) {
- ($s = $1) =~ s/^ //gs;
- @erv = split /:/, $s;
- if($erv[0] =~ /^$/) {
- print "Error, no servername.\nSyntax SERVER:PORT*:NICK*:NAME*:IDENT*:NICKSERVPASSWORD*:SERVERPASSWORD*\n* - Optional. If you don't want to include the value, leave it blank.\nExample : irc.purplesurge.com::Rin:::MyPassword::\n";
- }
- else {
- print "Saving.\n";
- open DATA, ">".$Bot{"Path"}."Data.txt";
- print DATA $Dat[0].$s;
- close DATA;
- open DATA, "<".$Bot{"Path"}."Data.txt";
- @Dat = <DATA>;
- close DATA;
- }
- }
- elsif (/^Run$/i) {
- print "Running...\n";
- exec("perl ".$Bot{"Path"}."Bot.pl run ".$Dat[1]);
- exit 0;
- }
- else {
- print "Unknown command\n";
- }
- }
- }
- if($ARGV[0] =~ /^Run$/i) {
- {
- print join "-", @ARGV."\n";
- open DATA, "<".$Bot{"Path"}."Data.txt";
- @Dat = <DATA>;
- close DATA;
- $Bot{"Server"} = (split /:/, $ARGV[1])[0];
- print "No Server, terminating.\n" if((split /:/, $ARGV[1])[0] =~ /^$/i);
- exit if((split /:/, $ARGV[1])[0] =~ /^$/i);
- $Bot{"Port"} = "6667";
- $Bot{"Port"} = (split /:/, $ARGV[1])[1] if((split /:/, $ARGV[1])[1] !~ /^$/i);
- print "No Port specified, using default : ".$Bot{"Port"}."\n" if((split /:/, $ARGV[1])[1] =~ /^$/i);
- $Bot{"Nick"} = (split /:/, $Dat[0])[0];
- $Bot{"Nick"} = (split /:/, $ARGV[1])[2] if((split /:/, $ARGV[1])[2] !~ /^$/i);
- print "No Nick specified, using default : ".$Bot{"Nick"}."\n" if((split /:/, $ARGV[1])[2] =~ /^$/i);
- $Bot{"Name"} = (split /:/, $Dat[0])[1];
- $Bot{"Name"} = (split /:/, $ARGV[1])[3] if((split /:/, $ARGV[1])[3] !~ /^$/i);
- print "No Name specified, using default : ".$Bot{"Name"}."\n" if((split /:/, $ARGV[1])[3] =~ /^$/i);
- $Bot{"Ident"} = (split /:/, $Dat[0])[2];
- $Bot{"Ident"} = (split /:/, $ARGV[1])[4] if((split /:/, $ARGV[1])[4] !~ /^$/i);
- print "No Ident specified, using default : ".$Bot{"Ident"}."\n" if((split /:/, $ARGV[1])[4] =~ /^$/i);
- $Bot{"NPassword"} = (split /:/, $Dat[0])[3];
- $Bot{"NPassword"} = (split /:/, $ARGV[1])[5] if((split /:/, $ARGV[1])[5] !~ /^$/i);
- print "No Nickserv password specified, using default : ".$Bot{"NPassword"}."\n" if((split /:/, $ARGV[1])[5] =~ /^$/i);
- $Bot{"SPassword"} = (split /:/, $ARGV[1])[6];
- $Bot{"Owner"} = (split /:/, $Dat[0])[7];
- $Bot{"Owner"} = (split /:/, $ARGV[1])[5] if((split /:/, $ARGV[1])[7] !~ /^$/i);
- print "No Owner specified, using default : ".$Bot{"Owner"}."\n" if((split /:/, $ARGV[1])[5] =~ /^$/i);
- }
- my ($irc) = POE::Component::IRC->spawn();
- POE::Session->create( inline_states => {
- _start => sub {
- $irc->yield(register => "all");
- $irc->yield( connect => {
- Nick => $Bot{"Nick"},
- Username => $Bot{"Ident"},
- Ircname => $Bot{"Name"},
- Server => $Bot{"Server"},
- Port => $Bot{"Port"},
- Password => $Bot{"SPassword"},
- });
- },
- irc_connected => sub {
- my ($kernel, $IRC0) = @_[KERNEL, ARG0];
- print &TS()."Connected to ".$IRC0.".\n";
- my $alarm_id = $irc->delay( [ join => "#Powerplant" ], 3 );
- },
- irc_disconnected => sub {
- my ($kernel, $IRC0) = @_[KERNEL, ARG0];
- print &TS()."Disconnected from ".$IRC0.".\n";
- },
- irc_error => sub {
- my ($kernel, $IRC0) = @_[KERNEL, ARG0];
- print &TS()."Error : ".$IRC0.".\n";
- },
- irc_join => sub {
- my ($kernel, $IRC0, $IRC1) = @_[KERNEL, ARG0, ARG1];
- print &TS()."Join \) * ".(split /!/, $IRC0)[0]." \(".(split /!/, $IRC0)[1]."\) joins ".$IRC1.".\n";
- },#Sent whenever someone gets booted off a channel that you're on. ARG0 is the kicker's nick!hostmask. ARG1 is the channel name. ARG2 is the nick of the unfortunate kickee. ARG3 is the explanation string for the kick.
- irc_invite => sub {
- my ($kernel, $IRC0, $IRC1) = @_[KERNEL, ARG0, ARG1];
- print &TS()."Invite \) * ".(split /!/, $IRC0)[0]." \(".(split /!/, $IRC0)[1]."\) invites you to join ".$IRC1.".\n";
- },
- irc_kick => sub {
- my ($kernel, $IRC0, $IRC1,$IRC2,$IRC3) = @_[KERNEL, ARG0, ARG1, ARG2];
- print &TS()."Kick \) * ".(split /!/, $IRC0)[0]." \(".(split /!/, $IRC0)[1]."\) kicks ".$IRC2." out of ".$IRC1." \(".$IRC3."\)\n";
- }
- });
- $poe_kernel->run();
- exit 0;
- }
- sub TS {
- my($Sec, $Min, $Hour, $Day, $mon, $year, $WDay, $YDay) = localtime;
- $CurSec = (((($YDay * 24) * 60) * 60) + (($Hour * 60) * 60) + ($Min * 60) + $Sec);
- my $APM = "AM";
- if($Hour > 12) { $Hour -= 12; $APM = "PM"; }
- if($Hour < 10) { $Hour = "0".$Hour; }
- if($Min < 10) { $Min = "0".$Min; }
- if($Sec < 10) { $Sec = "0".$Sec; }
- return $Bot{"Server"}." \( ".$Hour.":".$Min.":".$Sec." ".$APM."~\) ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement