LogoPhly, boy, phly
the weblog and site of Matthew Weier O'Phinney

Wednesday, December 10. 2008

Mumbles irssi integration

I've been using IRC regularly for the past six to nine months, in large part due to the growing ZF community on the Freenode #zftalk channel (unfortunately, I simply don't have time to be in that particular channel any more, but you can generally find me in #zftalk.dev), but also to keep in contact with other peers, friends, and colleagues.

One difficulty, however, is keeping productivity high while staying on IRC. To me, the ultimate client would provide me notifications when somebody mentions my name or a watch word - allowing me to read the channel at my leisure, yet still respond to people in a timely fashion.

I've tried a variety of IRC clients over the months, starting with Pidgin (poor interface for IRC), mirc (huge difficulties figuring out the UI), xchat (not bad, but seemed a bit heavy), Chatzilla (I liked the interface, but once you got many tabs going, it was unwieldy switching around between them; I also hated that Firefox dying or restarting caused Chatzilla to do likewise), and now irssi.

So far, irssi is the best I've tried -- I can run it in screen, allowing me to keep it open as long as my machine is running. The interface is reasonable, and cleanly keeps channels separate from private messages. Opening, closing, and manipulating windows is easy. And it's highly scriptable... including in a language I actually use! The perl bindings are top notch, though sometimes cryptic. What's important, however, is that there are plenty of examples out there if you want to try doing something. So, I figured I'd write up a quick plugin to trigger notifications.

I've been using a number of different notification servers for linux, and personally like both gnotify and mumbles. Both are very lightweight and offer network protocols for triggering notifications.

I first tried using gnotify. It has a very, very simple TCP protocol, and I've had success creating messages from the shell, PHP, and perl. Unfortunately, for some reason, using it in irssi displayed some odd behavior: I'd lose the cursor and the ability to enter input from the time a notification triggered until it completed (i.e., the notification disappeared). Forking the process did not appear to help.

So, I decided to try out mumbles. Mumbles is written in python, and has themeable notifications -- already a plus. It runs via dbus by default, but can also optionally spawn a server that implements the Growl protocol -- making it accessible for any process to send notifications. Additionally, it has a command-line utility for triggering notifications -- by default over dbus, but optionally by contacting the growl server, if running.

Growl's protocol is a bit involved, and I didn't want to spend too much time on this. So, I did a quick, dirty hack: I used backticks to trigger the CLI utility. And it works fantastically -- no delays whatsoever. Here's the code:


# $HOME/.irssi/scripts/mumbles.pl
use strict;
use Irssi;
use Irssi::Irc;
use vars qw($VERSION %IRSSI);

$VERSION = '0.1.0';
%IRSSI = (
    authors     => "Matthew Weier O'Phinney",
    contact     => 'matthew@weierophinney.net',
    name        => 'Mumbles notifications for irssi',
    description => 'This script enables mumbles notifications for irssi',
    license     => 'New BSD',
        changed     => "2008-12-10"
);


sub mumbles_sig_printtext {
  my ($dest, $text, $stripped) = @_;

  if (($dest->{level} & (MSGLEVEL_HILIGHT|MSGLEVEL_MSGS)) && ($dest->{level} & MSGLEVEL_NOHILIGHT) == 0)
  {
    if ($dest->{level} & MSGLEVEL_PUBLIC)
    {
      mumbles($dest->{target} . " : " . $text);
    }
  }
}

sub mumbles {
    my $message = shift;
    my $response;

    $message =~ s/[^!-~\s]//g;

    `/usr/bin/mumbles-send -g 127.0.0.1 -s "IRC" "$message"`;
}

Irssi::command_bind 'mumbles' => sub {
    my ($message) = @_;
    mumbles($message);
};

Irssi::signal_add({
  'print text'    => \&mumbles_sig_printtext
});
 

This triggers a notification for any "highlight" event -- basically, anytime anybody "says" my name in a channel, or mentions a keyword I've marked for highlighting. Additionally, I created a "mumbles" command so that I can send test messages (usage: "/mumbles "this is the message..."). You could certainly bind to other events, such as topic changes, joins, parts, etc -- I'm only interested in highlight events.

You may note the regexp in there. One thing I discovered was that most messages contained control and non-ascii characters that often resulted in unreadable notifications, as well as some nasty messages reported by irssi. The regexp removes anything not in the ascii character set or the set of whitespace definitions prior to emitting the notification.

