markizano

irssi-notify.pl

Dec 18th, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.77 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. ##
  3. ## Put me in ~/.irssi/scripts, and then execute the following in irssi:
  4. ##
  5. ##         /load perl
  6. ##         /script load notify
  7. ##
  8.  
  9. use strict;
  10. use Irssi;
  11. use vars qw($VERSION %IRSSI);
  12. use Data::Dumper;
  13. use File::Slurp;
  14.  
  15. our $VERSION = "0.01";
  16. %IRSSI = (
  17.         authors  => ('Luke Macken', 'Markizano Draconus'),
  18.         contact  => ('[email protected]', '[email protected]'),
  19.         name            => 'notify.pl',
  20.         description => 'Sends notifications to libnotify for when people mention your nick either in channels or private messages.',
  21.         license  => 'GNU General Public License',
  22.         url              => 'http://lewk.org/log/code/irssi-notify',
  23. );
  24.  
  25. sub notify{
  26.         my ($dest, $text, $message) = @_;
  27.         my $server = $dest->{server};
  28.         my $title = "";
  29.  
  30.         return if(!$server);
  31.         if(
  32.                 $dest->{level} & (MSGLEVEL_HILIGHT | MSGLEVEL_MSGS)
  33.                 && ($dest->{level} & MSGLEVEL_NOHILIGHT)
  34.                 && ($dest->{level} & MSGLEVEL_CLIENTCRAP) == 0
  35.         ){
  36.                 return;
  37.         }
  38.  
  39.         return if($message !~ m/$server->{wanted_nick}/i);
  40.         return if($message =~ m/^\<.?$server->{wanted_nick}/i);
  41.         $message =~ s/(^-|')/'\\\1'/g;
  42.         $title = "$dest->{target}\@$server->{address}";
  43.         system("notify-send -i terminator -t 5000 '$title' '$message' 2>>/tmp/fnotify.err");
  44.         system("pgrep zenity 2>/dev/null >/dev/null || zenity --notification --text='$title' --window-icon=/usr/share/icons/hicolor/32x32/apps/terminator.png &");
  45.         File::Slurp::write_file('/tmp/fnotify.out', { append => 1 }, "$title\n$message");
  46. #       system("echo '$title\n$message' >> /tmp/fnotify.out");
  47. }
  48.  
  49. Irssi::signal_add('print text', 'notify');
Advertisement
Add Comment
Please, Sign In to add comment