Guest User

Untitled

a guest
Oct 23rd, 2017
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. ## Put me in ~/.irssi/scripts/autorun
  2. ##
  3.  
  4. use Irssi;
  5. use vars qw($VERSION %IRSSI);
  6.  
  7. $VERSION = "0.02";
  8. %IRSSI = (
  9. authors => 'Donald Ephraim Curtis',
  10. contact => 'dcurtis@cs.uiowa.edu',
  11. name => 'notify.pl',
  12. description => 'notify Awesome WM of irssi message',
  13. license => 'GNU General Public License',
  14. );
  15.  
  16. sub notify {
  17. my ($title, $text) = @_;
  18.  
  19. my %replacements = (
  20. '<' => '<',
  21. '>' => '>',
  22. '&' => '&',
  23. '\"' => '"',
  24. '`' => '', # added for security purposes
  25. );
  26.  
  27. # lazy way of constructing the regexp - I've done enough typing already!
  28. my $replacement_string = join '', keys %replacements;
  29.  
  30.  
  31. $title =~ s/([\Q$replacement_string\E])/$replacements{$1}/g;
  32. $text =~ s/([\Q$replacement_string\E])/$replacements{$1}/g;
  33.  
  34. system("notify-send -t 7500 \"<span color='#FF005F'>".$title."</span>\""." \"".$text."\"");
  35. }
  36.  
  37.  
  38. sub highlight {
  39. my ($dest, $msg, $stripped) = @_;
  40.  
  41. my $window = Irssi::active_win();
  42.  
  43. if (($dest->{level} & MSGLEVEL_HILIGHT) && ($dest->{level} & MSGLEVEL_PUBLIC)) {
  44. notify($dest->{target}, $stripped);
  45. }
  46.  
  47. }
  48.  
  49. sub query {
  50. my ($server, $msg, $nick, $addr) = @_;
  51.  
  52. my $window = Irssi::active_win();
  53.  
  54. my $itemwindow = $server->window_find_item($nick);
  55. if ($window->{refnum} != $itemwindow->{refnum}) {
  56. notify($nick, $msg);
  57. }
  58. }
  59.  
  60. Irssi::signal_add('print text', 'highlight');
  61. Irssi::signal_add('message private', 'query');
Add Comment
Please, Sign In to add comment