All pastes #881712 Raw Edit

Anonymous

public text v1 · immutable
#881712 ·published 2008-01-30 00:09 UTC
rendered paste body
use strict;
use vars qw($VERSION %IRSSI);
use FileHandle;
use IPC::Open2;

use Irssi;
$VERSION = '1.00';
%IRSSI = (
    authors     => 'sloow',
    contact     => 'sloow@sloow.org',
    name        => 'Experimental',
    license     => 'Public Domain',
);

my ($Reader, $Writer, $pid);
my $GameOn = 0;

# This sub will handle ALL incoming private messages
sub server_msgs {
  my ($server, $data2, $nick, $address) = @_;
  my ($target, $text) = split(/ :/, $data2, 2);

  if ( ($target =~ /^\#testing123$/) && ($nick =~ /^micro500$/i) )
  {
      my $answer;
      
      if ($text =~ /^Game has begun/)
      {
          $server->command("msg #testing123 Looks like the start of a game!");
          $GameOn = 1;
          $pid = open2(\*Reader, \*Writer, './solver');
          Writer->autoflush();
          $server->command("msg #testing123 Started solver pid = " .$pid);
          print Writer $text . "\n";
          chomp($answer = <$Reader>);
          print $answer;
          $server->command("msg #testing123 Bot says " . $answer);
      }
      elsif ($GameOn && ($text =~ /^The/ || $text =~ /^Digit/))
      {
          $server->command("msg #testing123 Looks like a clue!");
          print Writer $text . "\n";
          chomp($answer = <$Reader>);
          print $answer;
          $server->command("msg #testing123 Bot says " . $answer);
      }
      elsif ($GameOn && $text =~ /found the correct code/)
      {
          $server->command("msg #testing123 Looks like the game is over!");
          $GameOn = 0;
          close Writer;
          close Reader;
          waitpid($pid, 0)
      }
  }

}

Irssi::signal_add("event privmsg", "server_msgs");