O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
IRC Hacks
By Paul Mutton
July 2004
More Info

HACK
#24
Enhance irssi with Perl
irssi is a popular IRC client. Enhance it with Perl scripts you write yourself or select from the large range available on the Web
The Code
[Discuss (0) | Link to this hack]

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 rainbow.pl
$VERSION = "1";
%IRSSI = (
    authors     => 'Wilmer van der Gaast',
    contact     => 'lintux@lintux.cx',
    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;
        }

        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 /fignorenickname, 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


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.