Skip to content

Instantly share code, notes, and snippets.

@rpetre
Created September 4, 2013 15:26
Show Gist options
  • Select an option

  • Save rpetre/6438588 to your computer and use it in GitHub Desktop.

Select an option

Save rpetre/6438588 to your computer and use it in GitHub Desktop.
##
## Put me in ~/.irssi/scripts, and then execute the following in irssi:
##
## /load perl
## /script load notify
##
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
use Net::DBus;
$VERSION = "0.01";
%IRSSI = (
authors => 'Luke Macken, Paul W. Frields',
contact => '[email protected], [email protected]',
name => 'notify.pl',
description => 'Use libnotify to alert user to hilighted messages',
license => 'GNU General Public License',
url => 'http://lewk.org/log/code/irssi-notify',
);
Irssi::settings_add_str('notify', 'notify_icon', 'gtk-dialog-info');
Irssi::settings_add_str('notify', 'notify_time', '5000');
sub notify {
my ($server, $summary, $message) = @_;
# Make the message entity-safe
$message =~ s/&/&/g; # That could have been done better.
$message =~ s/</&lt;/g;
$message =~ s/>/&gt;/g;
$message =~ s/'/&apos;/g;
# my $cmd = "EXEC - notify-send" .
# " -i " . Irssi::settings_get_str('notify_icon') .
# " -t " . Irssi::settings_get_str('notify_time') .
# " -- '" . $summary . "'" .
# " '" . $message . "'";
#
# $server->command($cmd);
my $sessionBus = Net::DBus->session;
my $notificationsService = $sessionBus->get_service('org.freedesktop.Notifications');
my $notificationsObject = $notificationsService->get_object('/org/freedesktop/Notifications', 'org.freedesktop.Notifications');
my $notificationId;
$notificationId = $notificationsObject->Notify('', 0, Irssi::settings_get_str('notify_icon') , $summary, $message, [], {}, Irssi::settings_get_str('notify_time') );
}
sub print_text_notify {
my ($dest, $text, $stripped) = @_;
my $server = $dest->{server};
return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT));
my $sender = $stripped;
$sender =~ s/^\<.([^\>]+)\>.+/\1/ ;
$stripped =~ s/^\<.[^\>]+\>.// ;
my $summary = $dest->{target} . ": " . $sender;
notify($server, $summary, $stripped);
}
sub message_private_notify {
my ($server, $msg, $nick, $address) = @_;
return if (!$server);
notify($server, "Private message from ".$nick, $msg);
}
sub dcc_request_notify {
my ($dcc, $sendaddr) = @_;
my $server = $dcc->{server};
return if (!$dcc);
notify($server, "DCC ".$dcc->{type}." request", $dcc->{nick});
}
Irssi::signal_add('print text', 'print_text_notify');
Irssi::signal_add('message private', 'message_private_notify');
Irssi::signal_add('dcc request', 'dcc_request_notify');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment