Previous Section  < Day Day Up >  Next Section

Hack 24 Enhance irssi with Perl

figs/moderate.gif figs/hack24.gif

irssi is a popular IRC client. Enhance it with Perl scripts you write yourself or select from the large range available on the Web.

irssi is a client with a very nice Perl scripting interface. You don't have to be a Perl programmer to enjoy this fact, as many scripts are already available. In fact, it's hard to find original ideas for new scripts, because everything seems to exist already!

Here we'll demonstrate some interesting scripts that let you see what films people are watching, find out what their real names are, obfuscate text, and so on. All of these scripts (and more) are available for download at Before you start downloading lots of scripts, now would be a good time to explain how to use them.

4.9.1 Using an irssi Script

There are two ways to do this. First, of course, you have to download a script. Save it anywhere you want. To try the script, use the /script load command. Then do whatever you want to see how the script works for you. If it doesn't seem to work, don't forget to read the documentation that accompanies the script to see if you have to change any settings to make it work.

If you like the script, just copy it to the .irssi/scripts/autorun directory in your home directory. Next time you start irssi, the script will be loaded. Of course, if you don't like the script, you can unload it using the /script unload command. Remember that the unload command doesn't accept complete paths to files. Just the filename is enough.

For example, if you have downloaded the script and saved it in your home directory, this is how you would load and unload it:

> /script load /home/wilmer/

-!- Irssi: Loaded script imdb

> /script unload imdb

-!- Irssi: Unloaded script imdb

If the /script command doesn't seem to work, you may need to recompile irssi with Perl scripting support, or you may need to manually load the Perl module using the /load perl command. If you still can't get it working, please read the irssi-building documentation for more information.

Now you can take a look at some scripts of interest and some useful hints.

4.9.2 See What Film Everyone's Watching

You may have heard of the Internet Movie DataBase at While using IRC, you may also have noticed people with seven-digit numbers after their nickname. Usually, this number corresponds to a film on IMDB. Of course, you can look up the film on IMDB when the user puts it in her nick—but why do that if a script can do it for you?

The script is called and can be found at When you load it and someone changes his nick to something with an IMDB number in it, it looks up the name of the film and tells you what it is. Here's an example of it in use:

<pengu> i'm going to watch a movie

-!- pengu is now known as tux|0208092

-!- pengu is watching Snatch. (2000)

Certainly more informative than just a number.

4.9.3 Who's Behind That Nick?

Another script you may like is ( When someone joins a channel, it gets the person's "real name" from the server and puts it in the join message. It looks like this:

-!- AxE (Alex Bylund) [] has joined #bitlbee

4.9.4 Strange Dialects

You may have seen some people talk like this on IRC:

<Pink> PpfPpmMfm, fmpmfpmppffm pmpmffpmfpmfmppmpm pmpmppppppppffm!

There are a lot of strange people on IRC, so it's quite easy to dismiss such a message. It may seem unlikely to you, but this really means something! To find out what it means, you can load the plug-in ( It decodes these lines automatically, and it even allows you to write like this, using the /kenny command. When you have the kenny script loaded, the previous line will be rendered like this:

[kenny] <Pink> OMG, they killed kenny!

This is certainly not the most useful script ever, but still it's fun to play with for a while. Some other encodings you can try are,,,, and, all available directly from

4.9.5 Automatically Get Ops When the Channel Is Empty

There is a script called (, which is useful for regaining operator status if you have lost it. When you're in an unregistered channel and don't have operator status, this script automatically parts and immediately rejoins the channel after the last person has left. This usually makes you the new channel owner and gives you operator status for that channel.

4.9.6 Keep Everyone Amused When You're Away

Another amusing script is ( When you're away and people send you a private message, this script generates a reply and sends it back. Although it's not hard for people to find out that they're talking to a bot, it's still good for some very funny conversations.

You can find some very nice Eliza conversations here:

4.9.7 What Was That Query About Again?

Sometimes you close a query window because you don't expect a reaction any more, only to find that the person sends a reply a few seconds later. Being a busy person, you don't have the slightest idea what it was about any more. The script ( provides a useful solution. If you have logging enabled, it puts the last lines from the log file in the query window when it opens—usually enough to understand what the person is talking about.

For example, without QueryResume, you might not have any idea what this "wheeee" was referring to:

22:16:35 ,--[QueryResume]

22:16:35 | 21:35      pengu| yeah :)

22:16:35 | 21:36      pengu| so now i'm a groupie?

22:16:35 | 21:36      pengu| ;p

22:16:35 | 21:36     wilmer| *grin*

22:16:35 | 21:36     wilmer| yes, you're the first

22:16:35 `--<~/.irssi/irclogs/FLUT/pengu.log>->

22:16:35     -!-     Irssi: Starting query in FLUT with pengu

22:16:35      pengu| wheeee

By default, QueryResume gives you the last 10 lines from the logs. If you want more (or fewer) lines, you can change the number using the queryresume_lines setting. For example, to get just five lines, type /set queryresume_lines 5.

4.9.8 Other Interesting Scripts

Many more scripts are available—enough to write another book about. If you haven't found what you're looking for yet, just look at the list on the irssi web site at Likely, someone has already written what you're looking for. If not, maybe it's time to write a script yourself. Unfortunately, there is little documentation about writing irssi scripts, so you'll just have to look at other examples to see how things are done.

4.9.9 The Code

Following is a small example script. It makes a person believe she is in your ignore list, which can help to kill some boring discussions from time to time:

#!/usr/bin/perl -w

use strict;

use vars qw($VERSION %IRSSI);

# This file is partially based on

$VERSION = "1";

%IRSSI = (

    authors     => 'Wilmer van der Gaast',

    contact     => '',

    name        => 'Fake-Ignore',

    license     => 'GNU GPLv2 or later',


use Irssi;

use Irssi::Irc;

sub fignore {

        my ($text, $server, $dest) = @_;

        if (!$server || !$server->{connected}) {

                Irssi::print("Not connected to server");



        return unless $dest;

        if ($dest->{type} eq "CHANNEL" || $dest->{type} eq "QUERY") {

                $text = `date +%H:%M:%S` . ' Ignoring ALL from ' . $text;

                $text =~ s/[\n\r ]+/ /gs;

                $dest->command("/msg " . $dest->{name} . " " . $text );



Irssi::command_bind( "fignore", "fignore" );

The %IRSSI hash is used to define some information about the module. This is usually the best place to put the information about your module, such as who wrote it and how he can be contacted. The module defines a couple of subs and, in the end, those subs are linked to either irssi commands or events. This example script is tied to a client command, so if you were to type /fignore nickname, the target user would see a message suggesting that she is being ignored by your client. If you want to know more about event-based scripts, you can take one of the many other scripts as an example. Here is the result from running this script:

/fignore brannigan

23:51:29 Ignoring ALL from brannigan

Wilmer van der Gaast

    Previous Section  < Day Day Up >  Next Section