Irssi+POE script goodness

BinGOs on 2006-10-05T10:19:17

A while ago Martijn van Beers introduced me to the idea of running POE inside Irssi IRC client.

Now this sounded like a really cool idea to me.

I had Irssi installed already with Perl support and POE (of course), so it was a case of installing POE::Loop::Glib.

use Irssi;
use Irssi::Irc;
use Glib;

my $win = Irssi::active_win();
$win->print ('DEPTH ' . Glib::main_depth);

use POE qw(Loop::Glib);

$VERSION = "0.2";
%IRSSI = (
    authors     => 'Martijn van Beers',
    contact     => 'martijn[at]eekeek.org',
    name        => 'memephage',
    description => 'send urls to proximity store',
    license     => 'GPL',
    url         => 'http://example.com',
);


POE::Session->create (
        inline_states => {
                _start => sub {
                        my $kernel = $_[KERNEL];
                        $kernel->delay_add ('foo', 4);
                },
                foo => sub {
                        my $kernel = $_[KERNEL];
                        my $w = Irssi::active_win();
                        $w->print ('POE FOO');
                },
                _stop => sub {
                        my $w = Irssi::active_win();
                        $w->print ('POE STOP');
                },
        },
);

1;

Martijn provided me with the above script (which I have amended slightly) for testing that Irssi and POE were now best of buddies. Save it to ~/.irssi/scripts as poetest.pl and in Irssi use the command /SCRIPT LOAD poetest.pl. 'POE FOO' should be written to the active window after 4 seconds, then 'POE STOP'. Very nice. But not that useful.

So a more useful application was a script for managing individuals on Freenode #perl channel, the code for which is here.

Some caveats are:

  • There is no need to explicitly run the POE::Kernel
  • Using /SCRIPT UNLOAD does not stop the session
  • Sessions created in different scripts can communicate with each other using normal POE semantics.

Many interesting things are bubbling through my mind about how to abuse this, I'll write some more as they occur to me >:o]