Something else I needed to do was configure compiz to ensure that the notifications actually popped above my windows. I did this by going into the compiz configuration manager, selecting "General Options", selecting the "Focus & Raise Behaviour" tab, and modifying the "Focus Prevention Windows" to read as follows:

(any) & !(class=Mumbles)

To test it, I placed the script in $HOME/.irssi/scripts/mumbles.pl, and then, in irssi, executed "/load mumbles.pl".

Once I had it to my liking, I symlinked it into my $HOME/.irssi/scripts/autorun/ directory, allowing it to run as soon as irssi loads. I can now have irssi running in a screen session, or minimize the terminal, and get notifications -- keeping me productive and informed at the same time.

UPDATED 2008-12-12: Added information on how to load the script, as well as fixed the location to the autorun directory. Thanks, @sidhighwind!

Posted by Matthew Weier O'Phinney in Perl, Programming at 15:01 | Comments (5) | Trackbacks (0)
Defined tags for this entry: irc, perl, programming
Related entries by tags:
Vimgrep and Vim Project
git-svn Tip: don't use core.autocrlf
Server Upgrades... lost entries...
Submitting Bug Reports
Backwards Compatibility

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

I use IRC in the same way and get Colloquy to notify me if a keyword that I've set up is mentioned.

I'd never get anything done otherwise :-)

Rob...
#1 Rob... (Link) on 2008-12-10 16:00 (Reply)
Heh. Again, Colloquy and Growl for the win -- I've been using this combination (since colloquy lets you put custom 'highlight' words in using just the configuration) for over a year now.
#2 Karl Katzke (Link) on 2008-12-10 16:50 (Reply)
Well, Colloquy isn't an option for me -- I'm not on a Mac. :-) irssi provides the custom highlight words as well, and has the added bonus of being able to run in a terminal -- which means I can put it in a screen session and detach it when I log out. (I hope to setup a server soon so I can have an irssi proxy, which would give me even *more* options!)
#2.1 Matthew Weier O'Phinney (Link) on 2008-12-10 20:20 (Reply)
The trick with IRC is just being able to ignore it. I often follow conversations even though it's not really something I'd need to do.

Your approach to notifications seems a bit complex though. I don't know exactly why you're doing it this way, but for me the bell functionality in irssi and screen are enough. I've set it up so that I get an audible ding sound when I get a highlight or a PM, which works fine.
#3 Jani Hartikainen (Link) on 2008-12-11 03:25 (Reply)
It's actually not a very complex setup -- I already have a notification daemon running, so I'm simply piping events to it.

The big win for me with having them is that I can see who they are from and what was said -- which allows me to decide whether or not I need to respond or if I can continue ignoring it. Using the visual bell (or an audible one) does not give me that kind of feedback.
#3.1 Matthew Weier O'Phinney (Link) on 2008-12-11 07:48 (Reply)

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
  • Home
  • Resume
  • Blog
  • Phly PEAR Channel
  • Twitter
  • Contact Me
  • About this site

ZCE

Zend Education Advisory Board Member

Add to Technorati Favorites

Calendar

Back September '10
Mon Tue Wed Thu Fri Sat Sun
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      

Quicksearch

Links

  • PHLY - PHp LibrarY
  • Planet PHP
  • Zend Framework, where I'm project lead
  • Sebastian Bergmann
  • Cal Evans
  • Shahar Evron
  • Paul M. Jones
  • Bill Karwin
  • Mike Naberezny
  • Fabien Potencier
  • Ben Ramsey
  • Derick Rethans
  • Ralph Schindler
  • Marco Tabini

Archives

September 2010
August 2010
July 2010
Recent...
Older...

Categories

XML Linux
XML Personal
XML Aikido
XML Family
XML Programming
XML Dojo
XML Perl
XML PHP

All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Show tagged entries

xml apache
xml best practices
xml books
xml conferences
xml cw09
xml decorators
xml dojo
xml dpc08
xml file_fortune
xml git
xml linux
xml mvc
xml oop
xml pear
xml perl
xml personal
xml php
xml phpworks08
xml programming
xml rest
xml ubuntu
xml vim
xml webinar
xml zendcon
xml zendcon08
xml zendcon09
xml zend framework
© 2004 - present, Matthew Weier O'Phinney
matthew-web <at> weierophinney.net