-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathnotify.pl
122 lines (103 loc) · 3.31 KB
/
notify.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
##
## 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 HTML::Entities;
$VERSION = "0.5";
%IRSSI = (
authors => 'Luke Macken, Paul W. Frields',
contact => 'lewk@csh.rit.edu, stickster@gmail.com',
name => 'notify.pl',
description => 'Use D-Bus to alert user to hilighted messages',
license => 'GNU General Public License',
url => 'http://code.google.com/p/irssi-libnotify',
);
Irssi::settings_add_str('notify', 'notify_remote', '');
Irssi::settings_add_str('notify', 'notify_debug', '');
sub sanitize {
my ($text) = @_;
encode_entities($text,'\'<>&');
my $apos = "'";
my $aposenc = "\'";
$text =~ s/$apos/$aposenc/g;
$text =~ s/"/\\"/g;
$text =~ s/\$/\\\$/g;
$text =~ s/`/\\"/g;
return $text;
}
sub notify_linux {
my ($server, $nodebugstr, $remote, $summary, $message) = @_;
my $cmd = "EXEC " . $nodebugstr . "ssh -q " . $remote . " \"".
" ~/bin/irssi-notifier.sh".
" dbus-send --session /org/irssi/Irssi org.irssi.Irssi.IrssiNotify" .
" string:'" . $summary . "'" .
" string:'" . $message . "'\"";
#print $cmd;
$server->command($cmd);
}
sub notify_mac {
my ($server, $nodebugstr, $remote, $summary, $message) = @_;
$message =~ s/\\"/\\\\\\"/g;
my $cmd = "EXEC " . $nodebugstr . "ssh -q " . $remote . " \"".
" osascript -e".
" 'display notification \\\"". $message . "\\\"" .
" with title \\\"" . $summary . "\\\"" .
" sound name \\\"Basso\\\"'\"";
$server->command($cmd);
}
sub notify {
my ($server, $summary, $message) = @_;
# Make the message entity-safe
$summary = sanitize($summary);
$message = sanitize($message);
my $debug = Irssi::settings_get_str('notify_debug');
my $nodebugstr = '- ';
if ($debug ne '') {
$nodebugstr = '';
}
my $cmd = "EXEC " . $nodebugstr .
" ~/bin/irssi-notifier.sh " .
"dbus-send --session /org/irssi/Irssi org.irssi.Irssi.IrssiNotify" .
" string:'" . $summary . "'" .
" string:'" . $message . "'";
$server->command($cmd);
my $remote = Irssi::settings_get_str('notify_remote');
if ($remote ne '') {
if (substr($remote, length($remote)-1) ne 'M') {
notify_linux($server, $nodebugstr, $remote, $summary, $message);
}
else {
$remote = substr($remote, 0, length($remote)-1);
notify_mac($server, $nodebugstr, $remote, $summary, $message);
}
}
}
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, "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');