Advertisement
Guest User

Untitled

a guest
May 29th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.41 KB | None | 0 0
  1. #!/usr/bin/perl
  2. print "POE IRC Bot. Skeleton by Caaz.\n";
  3. print "You can add an optional ! NICK.\n";
  4. print "SERVER ! PORT\n";
  5. chomp($Connect = <STDIN>);
  6.  
  7. use POE::Component::IRC;
  8. use POE;
  9.  
  10. # Fill these out.
  11. $BotNick = "Luka";      # Nick
  12. $BotUser = ".";     # Username "indent"
  13. $BotName = "a Perl bot. Originally by Caaz";    # Real Name
  14. $BotPass = "";      # Nickserv Password
  15. $BotOwner = "Caaz";     # Owner of the Bot
  16. $BotPath = "";      # Path to any files.
  17. $BotChannels = "#Powerplant";   # Channels it joins on connect.
  18.  
  19.  
  20. $Connect = $Connect." ! ".$BotNick;
  21. $BotNick = (split / ! /, $Connect)[2];
  22.  
  23. # Alright now, here's where we connect and get some events.
  24. my ($irc) = POE::Component::IRC->spawn();
  25. POE::Session->create(inline_states => {
  26.     _start     => sub {
  27.         $irc->yield(register => "all");
  28.         $irc->yield( connect => {
  29.             Nick     => (split / ! /, $Connect)[2],
  30.             Username => $BotUser,
  31.             Ircname  => $BotName,
  32.             Server   => (split / ! /, $Connect)[0],
  33.             Port     => (split / ! /, $Connect)[1],
  34.         });
  35.     },
  36.     irc_001 => sub {
  37.         $irc->yield(mode => $BotNick." +B");
  38.         $irc->yield(privmsg => "Nickserv" => "id ".$BotPass);
  39.         $irc->yield(join => $BotChannels);
  40.     },
  41.     irc_error => sub {
  42.         my ($kernel, $IRCWhat) = @_[KERNEL, ARG0];
  43.         print $IRCError."\n";
  44.     },
  45.     irc_ctcp_action => sub {
  46.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  47.         $IRCWhere = $where->[0];
  48.         print GetTime()."$IRCWhere >    * ".(split /!/, $IRCWho)[0]." $IRCWhat\n";
  49.         Bot("ACTION",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  50.     },
  51.     irc_join => sub {
  52.         my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  53.         print GetTime()."Join   * ".(split /!/, $IRCWho)[0]." joins $IRCWhere\n";
  54.         Bot("JOIN",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  55.     },
  56.     irc_invite => sub {
  57.         my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  58.         print GetTime()."Invi   * ".(split /!/, $IRCWho)[0]." invites you to $IRCWhere\n";
  59.         Bot("INVITE", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  60.     },
  61.     irc_kick => sub {
  62.         my ($kernel, $IRCWho, $IRCWhere, $IRCWhoElse, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
  63.         print GetTime()."Kick   * ".(split /!/, $IRCWho)[0]." kicks $IRCWhoElse out of $IRCWhere ($IRCWhat)\n";
  64.         Bot("KICK",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhoElse,$IRCWhat);
  65.     },
  66.     irc_msg => sub {
  67.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  68.         $IRCWhere = $where->[0];
  69.         print GetTime()."Priv >  <".(split /!/, $IRCWho)[0].">  $IRCWhat\n";
  70.         Bot("PRIVMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  71.     },
  72.     irc_nick => sub {
  73.         my ($kernel, $IRCWho, $IRCWhoElse) = @_[KERNEL, ARG0, ARG1];
  74.         print GetTime()."$IRCWhere >     Nick * ".(split /!/, $IRCWho)[0]." changes nick to $IRCWhoElse\n";
  75.         Bot("NICK", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhoElse);
  76.     },
  77.     irc_notice => sub {
  78.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  79.         $IRCWhere = $where->[0];
  80.         print GetTime()."Noti >  <".(split /!/, $IRCWho)[0].">  $IRCWhat\n";
  81.         Bot("NOTICE",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  82.     },
  83.     irc_part => sub {
  84.         my ($kernel, $IRCWho, $IRCWhere, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  85.         print GetTime()."Part   >   *".(split /!/, $IRCWho)[0]." left channel $IRCWhere \(".$IRCWhat."\)\n";
  86.         Bot("PART",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  87.     },
  88.     irc_public => sub {
  89.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  90.         $IRCWhere = $where->[0];
  91.         print GetTime()."$IRCWhere >     <".(split /!/, $IRCWho)[0].">  $IRCWhat\n";
  92.         Bot("CHANMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  93.     },
  94.     irc_disconnected => sub { print "Disconnected.\n"; exit 1; }, # Ends on disconnect.
  95. },);
  96. sub Bot {
  97.     $Event = $_[0];
  98.     if($Event =~ /CHANMSG/) { $Com = "privmsg ".$_[3]; $UserMsg = $_[4]; }
  99.     elsif($Event =~ /NOTICE/) { $Com = "notice ".$_[1]; $UserMsg = $_[4]; }
  100.     elsif($Event =~ /PRIVMSG/) { $Com = "notice ".$_[1]; $UserMsg = $_[4]; }
  101.     elsif($Event =~ /INVITE/) { $Com = "notice ".$_[1]; $UserMsg = $_[3]; }
  102.     elsif($Event =~ /JOIN/) { $Com = "notice ".$_[3]; $UserMsg = $_[3]; }
  103.     elsif($Event =~ /NICK/) { if($_[1] =~ /^$BotOwner$/i) { print "Owner changing...\n"; $BotOwner = $_[3]; } }
  104.     $UserNick = $_[1];
  105.     $UserHost = $_[2];
  106.     $UserMsg = POE::Component::IRC::Common::strip_color($UserMsg);
  107.     $CurSec = SpamProtect();
  108.     # Now this, is where the magic happens `O'
  109.     if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
  110.         if(($UserMsg =~ /^~End$/i) && ($UserNick =~ /^$BotOwner$/i)) {
  111.             $irc->yield(quit => POE::Component::IRC::Common::MAGENTA."〜 Goodbye 〜");
  112.         }
  113.     }
  114. }
  115. sub SpamProtect {
  116.     my($Sec, $Min, $Hour, $Day, $mon, $year, $WDay, $YDay) = localtime;
  117.     return (((($YDay * 24) * 60) * 60) + (($Hour * 60) * 60) + ($Min * 60) + $Sec);
  118. }
  119. sub Privmsg {
  120.     $PrivmsgA = $_[0];
  121.     @PrivmsgB = split / /, $PrivmsgA;
  122.     $ComA = shift(@PrivmsgB);
  123.     $ComB = shift(@PrivmsgB);
  124.     $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(join " ", @PrivmsgB)." 〜");
  125. }
  126. sub GetTime {
  127.     my($Sec, $Min, $Hour, $Day, $Mon, $Year, $WDay, $YDay) = localtime;
  128.     my $APM = "AM";
  129.     if($Hour > 12) { $Hour -= 12; $APM = "PM"; }
  130.     if($Hour < 10) { $Hour = "0".$Hour; }
  131.     if($Min < 10) { $Min = "0".$Min; }
  132.     if($Sec < 10) { $Sec = "0".$Sec; }
  133.     return "[ $Hour:$Min:$Sec $APM ]    ";
  134. }
  135. # Caaz was here.
  136. $poe_kernel->run();
  137. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement