use strict; use constant PIRATEBIN => '/home/bass/bin/pirate'; use Irssi qw( print ); use IPC::Open2; use vars qw( %IRSSI $ACTIVE ); %IRSSI = ( name => 'talk like a pirate', authors => 'Ian Langworth', ); $ACTIVE = 0; # have the /pirate command toggle the pirate mode and # announce it to the current channel Irssi::command_bind( pirate => sub { $ACTIVE = not $ACTIVE; print MSGS $ACTIVE ? '%r(pirate activated)%n' : '%g(pirate deactivated)%n' ; }); # callback for sending messages -- the MEAT! Irssi::signal_add_first( 'send text' => sub { my ($msg, $server, $witem) = @_; # tests and stuff stolen from dau.pl return unless (defined($server) && $server && $server->{connected}); return unless (defined($witem) && $witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')); # are we in mode? if ( $ACTIVE ) { # do the transformation -- from the Perl Cookbok, p.567 my $pid; eval { $pid = open2( *README, *WRITEME, PIRATEBIN ); }; if ( $@ ) { print CLIENTCRAP "open2 error: $@"; return } print WRITEME "$msg\n"; close WRITEME; $msg = ; close README; waitpid $pid, 0; chomp $msg; # print it foreach my $line (split /\n/, $msg) { $witem->command("MSG $witem->{name} $line"); } # don't let irssi print it Irssi::signal_stop(); } }); # success messages print CRAP '%r*%n'; print CRAP '%r*%n pirate loaded. type /pirate to toggle.'; print CRAP '%r*%n';