Skip to content

Instantly share code, notes, and snippets.

@davesque
Created September 25, 2012 17:02
Show Gist options
  • Save davesque/3783161 to your computer and use it in GitHub Desktop.
Save davesque/3783161 to your computer and use it in GitHub Desktop.
Modification of irssi lib notify script
#
# Installation:
#
# - Save me at ~/.irssi/scripts/notify.pl
#
# - In ~/.irssi/scripts:
# 1. $ mkdir autorun
# 2. $ cd autorun
# 3. $ ln -s ../notify.pl notify.pl
#
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
use HTML::Entities;
use IPC::System::Simple qw(systemx);
$VERSION = "0.5";
%IRSSI = (
authors => 'Luke Macken, Paul W. Frields',
contact => 'lewk@csh.rit.edu, stickster@gmail.com',
name => 'notify.pl',
description => 'Use lib notify to alert user of messages',
license => 'GNU General Public License',
url => 'http://code.google.com/p/irssi-libnotify',
);
Irssi::settings_add_str('notify', 'notify_remote', '');
sub trim {
my ($text) = @_;
$text =~ s/^\s+//;
$text =~ s/\s+$//;
return $text;
}
sub sanitize {
my ($text) = @_;
# Escape HTML entities
encode_entities($text,'\'"<>&');
# Escape backslash, apostrophe, quote, exclamation, and dash
$text =~ s/\\/\\\\/g;
$text =~ s/&#39;/\&apos;/g;
$text =~ s/"/\\"/g;
$text =~ s/!/\\!/g;
$text =~ s/-/\\-/g;
return $text;
}
sub notify {
my ($server, $summary, $message) = @_;
# Sanitize message
$summary = sanitize($summary);
$message = sanitize($message);
my @args = ($summary, $message);
systemx('notify-send', @args);
}
sub print_text_notify {
my ($dest, $text, $raw_message) = @_;
my $server = $dest->{server};
my $sender = $raw_message;
my $message = $raw_message;
# Return if anything other than chat message
return if ( ! $server || ! ( $raw_message =~ /^\<[^\>]+\>\s/ ) );
# Parse out sender
$sender =~ s/^\<([^\>]+)\>\s.*/$1/;
$sender = trim($sender);
# Parse out message
$message =~ s/^\<[^\>]+\>\s//;
my $summary = $dest->{target} . ": " . $sender;
notify($server, $summary, $message);
}
sub message_private_notify {
my ($server, $msg, $nick, $address) = @_;
return if (!$server);
notify($server, "PM 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