ircscripts

collection of scripts to enhance irc experience
Log | Files | Refs

notify.pl (2184B)


      1 ##
      2 ## Put me in ~/.irssi/scripts, and then execute the following in irssi:
      3 ##
      4 ##       /load perl
      5 ##       /script load notify
      6 ##
      7 
      8 use strict;
      9 use Irssi;
     10 use vars qw($VERSION %IRSSI);
     11 use HTML::Entities;
     12 
     13 $VERSION = "0.5";
     14 %IRSSI = (
     15     authors     => 'Luke Macken, Paul W. Frields, underd0g, l0bster',
     16     contact     => 'lewk@csh.rit.edu, stickster@gmail.com, r00t@l0bster.ru, 0x0@underd0g.co',
     17     name        => 'notify.pl',
     18     description => 'Use D-Bus to alert user to hilighted messages',
     19     license     => 'GNU General Public License',
     20     url         => 'https://github.com/l0bsterz/notify.git',
     21 );
     22 
     23 Irssi::settings_add_str('notify', 'notify_remote', '');
     24 
     25 sub sanitize {
     26   my ($text) = @_;
     27   encode_entities($text,'\'<>&');
     28   my $apos = "&#39;";
     29   my $aposenc = "\&apos;";
     30   $text =~ s/$apos/$aposenc/g;
     31   $text =~ s/"/\\"/g;
     32   return $text;
     33 }
     34 
     35 sub notify {
     36     my ($server, $summary, $message) = @_;
     37 
     38     # Make the message entity-safe
     39     $summary = sanitize($summary);
     40     $message = sanitize($message);
     41 
     42     my $cmd = "EXEC - " .
     43 	"notify-send -a irssi -- '" . $summary . "' '". $message . "'";
     44     $server->command($cmd);
     45 
     46     my $remote = Irssi::settings_get_str('notify_remote');
     47     if ($remote ne '') {
     48 	my $cmd = "EXEC - ssh -q " . $remote .
     49 	    "notify-send -a irssi -- '" . $summary . "' '". $message . "'";
     50 	$server->command($cmd);
     51     }
     52 
     53 }
     54  
     55 sub print_text_notify {
     56     my ($dest, $text, $stripped) = @_;
     57     my $server = $dest->{server};
     58     my $channel = $dest->{channel};
     59     return if (!$server);
     60     my $sender = $stripped;
     61     $sender =~ s/^\<?(.+?)\>? .*/\1/ ;
     62     $stripped =~ s/^.+? +(.*)/\1/ ;
     63     notify($channel, $sender, $stripped);
     64 }
     65 
     66 sub message_private_notify {
     67     my ($server, $msg, $nick, $address) = @_;
     68 
     69     return if (!$server);
     70     notify($server, "PM from ".$nick, $msg);
     71 }
     72 
     73 sub dcc_request_notify {
     74     my ($dcc, $sendaddr) = @_;
     75     my $server = $dcc->{server};
     76 
     77     return if (!$dcc);
     78     notify($server, "DCC ".$dcc->{type}." request", $dcc->{nick});
     79 }
     80 
     81 Irssi::signal_add('print text', 'print_text_notify');
     82 Irssi::signal_add('message private', 'message_private_notify');
     83 Irssi::signal_add('dcc request', 'dcc_request_notify');