SHARE
TWEET

Untitled

a guest Jun 5th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. # Perl IRC Bot, Version 4 skeleton.
  3.  
  4.  
  5. use lib '/Users/Caaz/lib';
  6. use POE::Component::IRC;
  7. use POE;
  8.  
  9. $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
  10.  
  11. 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";
  12. @Dat = <DATA>;
  13. close DATA;
  14. if($Dat[0] =~ /^$/) {
  15.     print "Adding default settings for first start up.\n";
  16.     open DATA, ">".$Bot{"Path"}."Data.txt";
  17.     print DATA "MyBot:Perl bot, Version 4:Perl:Password:Caaz\nirc.purplesurge.com";
  18.     close DATA;
  19.     open DATA, "<".$Bot{"Path"}."Data.txt";
  20.     @Dat = <DATA>;
  21.     close DATA;
  22. }
  23. if($ARGV[0] =~ /^$/) {
  24.     print "\nSet up mode.\n\n";
  25.     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";
  26.     while (<STDIN>) {
  27.         if (/^END$|^Exit$|^Close$/i) {
  28.             print "Closing...\n";
  29.             exit 0;
  30.         }
  31.         elsif (/^DefSet(.*)/i) {
  32.             ($s = $1) =~ s/^ //gs;
  33.             @erv = split /:/, $s;
  34.             if($erv[4] =~ /^$/) {
  35.                 print "Error, not all areas are properly set up. \nExample : "."MyBot:Perl bot, Version ".$Bot{"Version"}.":Perl:Password:Caaz\n";
  36.             }
  37.             else {
  38.                 print "Saving.\n";
  39.                 shift(@Dat);
  40.                 open DATA, ">".$Bot{"Path"}."Data.txt";
  41.                 print DATA $s."\n".(join "", @Dat);
  42.                 close DATA;
  43.                 open DATA, "<".$Bot{"Path"}."Data.txt";
  44.                 @Dat = <DATA>;
  45.                 close DATA;
  46.             }
  47.         }
  48.         elsif (/^Serv(.*)/i) {
  49.             ($s = $1) =~ s/^ //gs;
  50.             @erv = split /:/, $s;
  51.             if($erv[0] =~ /^$/) {
  52.                 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";
  53.             }
  54.             else {
  55.                 print "Saving.\n";
  56.                 open DATA, ">".$Bot{"Path"}."Data.txt";
  57.                 print DATA $Dat[0].$s;
  58.                 close DATA;
  59.                 open DATA, "<".$Bot{"Path"}."Data.txt";
  60.                 @Dat = <DATA>;
  61.                 close DATA;
  62.             }
  63.         }
  64.         elsif (/^Run$/i) {
  65.             print "Running...\n";
  66.             exec("perl ".$Bot{"Path"}."Bot.pl run ".$Dat[1]);
  67.             exit 0;
  68.         }
  69.         else {
  70.             print "Unknown command\n";
  71.         }
  72.     }
  73. }
  74. if($ARGV[0] =~ /^Run$/i) {
  75.     {
  76.         print join "-", @ARGV."\n";
  77.         open DATA, "<".$Bot{"Path"}."Data.txt";
  78.         @Dat = <DATA>;
  79.         close DATA;
  80.         $Bot{"Server"} = (split /:/, $ARGV[1])[0];
  81.         print "No Server, terminating.\n" if((split /:/, $ARGV[1])[0] =~ /^$/i);
  82.         exit if((split /:/, $ARGV[1])[0] =~ /^$/i);
  83.         $Bot{"Port"} = "6667";
  84.         $Bot{"Port"} = (split /:/, $ARGV[1])[1] if((split /:/, $ARGV[1])[1] !~ /^$/i);
  85.         print "No Port specified, using default : ".$Bot{"Port"}."\n" if((split /:/, $ARGV[1])[1] =~ /^$/i);
  86.         $Bot{"Nick"} = (split /:/, $Dat[0])[0];
  87.         $Bot{"Nick"} = (split /:/, $ARGV[1])[2] if((split /:/, $ARGV[1])[2] !~ /^$/i);
  88.         print "No Nick specified, using default : ".$Bot{"Nick"}."\n" if((split /:/, $ARGV[1])[2] =~ /^$/i);
  89.         $Bot{"Name"} = (split /:/, $Dat[0])[1];
  90.         $Bot{"Name"} = (split /:/, $ARGV[1])[3] if((split /:/, $ARGV[1])[3] !~ /^$/i);
  91.         print "No Name specified, using default : ".$Bot{"Name"}."\n" if((split /:/, $ARGV[1])[3] =~ /^$/i);
  92.         $Bot{"Ident"} = (split /:/, $Dat[0])[2];
  93.         $Bot{"Ident"} = (split /:/, $ARGV[1])[4] if((split /:/, $ARGV[1])[4] !~ /^$/i);
  94.         print "No Ident specified, using default : ".$Bot{"Ident"}."\n" if((split /:/, $ARGV[1])[4] =~ /^$/i);
  95.         $Bot{"NPassword"} = (split /:/, $Dat[0])[3];
  96.         $Bot{"NPassword"} = (split /:/, $ARGV[1])[5] if((split /:/, $ARGV[1])[5] !~ /^$/i);
  97.         print "No Nickserv password specified, using default : ".$Bot{"NPassword"}."\n" if((split /:/, $ARGV[1])[5] =~ /^$/i);
  98.         $Bot{"SPassword"} = (split /:/, $ARGV[1])[6];
  99.         $Bot{"Owner"} = (split /:/, $Dat[0])[7];
  100.         $Bot{"Owner"} = (split /:/, $ARGV[1])[5] if((split /:/, $ARGV[1])[7] !~ /^$/i);
  101.         print "No Owner specified, using default : ".$Bot{"Owner"}."\n" if((split /:/, $ARGV[1])[5] =~ /^$/i);
  102.     }
  103.     my ($irc) = POE::Component::IRC->spawn();
  104.     POE::Session->create( inline_states => {
  105.         _start     => sub {
  106.             $irc->yield(register => "all");
  107.             $irc->yield( connect => {
  108.                 Nick     => $Bot{"Nick"},
  109.                 Username => $Bot{"Ident"},
  110.                 Ircname  => $Bot{"Name"},
  111.                 Server   => $Bot{"Server"},
  112.                 Port     => $Bot{"Port"},
  113.                 Password => $Bot{"SPassword"},
  114.             });
  115.         },
  116.         irc_connected => sub {
  117.             my ($kernel, $IRC0) = @_[KERNEL, ARG0];
  118.             print &TS()."Connected to ".$IRC0.".\n";
  119.             my $alarm_id = $irc->delay( [ join => "#Powerplant" ], 3 );
  120.         },
  121.         irc_disconnected => sub {
  122.             my ($kernel, $IRC0) = @_[KERNEL, ARG0];
  123.             print &TS()."Disconnected from ".$IRC0.".\n";
  124.         },
  125.         irc_error => sub {
  126.             my ($kernel, $IRC0) = @_[KERNEL, ARG0];
  127.             print &TS()."Error : ".$IRC0.".\n";
  128.         },
  129.         irc_join => sub {
  130.             my ($kernel, $IRC0, $IRC1) = @_[KERNEL, ARG0, ARG1];
  131.             print &TS()."Join   \)  * ".(split /!/, $IRC0)[0]." \(".(split /!/, $IRC0)[1]."\) joins ".$IRC1.".\n";
  132.         },#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.
  133.         irc_invite => sub {
  134.             my ($kernel, $IRC0, $IRC1) = @_[KERNEL, ARG0, ARG1];
  135.             print &TS()."Invite \)  * ".(split /!/, $IRC0)[0]." \(".(split /!/, $IRC0)[1]."\) invites you to join ".$IRC1.".\n";
  136.         },
  137.         irc_kick => sub {
  138.             my ($kernel, $IRC0, $IRC1,$IRC2,$IRC3) = @_[KERNEL, ARG0, ARG1, ARG2];
  139.             print &TS()."Kick   \)  * ".(split /!/, $IRC0)[0]." \(".(split /!/, $IRC0)[1]."\) kicks ".$IRC2." out of ".$IRC1." \(".$IRC3."\)\n";
  140.         }
  141.     });
  142.     $poe_kernel->run();
  143.     exit 0;
  144. }
  145. sub TS {
  146.     my($Sec, $Min, $Hour, $Day, $mon, $year, $WDay, $YDay) = localtime;
  147.     $CurSec = (((($YDay * 24) * 60) * 60) + (($Hour * 60) * 60) + ($Min * 60) + $Sec);
  148.     my $APM = "AM";
  149.     if($Hour > 12) { $Hour -= 12; $APM = "PM"; }
  150.     if($Hour < 10) { $Hour = "0".$Hour; }
  151.     if($Min < 10) { $Min = "0".$Min; }
  152.     if($Sec < 10) { $Sec = "0".$Sec; }
  153.     return $Bot{"Server"}." \( ".$Hour.":".$Min.":".$Sec." ".$APM."~\)  ";
  154. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top