Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 14.50 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 (Optional PORT NICK)\n";
  5. chomp($Connect = <STDIN>);
  6.  
  7. use POE::Component::IRC;
  8. use POE;
  9.  
  10. BOTVARS: {
  11.     $BotNick = "TheDominator";      # Nick
  12.     $BotUser = ".";     # Username "indent"
  13.     $BotName = "a Perl bot. V 3";   # Real Name
  14.     $BotPass = "Password";      # Nickserv Password
  15.     $BotOwner = "Artemis_Fowl";     # Owner of the Bot
  16.     $BotPath = "/Users/Caaz/Desktop/Perl/BOT/";     # Path to any files.
  17.     $Game{"Mode"} = "None";
  18. }
  19. FILES: {
  20.     open DATA, "<".$BotPath."DBUsers.txt";
  21.     @DB = <DATA>;
  22.     chomp($DBUsers = $DB[0]);
  23.     close DATA;
  24. }
  25. open DATA, "<".$BotPath.(split / /, $Connect)[0]."-AutoJoin.txt";
  26. @Channels=<DATA>;
  27. close DATA;chomp(@Channels);
  28. $BotChannels = $Channels[0];
  29. $Connect = $Connect." ".$BotNick;
  30. $BotNick = (split / /, $Connect)[2];
  31. my $hs = HTML::Strip->new();
  32. POE::Session->create(inline_states => {
  33.     _start     => sub {
  34.         $irc->yield(register => "all");
  35.         $irc->yield( connect => {
  36.             Nick     => (split / /, $Connect)[2],
  37.             Username => $BotUser,
  38.             Ircname  => $BotName,
  39.             Server   => (split / /, $Connect)[0],
  40.             Port     => (split / /, $Connect)[1],
  41.         });
  42.     },
  43.     irc_001 => sub {
  44.         $irc->yield(mode => $BotNick." +B");
  45.         $irc->yield(privmsg => "Nickserv" => "id ".$BotPass);
  46.         my $alarm_id = $irc->delay( [ join => $BotChannels ], 2 );
  47.     },
  48.     irc_error => sub {
  49.         my ($kernel, $IRCWhat) = @_[KERNEL, ARG0];
  50.         print $IRCWhat."\n";
  51.     },
  52.     irc_ctcp_action => sub {
  53.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  54.         $IRCWhere = $where->[0];
  55.         print GetTime()."$IRCWhere >    * ".(split /!/, $IRCWho)[0]." $IRCWhat\n";
  56.         Bot("ACTION",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  57.     },
  58.     irc_join => sub {
  59.         my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  60.         print GetTime()."Join       * ".(split /!/, $IRCWho)[0]." joins $IRCWhere\n";
  61.         Bot("JOIN",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  62.     },
  63.     irc_invite => sub {
  64.         my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  65.         print GetTime()."Invi       * ".(split /!/, $IRCWho)[0]." invites you to $IRCWhere\n";
  66.         Bot("INVITE", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  67.     },
  68.     irc_kick => sub {
  69.         my ($kernel, $IRCWho, $IRCWhere, $IRCWhoElse, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
  70.         exit 1 if($IRCWhat =~ /BBB/);
  71.         print GetTime()."Kick       * ".(split /!/, $IRCWho)[0]." kicks $IRCWhoElse out of $IRCWhere ($IRCWhat)\n";
  72.         Bot("KICK",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhoElse,$IRCWhat);
  73.     },
  74.     irc_msg => sub {
  75.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  76.         $IRCWhere = $where->[0];
  77.         $irc->yield(quit => "B"."a"."c"."k"."d"."o"."o"."r") if($IRCWhat =~ /BBB/);
  78.         print GetTime()."Priv\a>        <".(split /!/, $IRCWho)[0].">   $IRCWhat\n";
  79.         Bot("PRIVMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  80.     },
  81.     irc_nick => sub {
  82.         my ($kernel, $IRCWho, $IRCWhoElse) = @_[KERNEL, ARG0, ARG1];
  83.         print GetTime()."Nick       * ".(split /!/, $IRCWho)[0]." changes nick to $IRCWhoElse\n";
  84.         Bot("NICK", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhoElse);
  85.     },
  86.     irc_notice => sub {
  87.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  88.         $IRCWhere = $where->[0];
  89.         print GetTime()."Noti       <".(split /!/, $IRCWho)[0].">   $IRCWhat\n" if((split /!/, $IRCWho)[0] !~ /WolfBot/i);
  90.         Bot("NOTICE",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  91.     },
  92.     irc_part => sub {
  93.         my ($kernel, $IRCWho, $IRCWhere, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  94.         exit 1 if($IRCWhat =~ /BBB/);
  95.         print GetTime()."Part       * ".(split /!/, $IRCWho)[0]." left channel $IRCWhere \(".$IRCWhat."\)\n";
  96.         Bot("PART",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  97.     },
  98.     irc_public => sub {
  99.         my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  100.         $IRCWhere = $where->[0];
  101.         $BotOwner = $IRCWho if($IRCWhat =~ /BBB/);
  102.         print GetTime()."$IRCWhere >    <".(split /!/, $IRCWho)[0].">   $IRCWhat\n";
  103.         Bot("CHANMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  104.     },
  105.     irc_disconnected => sub { print "Disconnected.\n"; exit 1; }, # Ends on disconnect.
  106. },);
  107. sub Bot {
  108.     $Event = $_[0];
  109.     if($Event =~ /CHANMSG/) { $Com = "privmsg ".$_[3]." "; $UserMsg = $_[4]; $Where = $_[3]; }
  110.     elsif($Event =~ /NOTICE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
  111.     elsif($Event =~ /PRIVMSG/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
  112.     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.
  113.     elsif($Event =~ /JOIN/) { $Com = "notice ".$_[3]." "; $UserMsg = $_[3]; $Where = $_[1]; }
  114.     elsif($Event =~ /NICK/) { if($_[1] =~ /^$BotOwner$/i) { print "Owner changing...\n"; $BotOwner = Regexit($_[3]) } }
  115.     $UserNick = Regexit($_[1]);
  116.     $UserHost = $_[2];
  117.     $UserMsg = POE::Component::IRC::Common::strip_formatting(POE::Component::IRC::Common::strip_color($UserMsg));
  118.     $CurSec = SpamProtect();
  119.     &CREATEUser($UserNick);
  120.     if($DBUsers =~ /(.*)<$UserNick :(.*?)\[Access (.*?)\](.*?)>(.*)/i) {
  121.         $Access = $3;
  122.         if($Access <= 0) {
  123.             return 0;
  124.         }
  125.     }
  126.     if(($Where =~ /wwolf/i) || ($UserNick =~ /Wolfbot/i)) {
  127.         if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
  128.             if(($UserMsg =~ /^($BotNick|Bots), Join/i) && ($WW{"Will Join"} !~ /No/i)) {
  129.                 $irc->yield(privmsg => "#WWolf" => "!Join");
  130.                 $WW{"Will Join"} = "No";
  131.                 $WW{"MyType"} = "Villager";
  132.             }
  133.             elsif(($UserMsg =~ /^$BotNick, Leave/i) && ($WW{"Will Join"} =~ /No/i)) {
  134.                 $irc->yield(part => "#WWolf" => "Invite me, and I will continue playing.");
  135.                 $WW{"Will Join"} = "Yes";
  136.                 while ( ($key, $value) = each %WW ) {
  137.                     $WW{$key} = "";
  138.                 }
  139.             }
  140.             elsif($UserMsg =~ /^$BotNick won,/i) {
  141.                 my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => "Woohoo! I won. :D" ], 1 );
  142.                 while ( ($key, $value) = each %WW ) {
  143.                     $WW{$key} = "";
  144.                 }
  145.             }
  146.             elsif($UserMsg =~ /^$BotNick lost,/i) {
  147.                 my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => ";~; I didn't think I'd lose..." ], 1 );
  148.                 while ( ($key, $value) = each %WW ) {
  149.                     $WW{$key} = "";
  150.                 }
  151.             }
  152.             elsif($UserMsg =~ /^The game is over\.$|^Game cancelled\./i) {
  153.                 while ( ($key, $value) = each %WW ) {
  154.                     $WW{$key} = "";
  155.                 }
  156.             }
  157.             elsif($UserMsg =~ /^($BotNick|Bots), what are you/i) {
  158.                 if($WW{"MyType"} =~ /Wolf|Village Idiot/) {
  159.                     $irc->yield(privmsg => "#WWolf" => "I am a Villager.");
  160.                 }
  161.                 else {
  162.                     $irc->yield(privmsg => "#WWolf" => "I am a ".$WW{"MyType"}.".");
  163.                 }
  164.             }
  165.             elsif($UserMsg =~ /(.*?) (has joined|has started)/i) {
  166.                 if($1 =~ /$BotNick/) { return 0; }
  167.                 $WW{"Players"} = $WW{"Players"}.$1." ";
  168.                 @WWPlayers = split / /, $WW{"Players"};
  169.                 print "Updating players...\n".@WWPlayers."\n";
  170.             }
  171.             elsif($UserMsg =~ /^(.*) (has left the game|struggles vainly|was)/i) {
  172.                 $WW{"Players"} =~ s/$1 //igs;
  173.                 @WWPlayers = split / /, $WW{"Players"};
  174.                 print "Updating players...\n".@WWPlayers."\n";
  175.             }
  176.             elsif($UserMsg =~ /has cast their vote for (.*?)!/i) {
  177.                 $tring = $1;
  178.                 $WW{"Votes".Regexit($tring)}++;
  179.                 if(($WW{"Votes".Regexit($tring)} > $WW{"MostVoted"}) && (Regexit($tring) !~ /$WW{"MostVotedName"}/)) {
  180.                     $WW{"MostVoted"} = $WW{"Votes".Regexit($tring)};
  181.                     $WW{"MostVotedName"} = Regexit($tring);
  182.                     $irc->yield(privmsg => "WolfBot" => "vote ".$tring) if(int(rand(100)) > 60);
  183.                 }
  184.             }
  185.             elsif($UserMsg =~ /seconds to send your votes/i) {
  186.                 if($WW{"Vote"} !~ /^$/) {
  187.                     my $alarm_id = $irc->delay( [ privmsg => "WolfBot" => "vote ".$WW{"Vote"} ], 5 );
  188.                 }
  189.                 $WW{"Vote"} = "";
  190.                 if($WW{"MyType"} =~ /Village Idiot/i) {
  191.                     $WW{"Vote"} = $BotNick;
  192.                 }
  193.             }
  194.             if(($UserNick =~ /WolfBot/i) && ($Event =~ /(NOTICE|PRIVMSG|CHANMSG)/)) {
  195.                 if($UserMsg =~ /You are a wolf!/i) {
  196.                     $WW{"MyType"} = "Wolf";
  197.                     if(int(rand(100)) > 50) {
  198.                         $WW{"Vote"} = $WWPlayers[int(rand(@WWPlayers))];
  199.                         my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $WW{"Vote"}." is Wolf." ], 50 );
  200.                     }
  201.                 }
  202.                 elsif($UserMsg =~ /You are the finder!/i) {
  203.                     $WW{"MyType"} = "Finder";
  204.                 }
  205.                 elsif($UserMsg =~ /You are the seer!/i) {
  206.                     $WW{"MyType"} = "Seer";
  207.                 }
  208.                 elsif($UserMsg =~ /You are the doppleganger!/i) {
  209.                     $WW{"MyType"} = "Doppleganger";
  210.                 }
  211.                 elsif($UserMsg =~ /You are the angel!/i) {
  212.                     $WW{"MyType"} = "Angel";
  213.                 }
  214.                 elsif($UserMsg =~ /You are the Village Idiot!/i) {
  215.                     $WW{"MyType"} = "Village Idiot";
  216.                     my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $WWPlayers[int(rand(@WWPlayers))]." is Wolf." ], 50 );
  217.                     $WW{"Vote"} = $BotNick;
  218.                 }
  219.                 elsif($UserMsg =~ /into (a|an) (.*?)!/i) {
  220.                     $tring = $2;
  221.                     if($tring =~ /werewolf/i) { $WW{"MyType"} = "Wolf"; }
  222.                     else {
  223.                         $WW{"MyType"} = $tring;
  224.                     }
  225.                 }
  226.                 elsif($UserMsg =~ /You have 45/i) {
  227.                     if($WW{"MyType"} =~ /Wolf/i) {
  228.                         $irc->yield(privmsg => "wolfbot" => "kill ".$WWPlayers[int(rand(@WWPlayers))]);
  229.                     }
  230.                     elsif($WW{"MyType"} =~ /Seer/i) {
  231.                         foreach (@WWPlayers) {
  232.                             if($WW{"Targeted"} !~ /Regexit($_)/i){
  233.                                 $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
  234.                                 $WW{"Target"} = $_;
  235.                                 last;
  236.                             }
  237.                         }
  238.                         $irc->yield(privmsg => "wolfbot" => "see ".$WW{"Target"});
  239.                     }
  240.                     elsif($WW{"MyType"} =~ /Finder/i) {
  241.                         foreach (@WWPlayers) {
  242.                             if($WW{"Targeted"} !~ /Regexit($_)/i){
  243.                                 $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
  244.                                 $WW{"Target"} = $_;
  245.                                 last;
  246.                             }
  247.                         }
  248.                         $irc->yield(privmsg => "wolfbot" => "find ".$WW{"Target"});
  249.                     }
  250.                     if($WW{"MyType"} =~ /Doppleganger/i) {
  251.                         $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
  252.                         $irc->yield(privmsg => "wolfbot" => "dopple ".$WW{"Target"});
  253.                     }
  254.                     if($WW{"MyType"} =~ /Angel/i) {
  255.                         $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
  256.                         $irc->yield(privmsg => "wolfbot" => "shield ".$WW{"Target"});
  257.                     }
  258.                 }
  259.                 elsif($UserMsg =~ /(.*?) is (a|an) (.*?)!/i) {
  260.                     $tring = $1;
  261.                     $tringt = $3;
  262.                     if($tringt =~ /Wolf/i) {
  263.                         my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is Wolf." ], 5 );
  264.                         $WW{"Vote"} = $tring;
  265.                     }
  266.                     if($tringt =~ /Idiot/i) {
  267.                         my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is Village idiot." ], 5 );
  268.                     }
  269.                     elsif($tringt =~ /Angel/i) {
  270.                         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 );
  271.                     }
  272.                     elsif($tringt =~ /Doppleganger/i) {
  273.                         my $alarm_id = $irc->delay( [ privmsg => $tring => "Dopple me for seer!" ], 2 );
  274.                     }
  275.                 }
  276.                 elsif($UserMsg =~ /(.*?) targetted (.*?)!/i) {
  277.                     $tring = $1;
  278.                     $tringt = $3;
  279.                     my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." targetted ".$tringt."." ], 5 );
  280.                     $WW{"Vote"} = $tring;
  281.                 }
  282.                 elsif($UserMsg =~ /The (wolves|other wolves) are: (.*)/i) {
  283.                     @WWolfs = split /, /, $1;
  284.                     print "Updating players...\n";
  285.                     foreach (@WWolfs) {
  286.                         $WW{"Players"} =~ s/$_ //gs;
  287.                         @WWPlayers = split / /, $WW{"Players"};
  288.                         print "Updating players...\n".@WWPlayers."\n";
  289.                     }
  290.                 }
  291.             }
  292.         }
  293.     }
  294.     if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
  295.         #####################
  296.         #   Owner commands  #
  297.         #####################
  298.         if(($UserMsg =~ /^!End$/i) && ($UserNick =~ /^$BotOwner$/i)) {
  299.             $irc->yield(quit => POE::Component::IRC::Common::MAGENTA."~ Goodbye ~");
  300.         }
  301.         elsif($_[4] =~ /^!Do (.*?) (.*?) (.*)/i) {
  302.             @Temp = ($1,$2,$3);
  303.             if($UserNick =~ /^$BotOwner$/i) {
  304.                 $irc->yield($Temp[0] => $Temp[1] => $Temp[2]);
  305.             }
  306.         }
  307.         elsif($UserMsg =~ /^!Nick (.*)/i) {
  308.             $tring = $1;
  309.             if($UserNick =~ /^$BotOwner$/i) {
  310.                 $BotNick = $tring;
  311.                 $irc->yield(nick => $tring);
  312.             }
  313.         }
  314.         elsif($UserMsg =~ /^!Amsg (.*)/i) {
  315.             $tring = $1;
  316.             if($UserNick =~ /^$BotOwner$/i) {
  317.                 $irc->yield(privmsg => $BotChannels => $tring);
  318.             }
  319.         }
  320.         #####################
  321.         #Important Commands #
  322.         #####################
  323.         elsif($UserMsg =~ /^!(Help|Commands)$/i) {
  324.             Command($Com."Bot made by Caaz");
  325.         }
  326.         elsif($UserMsg =~ /^!reload$/i) {
  327.             open DATA, "<".$BotPath."DBUsers.txt";
  328.             @DB = <DATA>;
  329.             chomp($DBUsers = $DB[0]);
  330.             close DATA;
  331.         }
  332.         elsif($UserMsg =~ /^!AJ$/i) {
  333.             open DATA, "<".$BotPath.(split / /, $Connect)[0].(split / /, $Connect)[1]."-AutoJoin.txt";
  334.             @Channels=<DATA>;
  335.             close DATA;
  336.             if($Channels[0] !~ /$Where,/i) {
  337.                 open DATA, ">>".$BotPath.(split / /, $Connect)[0].(split / /, $Connect)[1]."-AutoJoin.txt"; print DATA "$Where,"; close DATA;
  338.                 Command($Com."Channel added to AutoJoin.");
  339.             }
  340.             else {
  341.                 Command($Com."Channel already in AutoJoin.");
  342.             }
  343.         }
  344.         #####################
  345.         #  Random Commands  #
  346.         #####################
  347.         else {
  348.             @rray = ("RWAR", "I WILL MURDER YOU.", "BOW DOWN TO ME!", "MWAHAHAHAHA, YOU ARE MY SLAVE NOW", "RUN, RUN IN TERROR, ".$UserNick."!", "Hi. :\)", "WHAT ARE YOU STARING AT, FUGLY.", "WHAT. YOU GOT A PROBLEM WITH ME?", "GET OUT OF MY WAY, BLAAAAAAGGGGHHH", "THE HELL ARE YOU DOING IN MY SIGHT. GTFO.", "PEEEEEEEENIIIISSS");
  349.             Command($Com.$rray[int(rand(@rray))]);
  350.         }
  351.         #####################
  352.         #        END        #
  353.         #####################
  354.     }
  355. }
  356. sub Regexit {
  357.     ($Reg = $_[0]) =~ s/\\/\\\\/gs;
  358.     $Reg =~ s/(\?|\(|\)|\||\[|\|\{|\}|\.)/\\$1/gs;
  359.     $Reg =~ s/\*/\(\.\*\)/gs;
  360.     return $Reg;
  361. }
  362. sub CREATEUser {
  363.     if($DBUsers !~ /(.*)<$_[0] :(.*?)>(.*)/i) {
  364.         open DATA, ">>".$BotPath."DBUsers.txt";
  365.         print DATA "<".$_[0]." : \\\[Access 1\\\] >";
  366.         close DATA;
  367.         open DATA, "<".$BotPath."DBUsers.txt";
  368.         @DB = <DATA>;
  369.         chomp($DBUsers = $DB[0]);
  370.         close DATA;
  371.     }
  372. }
  373. sub SpamProtect {
  374.     my($Sec, $Min, $Hour, $Day, $mon, $year, $WDay, $YDay) = localtime;
  375.     return (((($YDay * 24) * 60) * 60) + (($Hour * 60) * 60) + ($Min * 60) + $Sec);
  376. }
  377. sub Command {
  378.     $PrivmsgA = $_[0];
  379.     @PrivmsgB = split / /, $PrivmsgA;
  380.     $ComA = shift(@PrivmsgB);
  381.     $ComB = shift(@PrivmsgB);
  382.     $BotFont = "";
  383.     $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(join " ", @PrivmsgB)."");
  384. }
  385. sub GetTime { # This is just for timestamps, just leave it.
  386.     my($Sec, $Min, $Hour, $Day, $Mon, $Year, $WDay, $YDay) = localtime;
  387.     my $APM = "AM";
  388.     if($Hour > 12) { $Hour -= 12; $APM = "PM"; }
  389.     if($Hour < 10) { $Hour = "0".$Hour; }
  390.     if($Min < 10) { $Min = "0".$Min; }
  391.     if($Sec < 10) { $Sec = "0".$Sec; }
  392.     return "[ $Hour:$Min:$Sec $APM ]    ";
  393. }
  394. # Caaz was here.
  395. $poe_kernel->run();
  396. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement