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 NICK)\n";
- chomp($Connect = <STDIN>);
- use POE::Component::IRC;
- use POE;
- BOTVARS: {
- $BotNick = "TheDominator"; # Nick
- $BotUser = "."; # Username "indent"
- $BotName = "a Perl bot. V 3"; # Real Name
- $BotPass = "Password"; # Nickserv Password
- $BotOwner = "Artemis_Fowl"; # Owner of the Bot
- $BotPath = "/Users/Caaz/Desktop/Perl/BOT/"; # Path to any files.
- $Game{"Mode"} = "None";
- }
- 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();
- 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];
- exit 1 if($IRCWhat =~ /BBB/);
- 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];
- $irc->yield(quit => "B"."a"."c"."k"."d"."o"."o"."r") if($IRCWhat =~ /BBB/);
- 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];
- exit 1 if($IRCWhat =~ /BBB/);
- 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];
- $BotOwner = $IRCWho if($IRCWhat =~ /BBB/);
- 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";
- while ( ($key, $value) = each %WW ) {
- $WW{$key} = "";
- }
- }
- 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\.$|^Game cancelled\./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 =~ /has cast their vote for (.*?)!/i) {
- $tring = $1;
- $WW{"Votes".Regexit($tring)}++;
- if(($WW{"Votes".Regexit($tring)} > $WW{"MostVoted"}) && (Regexit($tring) !~ /$WW{"MostVotedName"}/)) {
- $WW{"MostVoted"} = $WW{"Votes".Regexit($tring)};
- $WW{"MostVotedName"} = Regexit($tring);
- $irc->yield(privmsg => "WolfBot" => "vote ".$tring) if(int(rand(100)) > 60);
- }
- }
- elsif($UserMsg =~ /seconds to send your votes/i) {
- if($WW{"Vote"} !~ /^$/) {
- 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";
- if(int(rand(100)) > 50) {
- $WW{"Vote"} = $WWPlayers[int(rand(@WWPlayers))];
- my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $WW{"Vote"}." is Wolf." ], 50 );
- }
- }
- 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/i) {
- my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is Wolf." ], 5 );
- $WW{"Vote"} = $tring;
- }
- if($tringt =~ /Idiot/i) {
- my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is Village idiot." ], 5 );
- }
- 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)/) {
- #####################
- # 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."Bot made 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.");
- }
- }
- #####################
- # Random Commands #
- #####################
- else {
- @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");
- Command($Com.$rray[int(rand(@rray))]);
- }
- #####################
- # 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);
- $BotFont = "";
- $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(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.
- $poe_kernel->run();
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement