Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- print "Werewolf autoplay by Caaz.\n";
- use POE::Component::IRC;
- use POE;
- BOTVARS: {
- $BotNick = "Ookami"; # Nick
- $BotUser = "."; # Username "indent"
- $BotName = "a Perl bot. Werewolf Autoplay 0.3"; # Real Name
- $BotPass = "PASSWIRD"; # Nickserv Password
- }
- my ($irc) = POE::Component::IRC->spawn();
- POE::Session->create(inline_states => {
- _start => sub {
- $irc->yield(register => "all");
- $irc->yield( connect => {
- Nick => $BotNick,
- Username => $BotUser,
- Ircname => $BotName,
- Server => "irc.purplesurge.com",
- Port => "6667",
- });
- },
- irc_001 => sub {
- $irc->yield(mode => $BotNick." +B");
- $irc->yield(privmsg => "Nickserv" => "id ".$BotPass);
- my $alarm_id = $irc->delay( [ join => "#Powerplant,#WWolf" ], 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";
- 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]; }
- $UserNick = Regexit($_[1]);
- $UserHost = $_[2];
- $UserMsg = POE::Component::IRC::Common::strip_formatting(POE::Component::IRC::Common::strip_color($UserMsg));
- if(($Where =~ /wwolf/i) || ($UserNick =~ /Wolfbot/i)) {
- if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
- if(($UserMsg =~ /^$BotNick, 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, 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($UerMsg =~ /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 =~ /You transform 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";
- }
- }
- }
- }
- }
- }
- sub Regexit {
- ($Reg = $_[0]) =~ s/\\/\\\\/gs;
- $Reg =~ s/(\?|\(|\)|\||\[|\|\{|\}|\.)/\\$1/gs;
- $Reg =~ s/\*/\(\.\*\)/gs;
- return $Reg;
- }
- 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