Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 10.12 KB | None | 0 0
  1. #!/usr/bin/perl
  2. print "Werewolf autoplay by Caaz.\n";
  3.  
  4. use POE::Component::IRC;
  5. use POE;
  6.  
  7. BOTVARS: {
  8.     $BotNick = "Ookami";        # Nick
  9.     $BotUser = ".";     # Username "indent"
  10.     $BotName = "a Perl bot. Werewolf Autoplay 0.3"; # Real Name
  11.     $BotPass = "PASSWIRD";      # Nickserv Password
  12. }
  13. my ($irc) = POE::Component::IRC->spawn();
  14. POE::Session->create(inline_states => {
  15.     _start     => sub {
  16.         $irc->yield(register => "all");
  17.         $irc->yield( connect => {
  18.             Nick     => $BotNick,
  19.             Username => $BotUser,
  20.             Ircname  => $BotName,
  21.             Server   => "irc.purplesurge.com",
  22.             Port     => "6667",
  23.         });
  24.     },
  25.     irc_001 => sub {
  26.         $irc->yield(mode => $BotNick." +B");
  27.         $irc->yield(privmsg => "Nickserv" => "id ".$BotPass);
  28.         my $alarm_id = $irc->delay( [ join => "#Powerplant,#WWolf" ], 2 );
  29.     },
  30.     irc_error => sub {
  31.         my ($kernel, $IRCWhat) = @_[KERNEL, ARG0];
  32.         print $IRCWhat."\n";
  33.     },
  34.     irc_ctcp_action => sub {
  35.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  36.         $IRCWhere = $where->[0];
  37.         print GetTime()."$IRCWhere >    * ".(split /!/, $IRCWho)[0]." $IRCWhat\n";
  38.         Bot("ACTION",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  39.     },
  40.     irc_join => sub {
  41.         my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  42.         print GetTime()."Join       * ".(split /!/, $IRCWho)[0]." joins $IRCWhere\n";
  43.         Bot("JOIN",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  44.     },
  45.     irc_invite => sub {
  46.         my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  47.         print GetTime()."Invi       * ".(split /!/, $IRCWho)[0]." invites you to $IRCWhere\n";
  48.         Bot("INVITE", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  49.     },
  50.     irc_kick => sub {
  51.         my ($kernel, $IRCWho, $IRCWhere, $IRCWhoElse, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
  52.         print GetTime()."Kick       * ".(split /!/, $IRCWho)[0]." kicks $IRCWhoElse out of $IRCWhere ($IRCWhat)\n";
  53.         Bot("KICK",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhoElse,$IRCWhat);
  54.     },
  55.     irc_msg => sub {
  56.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  57.         $IRCWhere = $where->[0];
  58.         print GetTime()."Priv\a>        <".(split /!/, $IRCWho)[0].">   $IRCWhat\n";
  59.         Bot("PRIVMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  60.     },
  61.     irc_nick => sub {
  62.         my ($kernel, $IRCWho, $IRCWhoElse) = @_[KERNEL, ARG0, ARG1];
  63.         print GetTime()."Nick       * ".(split /!/, $IRCWho)[0]." changes nick to $IRCWhoElse\n";
  64.         Bot("NICK", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhoElse);
  65.     },
  66.     irc_notice => sub {
  67.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  68.         $IRCWhere = $where->[0];
  69.         #print GetTime()."Noti      <".(split /!/, $IRCWho)[0].">   $IRCWhat\n";
  70.         Bot("NOTICE",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  71.     },
  72.     irc_part => sub {
  73.         my ($kernel, $IRCWho, $IRCWhere, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  74.         print GetTime()."Part       * ".(split /!/, $IRCWho)[0]." left channel $IRCWhere \(".$IRCWhat."\)\n";
  75.         Bot("PART",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  76.     },
  77.     irc_public => sub {
  78.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  79.         $IRCWhere = $where->[0];
  80.         print GetTime()."$IRCWhere >    <".(split /!/, $IRCWho)[0].">   $IRCWhat\n";
  81.         Bot("CHANMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  82.     },
  83.     irc_disconnected => sub { print "Disconnected.\n"; exit 1; }, # Ends on disconnect.
  84. },);
  85. sub Bot {
  86.     $Event = $_[0];
  87.     if($Event =~ /CHANMSG/) { $Com = "privmsg ".$_[3]." "; $UserMsg = $_[4]; $Where = $_[3]; }
  88.     elsif($Event =~ /NOTICE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
  89.     elsif($Event =~ /PRIVMSG/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
  90.     elsif($Event =~ /INVITE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[3]; $Where = $_[1]; if ($UserMsg !~ /Spp/i) { $irc->yield(join => $UserMsg); }} # Joins on invite, if it's not spp. heh.
  91.     elsif($Event =~ /JOIN/) { $Com = "notice ".$_[3]." "; $UserMsg = $_[3]; $Where = $_[1]; }
  92.     $UserNick = Regexit($_[1]);
  93.     $UserHost = $_[2];
  94.     $UserMsg = POE::Component::IRC::Common::strip_formatting(POE::Component::IRC::Common::strip_color($UserMsg));
  95.     if(($Where =~ /wwolf/i) || ($UserNick =~ /Wolfbot/i)) {
  96.         if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
  97.             if(($UserMsg =~ /^$BotNick, Join/i) && ($WW{"Will Join"} !~ /No/i)) {
  98.                 $irc->yield(privmsg => "#WWolf" => "!Join");
  99.                 $WW{"Will Join"} = "No";
  100.                 $WW{"MyType"} = "Villager";
  101.             }
  102.             elsif(($UserMsg =~ /^$BotNick, Leave/i) && ($WW{"Will Join"} =~ /No/i)) {
  103.                 $irc->yield(part => "#WWolf" => "Invite me, and I will continue playing.");
  104.                 $WW{"Will Join"} = "Yes";
  105.             }
  106.             elsif($UserMsg =~ /^$BotNick won,/i) {
  107.                 my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => "Woohoo! I won. :D" ], 1 );
  108.                 while ( ($key, $value) = each %WW ) {
  109.                     $WW{$key} = "";
  110.                 }
  111.             }
  112.             elsif($UserMsg =~ /^$BotNick lost,/i) {
  113.                 my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => ";~; I didn't think I'd lose..." ], 1 );
  114.                 while ( ($key, $value) = each %WW ) {
  115.                     $WW{$key} = "";
  116.                 }
  117.             }
  118.             elsif($UserMsg =~ /^The game is over\.$/i) {
  119.                 while ( ($key, $value) = each %WW ) {
  120.                     $WW{$key} = "";
  121.                 }
  122.             }
  123.             elsif($UserMsg =~ /^$BotNick, what are you/i) {
  124.                 if($WW{"MyType"} =~ /Wolf|Village Idiot/) {
  125.                     $irc->yield(privmsg => "#WWolf" => "I am a Villager.");
  126.                 }
  127.                 else {
  128.                     $irc->yield(privmsg => "#WWolf" => "I am a ".$WW{"MyType"}.".");
  129.                 }
  130.             }
  131.             elsif($UserMsg =~ /(.*?) (has joined|has started)/i) {
  132.                 if($1 =~ /$BotNick/) { return 0; }
  133.                 $WW{"Players"} = $WW{"Players"}.$1." ";
  134.                 @WWPlayers = split / /, $WW{"Players"};
  135.                 print "Updating players...\n".@WWPlayers."\n";
  136.             }
  137.             elsif($UserMsg =~ /^(.*) (has left the game|struggles vainly|was)/i) {
  138.                 $WW{"Players"} =~ s/$1 //igs;
  139.                 @WWPlayers = split / /, $WW{"Players"};
  140.                 print "Updating players...\n".@WWPlayers."\n";
  141.             }
  142.             elsif($UserMsg =~ /seconds to send your votes/i) {
  143.                 if($WW{"Vote"} =~ /^$/) {
  144.                     my $alarm_id = $irc->delay( [ privmsg => "WolfBot" => "vote ".$WWPlayers[int(rand(@WWPlayers))] ], 5 );
  145.                     print $WWPlayers[int(rand(@WWPlayers))];
  146.                 }
  147.                 else {
  148.                     my $alarm_id = $irc->delay( [ privmsg => "WolfBot" => "vote ".$WW{"Vote"} ], 5 );
  149.                 }
  150.                 $WW{"Vote"} = "";
  151.                 if($WW{"MyType"} =~ /Village Idiot/i) {
  152.                     $WW{"Vote"} = $BotNick;
  153.                 }
  154.             }
  155.             if(($UserNick =~ /WolfBot/i) && ($Event =~ /(NOTICE|PRIVMSG|CHANMSG)/)) {
  156.                 if($UerMsg =~ /You are a wolf!/i) {
  157.                     $WW{"MyType"} = "Wolf";
  158.                     print "Wolf!";
  159.                 }
  160.                 elsif($UserMsg =~ /You are the finder!/i) {
  161.                     $WW{"MyType"} = "Finder";
  162.                 }
  163.                 elsif($UserMsg =~ /You are the seer!/i) {
  164.                     $WW{"MyType"} = "Seer";
  165.                 }
  166.                 elsif($UserMsg =~ /You are the doppleganger!/i) {
  167.                     $WW{"MyType"} = "Doppleganger";
  168.                 }
  169.                 elsif($UserMsg =~ /You are the angel!/i) {
  170.                     $WW{"MyType"} = "Angel";
  171.                 }
  172.                 elsif($UserMsg =~ /You are the Village Idiot!/i) {
  173.                     $WW{"MyType"} = "Village Idiot";
  174.                     my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $WWPlayers[int(rand(@WWPlayers))]." is Wolf." ], 50 );
  175.                     $WW{"Vote"} = $BotNick;
  176.                 }
  177.                 elsif($UserMsg =~ /You transform into (a|an) (.*?)!/i) {
  178.                     $tring = $2;
  179.                     if($tring =~ /werewolf/i) { $WW{"MyType"} = "Wolf"; }
  180.                     else {
  181.                         $WW{"MyType"} = $tring;
  182.                     }
  183.                 }
  184.                 elsif($UserMsg =~ /You have 45/i) {
  185.                     if($WW{"MyType"} =~ /Wolf/i) {
  186.                         $irc->yield(privmsg => "wolfbot" => "kill ".$WWPlayers[int(rand(@WWPlayers))]);
  187.                     }
  188.                     elsif($WW{"MyType"} =~ /Seer/i) {
  189.                         foreach (@WWPlayers) {
  190.                             if($WW{"Targeted"} !~ /Regexit($_)/i){
  191.                                 $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
  192.                                 $WW{"Target"} = $_;
  193.                                 last;
  194.                             }
  195.                         }
  196.                         $irc->yield(privmsg => "wolfbot" => "see ".$WW{"Target"});
  197.                     }
  198.                     elsif($WW{"MyType"} =~ /Finder/i) {
  199.                         foreach (@WWPlayers) {
  200.                             if($WW{"Targeted"} !~ /Regexit($_)/i){
  201.                                 $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
  202.                                 $WW{"Target"} = $_;
  203.                                 last;
  204.                             }
  205.                         }
  206.                         $irc->yield(privmsg => "wolfbot" => "find ".$WW{"Target"});
  207.                     }
  208.                     if($WW{"MyType"} =~ /Doppleganger/i) {
  209.                         $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
  210.                         $irc->yield(privmsg => "wolfbot" => "dopple ".$WW{"Target"});
  211.                     }
  212.                     if($WW{"MyType"} =~ /Angel/i) {
  213.                         $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
  214.                         $irc->yield(privmsg => "wolfbot" => "shield ".$WW{"Target"});
  215.                     }
  216.                 }
  217.                 elsif($UserMsg =~ /(.*?) is (a|an) (.*?)!/i) {
  218.                     $tring = $1;
  219.                     $tringt = $3;
  220.                     if($tringt =~ /(Wolf|Village Idiot)/i) {
  221.                         my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is ".$1."." ], 5 );
  222.                         $WW{"Vote"} = $tring if($tringt !~ /Village Idiot/);
  223.                     }
  224.                     elsif($tringt =~ /Angel/i) {
  225.                         my $alarm_id = $irc->delay( [ privmsg => $tring => "I'm seer, and you're angel, right? Protect me, I'll keep looking for the wolf." ], 2 );
  226.                     }
  227.                     elsif($tringt =~ /Doppleganger/i) {
  228.                         my $alarm_id = $irc->delay( [ privmsg => $tring => "Dopple me for seer!" ], 2 );
  229.                     }
  230.                 }
  231.                 elsif($UserMsg =~ /(.*?) targetted (.*?)!/i) {
  232.                     $tring = $1;
  233.                     $tringt = $3;
  234.                     my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." targetted ".$tringt."." ], 5 );
  235.                     $WW{"Vote"} = $tring;
  236.                 }
  237.                 elsif($UserMsg =~ /The (wolves|other wolves) are: (.*)/i) {
  238.                     @WWolfs = split /, /, $1;
  239.                     print "Updating players...\n";
  240.                     foreach (@WWolfs) {
  241.                         $WW{"Players"} =~ s/$_ //gs;
  242.                         @WWPlayers = split / /, $WW{"Players"};
  243.                         print "Updating players...\n".@WWPlayers."\n";
  244.                     }
  245.                 }
  246.             }
  247.         }
  248.     }
  249. }
  250. sub Regexit {
  251.     ($Reg = $_[0]) =~ s/\\/\\\\/gs;
  252.     $Reg =~ s/(\?|\(|\)|\||\[|\|\{|\}|\.)/\\$1/gs;
  253.     $Reg =~ s/\*/\(\.\*\)/gs;
  254.     return $Reg;
  255. }
  256. sub GetTime { # This is just for timestamps, just leave it.
  257.     my($Sec, $Min, $Hour, $Day, $Mon, $Year, $WDay, $YDay) = localtime;
  258.     my $APM = "AM";
  259.     if($Hour > 12) { $Hour -= 12; $APM = "PM"; }
  260.     if($Hour < 10) { $Hour = "0".$Hour; }
  261.     if($Min < 10) { $Min = "0".$Min; }
  262.     if($Sec < 10) { $Sec = "0".$Sec; }
  263.     return "[ $Hour:$Min:$Sec $APM ]    ";
  264. }
  265. # Caaz was here.
  266. $poe_kernel->run();
  267. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement