weblog d’un abbe

20080615

irssi notifications

Filed under: Hacking — Tags: , , , , — abbe @ 0049

notify-irssi.pl
Following is the code of irssi plugin, which I hacked. It displays popup messages (using notification-daemon) for any IMs you received:

# irssi-notify.pl
use Irssi;
use Net::DBus;
 
$::VERSION='0.0.1';
%::IRSSI = (
    authors => 'Ashish Shukla',
    contact => 'gmail.com!wahjava',
    name => 'irssi-notify',
    description => 'Displays a pop-up message for message received',
    url => 'https://wahjava.wordpress.com/',
    license => 'GNU General Public License',
    changed => '$Date$'
    );
 
my $APPNAME = 'irssi';
 
my $bus = Net::DBus->session;
my $notifications = $bus->get_service('org.freedesktop.Notifications');
my $object = $notifications->get_object('/org/freedesktop/Notifications',
					'org.freedesktop.Notifications');
 
my $notify_nick = 'abbe';
 
# $object->Notify('appname', 0, 'info', 'Title', 'Message', [], { }, 3000);
 
sub pub_msg {
    my ($server,$msg,$nick,$address,$target) = @_;
 
    if ($msg =~ $notify_nick)
    {
	$object->Notify("${APPNAME}:${server}",
			0,
			'info',
			"Public Message in $target",
			"$nick: $msg",
			[], { }, 3000);
    }
}
 
sub priv_msg {
    my ($server,$msg,$nick,$address) = @_;
    $object->Notify("${APPNAME}:${server}",
		    0,
		    'info',
		    'Private Message',
		    "$nick: $msg",
		    [], { }, 3000);
}
 
sub cmd_notifyon {
    my $nick = shift;
 
    if(!$nick)
    {
	Irssi::print("Current notification nick is $notify_nick .");
    }
    else
    {
	$notify_nick = $nick;
    }
}
 
Irssi::signal_add_last('message public', \&pub_msg);
Irssi::signal_add_last('message private', \&priv_msg);
Irssi::command_bind('notify-on', \&cmd_notifyon);

To use it: copy, paste it into a file, say irssi-notify.pl in your $HOME. And then start irssi , and load plugin with command /script load ~/irssi-notify.pl and after that use /notify-on command to register your nick with this plugin, so it’ll popup messages with you nick mentioned. e.g. to register mikeab for notifications, I’ll do /notify-on mikeab. You’ll also need Net::DBus perl module. Happy irssi -ng…:)

P.S. BtW, there is another similar plugin also, which doesn’t require DBus, and it is available from http://codesnippets.joyent.com/posts/show/1394.

UPDATE: You can also download irssi-notify.pl.

Advertisements

9 Comments »

  1. Real programmers use irssi with bitlbee for all instant communications. Real programmers know when a new message is in without being notified. Real programmers… it goes on and on.

    Nice work! I should try irssi sometime.

    Comment by Edwin — 20080615 @ 0142

  2. s/i with b/i + ctrlproxy + b/

    :)

    Comment by आशीष शुक्ल — 20080615 @ 0242

  3. ahem… cool stuff.. I’ve tested it and it works jolly well

    Comment by viyyer — 20080615 @ 1003

  4. /me feels good :)

    Comment by आशीष शुक्ल — 20080615 @ 1605

  5. awesome, thank you in advance

    Comment by omid — 20081112 @ 0051

  6. Hello webmaster,
    I would like to share with you a link, write to alarroste@mail.ru

    Comment by alarroste — 20090219 @ 0519

  7. Thank you bro, perfect job.

    Comment by hal2k — 20090516 @ 1856

  8. […] wrote an #irssi plugin using Net::DBus and notification-daemon at https://wahjava.wordpress.com/2008/06/15/irssi-notifications/ […]

    Pingback by Ashish SHUKLA (abbe) 's status on Thursday, 01-Oct-09 13:50:49 UTC - Identi.ca — 20091001 @ 1920

  9. nice, thanks ;)

    Comment by mrJesus — 20100201 @ 2044


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: