I use IRC every day. I like it ok. It’s a nice way to stay in contact with friends and other folks in the IT world. There is idle chatter for sure, but it’s also a nice way to aggregate knowledge. Lots of smart people in a channel with different specialties is good for everyone in the channel. You can trade ideas, ask questions, answer questions, get a second (or more) set of eyes on a solution you like…etc. So naturally there is a need for an IRC client. I use Irssi, and have for some time.
Geeks love to argue, it’s what we do. We can make more out of the mundane than any other group. Of course this leads to arguments as to which IRC client is superior and why.
One thing I like about Irssi is that it’s scriptable in Perl. Never mind the fact that I have never actually written a script for Irssi, it’s something I point to when defending my position that it’s superior.
I decided I needed to finally take a look at the scripting for Irssi. What a pain. The documentation is typical for a small OSS project, as in…it sucks. After looking at gobs of scripts and reading tons of code I decided to look at CPAN to see if there was an easier way. Of course there was.
I found POE::Session::Irssi there. A couple of seconds later I was grabbing events and parsing them like a pro.
For those that may come here via google, here is a short and sweet code set to get you up and running:
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
use Glib;
use POE qw(Loop::Glib);
use POE::Session::Irssi;
sub foo {
my $args = $_[ARG1];
my ($server, $channel, $nick, $address) = @$args;
$server->command("MSG $channel Hello World!");
}
POE::Session::Irssi->create( irssi_signals => { 'message join' => \&foo, } );
Pretty straight forward. The ‘create’ method can look for signals or commands. You name the hash key for which event you wish to grep and then can either inline the sub, or as I have here a reference to a sub. From there it’s a matter of doing what you want to do with when that event is triggered.
In the above example, when someone joins a channel you are in, it prints ‘Hello World’ to the screen.
There were a couple of other things I have figured out while messing with this, that I will save for another post.