Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- print "POE IRC Bot. Skeleton by Caaz.\n";
- print "You can add an optional NICK.\n";
- print "SERVER \(Optional PORT, and NICK\)\n";
- chomp($Connect = <STDIN>);
- use lib '/Users/Caaz/lib';
- use POE::Component::IRC;
- use POE;
- use LWP::Simple;
- use LWP::UserAgent;
- use Digest::MD5 qw(md5 md5_hex md5_base64);
- use HTML::Strip;
- BOTVARS: {
- $BotNick = "MajinBot"; # Nick
- $BotUser = "."; # Username "indent"
- $BotName = "a Perl bot. Version 3"; # Real Name
- $BotPass = "PASSWORD"; # Nickserv Password
- $BotOwner = "MajinMew"; # Owner of the Bot
- $BotPath = "C:\\users\\Steven\\desktop\\majinbot\\"; # Path to any files.
- }
- FILES: {
- open DATA, "<".$BotPath."DBUsers.txt";
- @DB = <DATA>;
- chomp($DBUsers = $DB[0]);
- close DATA;
- }
- open DATA, "<".$BotPath.(split / /, $Connect)[0]."-AutoJoin.txt";
- @Channels=<DATA>;
- close DATA;chomp(@Channels);
- $BotChannels = $Channels[0];
- $Connect = $Connect." ".$BotNick." ";
- $BotNick = (split / /, $Connect)[2];
- my $hs = HTML::Strip->new();
- my ($irc) = POE::Component::IRC->spawn();
- POE::Session->create(inline_states => {
- _start => sub {
- $irc->yield(register => "all");
- $irc->yield( connect => {
- Nick => (split / /, $Connect)[2],
- Username => $BotUser,
- Ircname => $BotName,
- Server => (split / /, $Connect)[0],
- Port => (split / /, $Connect)[1],
- });
- },
- irc_001 => sub {
- $irc->yield(mode => $BotNick." +B");
- $irc->yield(privmsg => "Nickserv" => "id ".$BotPass);
- my $alarm_id = $irc->delay( [ join => $BotChannels ], 2 );
- },
- irc_error => sub {
- my ($kernel, $IRCWhat) = @_[KERNEL, ARG0];
- print $IRCWhat."\n";
- },
- irc_ctcp_action => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."$IRCWhere > * ".(split /!/, $IRCWho)[0]." $IRCWhat\n";
- Bot("ACTION",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_join => sub {
- my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
- print GetTime()."Join * ".(split /!/, $IRCWho)[0]." joins $IRCWhere\n";
- Bot("JOIN",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
- },
- irc_invite => sub {
- my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
- print GetTime()."Invi * ".(split /!/, $IRCWho)[0]." invites you to $IRCWhere\n";
- Bot("INVITE", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
- },
- irc_kick => sub {
- my ($kernel, $IRCWho, $IRCWhere, $IRCWhoElse, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
- print GetTime()."Kick * ".(split /!/, $IRCWho)[0]." kicks $IRCWhoElse out of $IRCWhere ($IRCWhat)\n";
- Bot("KICK",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhoElse,$IRCWhat);
- },
- irc_msg => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."Priv\a> <".(split /!/, $IRCWho)[0]."> $IRCWhat\n";
- Bot("PRIVMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_nick => sub {
- my ($kernel, $IRCWho, $IRCWhoElse) = @_[KERNEL, ARG0, ARG1];
- print GetTime()."Nick * ".(split /!/, $IRCWho)[0]." changes nick to $IRCWhoElse\n";
- Bot("NICK", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhoElse);
- },
- irc_notice => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."Noti <".(split /!/, $IRCWho)[0]."> $IRCWhat\n" if((split /!/, $IRCWho)[0] !~ /WolfBot/i);
- Bot("NOTICE",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_part => sub {
- my ($kernel, $IRCWho, $IRCWhere, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- print GetTime()."Part * ".(split /!/, $IRCWho)[0]." left channel $IRCWhere \(".$IRCWhat."\)\n";
- Bot("PART",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_public => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."$IRCWhere > <".(split /!/, $IRCWho)[0]."> $IRCWhat\n";
- Bot("CHANMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_disconnected => sub { print "Disconnected.\n"; exit 1; }, # Ends on disconnect.
- },);
- sub Bot {
- $Event = $_[0];
- if($Event =~ /CHANMSG/) { $Com = "privmsg ".$_[3]." "; $UserMsg = $_[4]; $Where = $_[3]; }
- elsif($Event =~ /NOTICE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
- elsif($Event =~ /PRIVMSG/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
- 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.
- elsif($Event =~ /JOIN/) { $Com = "notice ".$_[3]." "; $UserMsg = $_[3]; $Where = $_[1]; }
- elsif($Event =~ /NICK/) { if($_[1] =~ /^$BotOwner$/i) { print "Owner changing...\n"; $BotOwner = Regexit($_[3]) } }
- $UserNick = Regexit($_[1]);
- $UserHost = $_[2];
- $UserMsg = POE::Component::IRC::Common::strip_formatting(POE::Component::IRC::Common::strip_color($UserMsg));
- $CurSec = SpamProtect();
- &CREATEUser($UserNick);
- if($DBUsers =~ /(.*)<$UserNick :(.*?)\[Access (.*?)\](.*?)>(.*)/i) {
- $Access = $3;
- if($Access <= 0) {
- return 0;
- }
- }
- if(($Where =~ /wwolf/i) || ($UserNick =~ /Wolfbot/i)) {
- if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
- if(($UserMsg =~ /^($BotNick|Bots), Join/i) && ($WW{"Will Join"} !~ /No/i)) {
- $irc->yield(privmsg => "#WWolf" => "!Join");
- $WW{"Will Join"} = "No";
- $WW{"MyType"} = "Villager";
- }
- elsif(($UserMsg =~ /^$BotNick, Leave/i) && ($WW{"Will Join"} =~ /No/i)) {
- $irc->yield(part => "#WWolf" => "Invite me, and I will continue playing.");
- $WW{"Will Join"} = "Yes";
- }
- elsif($UserMsg =~ /^$BotNick won,/i) {
- my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => "Woohoo! I won. :D" ], 1 );
- while ( ($key, $value) = each %WW ) {
- $WW{$key} = "";
- }
- }
- elsif($UserMsg =~ /^$BotNick lost,/i) {
- my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => ";~; I didn't think I'd lose..." ], 1 );
- while ( ($key, $value) = each %WW ) {
- $WW{$key} = "";
- }
- }
- elsif($UserMsg =~ /^The game is over\.$/i) {
- while ( ($key, $value) = each %WW ) {
- $WW{$key} = "";
- }
- }
- elsif($UserMsg =~ /^($BotNick|Bots), what are you/i) {
- if($WW{"MyType"} =~ /Wolf|Village Idiot/) {
- $irc->yield(privmsg => "#WWolf" => "I am a Villager.");
- }
- else {
- $irc->yield(privmsg => "#WWolf" => "I am a ".$WW{"MyType"}.".");
- }
- }
- elsif($UserMsg =~ /(.*?) (has joined|has started)/i) {
- if($1 =~ /$BotNick/) { return 0; }
- $WW{"Players"} = $WW{"Players"}.$1." ";
- @WWPlayers = split / /, $WW{"Players"};
- print "Updating players...\n".@WWPlayers."\n";
- }
- elsif($UserMsg =~ /^(.*) (has left the game|struggles vainly|was)/i) {
- $WW{"Players"} =~ s/$1 //igs;
- @WWPlayers = split / /, $WW{"Players"};
- print "Updating players...\n".@WWPlayers."\n";
- }
- elsif($UserMsg =~ /seconds to send your votes/i) {
- if($WW{"Vote"} =~ /^$/) {
- my $alarm_id = $irc->delay( [ privmsg => "WolfBot" => "vote ".$WWPlayers[int(rand(@WWPlayers))] ], 5 );
- print $WWPlayers[int(rand(@WWPlayers))];
- }
- else {
- my $alarm_id = $irc->delay( [ privmsg => "WolfBot" => "vote ".$WW{"Vote"} ], 5 );
- }
- $WW{"Vote"} = "";
- if($WW{"MyType"} =~ /Village Idiot/i) {
- $WW{"Vote"} = $BotNick;
- }
- }
- if(($UserNick =~ /WolfBot/i) && ($Event =~ /(NOTICE|PRIVMSG|CHANMSG)/)) {
- if($UserMsg =~ /You are a wolf!/i) {
- $WW{"MyType"} = "Wolf";
- print "Wolf!";
- }
- elsif($UserMsg =~ /You are the finder!/i) {
- $WW{"MyType"} = "Finder";
- }
- elsif($UserMsg =~ /You are the seer!/i) {
- $WW{"MyType"} = "Seer";
- }
- elsif($UserMsg =~ /You are the doppleganger!/i) {
- $WW{"MyType"} = "Doppleganger";
- }
- elsif($UserMsg =~ /You are the angel!/i) {
- $WW{"MyType"} = "Angel";
- }
- elsif($UserMsg =~ /You are the Village Idiot!/i) {
- $WW{"MyType"} = "Village Idiot";
- my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $WWPlayers[int(rand(@WWPlayers))]." is Wolf." ], 50 );
- $WW{"Vote"} = $BotNick;
- }
- elsif($UserMsg =~ /into (a|an) (.*?)!/i) {
- $tring = $2;
- if($tring =~ /werewolf/i) { $WW{"MyType"} = "Wolf"; }
- else {
- $WW{"MyType"} = $tring;
- }
- }
- elsif($UserMsg =~ /You have 45/i) {
- if($WW{"MyType"} =~ /Wolf/i) {
- $irc->yield(privmsg => "wolfbot" => "kill ".$WWPlayers[int(rand(@WWPlayers))]);
- }
- elsif($WW{"MyType"} =~ /Seer/i) {
- foreach (@WWPlayers) {
- if($WW{"Targeted"} !~ /Regexit($_)/i){
- $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
- $WW{"Target"} = $_;
- last;
- }
- }
- $irc->yield(privmsg => "wolfbot" => "see ".$WW{"Target"});
- }
- elsif($WW{"MyType"} =~ /Finder/i) {
- foreach (@WWPlayers) {
- if($WW{"Targeted"} !~ /Regexit($_)/i){
- $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
- $WW{"Target"} = $_;
- last;
- }
- }
- $irc->yield(privmsg => "wolfbot" => "find ".$WW{"Target"});
- }
- if($WW{"MyType"} =~ /Doppleganger/i) {
- $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
- $irc->yield(privmsg => "wolfbot" => "dopple ".$WW{"Target"});
- }
- if($WW{"MyType"} =~ /Angel/i) {
- $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
- $irc->yield(privmsg => "wolfbot" => "shield ".$WW{"Target"});
- }
- }
- elsif($UserMsg =~ /(.*?) is (a|an) (.*?)!/i) {
- $tring = $1;
- $tringt = $3;
- if($tringt =~ /(Wolf|Village Idiot)/i) {
- my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is ".$1."." ], 5 );
- $WW{"Vote"} = $tring if($tringt !~ /Village Idiot/);
- }
- elsif($tringt =~ /Angel/i) {
- 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 );
- }
- elsif($tringt =~ /Doppleganger/i) {
- my $alarm_id = $irc->delay( [ privmsg => $tring => "Dopple me for seer!" ], 2 );
- }
- }
- elsif($UserMsg =~ /(.*?) targetted (.*?)!/i) {
- $tring = $1;
- $tringt = $3;
- my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." targetted ".$tringt."." ], 5 );
- $WW{"Vote"} = $tring;
- }
- elsif($UserMsg =~ /The (wolves|other wolves) are: (.*)/i) {
- @WWolfs = split /, /, $1;
- print "Updating players...\n";
- foreach (@WWolfs) {
- $WW{"Players"} =~ s/$_ //gs;
- @WWPlayers = split / /, $WW{"Players"};
- print "Updating players...\n".@WWPlayers."\n";
- }
- }
- }
- }
- }
- if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
- ($tring = $UserMsg) =~ s/-|\[|\]|\{|\}|\(|\)|\*|\.|\?|\!//igs;
- $Prefix = "\`";
- if($UserMsg !~ /^$Prefix/i) { return 0; }
- $UserMsg =~ s/^$Prefix//gs;
- #&Op($UserNick,$UserHost,$tring,$Where);
- #####################
- # Owner commands #
- #####################
- if(($UserMsg =~ /^End$/i) && ($UserNick =~ /^$BotOwner$/i)) {
- $irc->yield(quit => POE::Component::IRC::Common::MAGENTA."~ Goodbye ~");
- }
- elsif($_[4] =~ /^Do (.*?) (.*?) (.*)/i) {
- @Temp = ($1,$2,$3);
- if($UserNick =~ /^$BotOwner$/i) {
- $irc->yield($Temp[0] => $Temp[1] => $Temp[2]);
- }
- }
- elsif($UserMsg =~ /^Nick (.*)/i) {
- $tring = $1;
- if($UserNick =~ /^$BotOwner$/i) {
- $BotNick = $tring;
- $irc->yield(nick => $tring);
- }
- }
- elsif($UserMsg =~ /^Amsg (.*)/i) {
- $tring = $1;
- if($UserNick =~ /^$BotOwner$/i) {
- $irc->yield(privmsg => $BotChannels => $tring);
- }
- }
- #####################
- #Important Commands #
- #####################
- elsif($UserMsg =~ /^(Help|Commands)$/i) {
- Command($Com."Totally updated by Caaz");
- }
- elsif($UserMsg =~ /^Reload$/i) {
- open DATA, "<".$BotPath."DBUsers.txt";
- @DB = <DATA>;
- chomp($DBUsers = $DB[0]);
- close DATA;
- }
- elsif($UserMsg =~ /^AJ$/i) {
- open DATA, "<".$BotPath.(split / /, $Connect)[0].(split / /, $Connect)[1]."-AutoJoin.txt";
- @Channels=<DATA>;
- close DATA;
- if($Channels[0] !~ /$Where,/i) {
- open DATA, ">>".$BotPath.(split / /, $Connect)[0].(split / /, $Connect)[1]."-AutoJoin.txt"; print DATA "$Where,"; close DATA;
- Command($Com."Channel added to AutoJoin.");
- }
- else {
- Command($Com."Channel already in AutoJoin.");
- }
- }
- elsif($UserMsg =~ /^Alert$/i) {
- print "\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\n";
- }
- #####################
- # Random Commands #
- #####################
- elsif($UserMsg =~ /^Catch$/i) {
- if($CurSec >= $Lag{$Where."-Poke"}) {
- $PokeD--;
- if($UserNick !~ /$PokeE/i) { $PokeD = 0; }
- $PokeE = $UserNick;
- open DATA, "<".$Path."\\Counters\\".$UserNick." - poke.txt";
- @Count=<DATA>;
- close DATA;
- chomp($PokeB = $Count[0]);
- open DATA, "<".$Path."pokelist.txt";
- @Poke=<DATA>;
- $RandNum = int(rand($.));
- close DATA; chomp(@Poke);
- $PokeA = "got away..";
- if((int(rand(100)) - ($PokeD * 3)) > 50) {
- $PokeA = "was caught! $UserNick now has ".($PokeB + 1)." Pokemon";
- $PokeB++;
- open DATA, ">".$Path."\\Counters\\".$UserNick." - poke.txt";
- print DATA $PokeB;
- close DATA;
- $PokeType = int(rand(120));
- if($PokeType > 90) { $PokeC = "Shiny "; }
- if($PokeType > 105) { $PokeC = "Shadow "; }
- if($PokeType > 100) { $PokeC = "Hentai "; }
- $irc->yield($Command => $Where => "A wild ".$PokeC.$Poke[$RandNum]." Appeared! $UserNick threw a Pokeball...".$Poke[$RandNum]." ".$PokeA);
- $Lag{$Where."-Poke"} = $CurSec + 2.5;
- $PokeC = "";
- }
- }
- }
- elsif($UserMsg =~ /^Add (.*)/i) {
- open DATA, ">>".$Path."pokelist.txt";
- print DATA $1.$2."\n";
- close DATA;
- $irc->yield($Command => $Where => "Added $1$2 to Pokemon list,");
- }
- elsif($UserMsg =~ /^Catch off/i) {
- $irc->yield($Command => $Where => "Catch is now off in this channel. Ask an admin of this bot for it to be turned back on.");
- $Lag{ $Where."-Poke" } = $CurSec + 90000000001;
- }
- elsif(($UserMsg =~ /^Catch on/i) && ($Access >= 10)) {
- $irc->yield($Command => $Where => "Catch is now on in this channel. ");
- $Lag{$Where."-Poke"} = $CurSec;
- }
- #####################
- # END #
- #####################
- }
- }
- sub Regexit {
- ($Reg = $_[0]) =~ s/\\/\\\\/gs;
- $Reg =~ s/(\?|\(|\)|\||\[|\|\{|\}|\.)/\\$1/gs;
- $Reg =~ s/\*/\(\.\*\)/gs;
- return $Reg;
- }
- sub CREATEUser {
- if($DBUsers !~ /(.*)<$_[0] :(.*?)>(.*)/i) {
- open DATA, ">>".$BotPath."DBUsers.txt";
- print DATA "<".$_[0]." : \\\[Access 1\\\] >";
- close DATA;
- open DATA, "<".$BotPath."DBUsers.txt";
- @DB = <DATA>;
- chomp($DBUsers = $DB[0]);
- close DATA;
- }
- }
- sub SpamProtect {
- my($Sec, $Min, $Hour, $Day, $mon, $year, $WDay, $YDay) = localtime;
- return (((($YDay * 24) * 60) * 60) + (($Hour * 60) * 60) + ($Min * 60) + $Sec);
- }
- sub Command {
- $PrivmsgA = $_[0];
- @PrivmsgB = split / /, $PrivmsgA;
- $ComA = shift(@PrivmsgB);
- $ComB = shift(@PrivmsgB);
- if($BotNick =~ /Luka/i) { $BotFont = "〜"; $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(join " ", @PrivmsgB)." 〜"); }
- if($BotNick =~ /(Rin|Ren)/i) { $BotFont = "〜"; $irc->yield($ComA => $ComB => POE::Component::IRC::Common::ORANGE.(join " ", @PrivmsgB)." ☯"); }
- elsif($BotNick =~ /Pichu/i) { $BotFont = "⚡"; $irc->yield($ComA => $ComB => POE::Component::IRC::Common::ORANGE.(join " ", @PrivmsgB)." ⚡"); }
- elsif($BotNick =~ /Akul/i) { $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(reverse(join " ", @PrivmsgB))." 〜"); }
- }
- sub GetTime { # This is just for timestamps, just leave it.
- my($Sec, $Min, $Hour, $Day, $Mon, $Year, $WDay, $YDay) = localtime;
- 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 "[ $Hour:$Min:$Sec $APM ] ";
- }
- # Caaz was here. Again.
- $poe_kernel->run();
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement