forked from Julian/irssi-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier.pl
151 lines (135 loc) · 4.88 KB
/
notifier.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# == WHAT
# Simple script for irssi to trigger Mac OS X 10.8's Notification Center
#
# Modified: 2015-11-8 (Julian) to support Linux too (Gnome).
#
# == WHO
# Patrick Kontschak 2012
#
# Forked from Nate Murray's irssi-growl: https://github.com/jashmenn/irssi-growl
#
# == CONFIG
# /SET notifier_on_regex [regex]
# /SET notifier_channel_regex [regex]
#
# == EXAMPLES
#
# notifier on mynickname
# /SET notifier_on_regex mynickname
#
# notifier on everything:
# /SET notifier_on_regex .*
#
# everything but jdewey
# /SET notifier_on_regex (?=^(?:(?!jdewey).)*$).*
#
# only notifier things for mychannel1 and mychannel2
# /SET notifier_channel_regex (mychannel1|mychannel2)
#
# == INSTALL
# Place notifier.pl in `~/.irssi/scripts/`.
# /script load notifier.pl
#
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
# use Config;
# Dev. info ^_^
$VERSION = "0.0";
%IRSSI = (
authors => "Patrick Kontschak",
contact => "patrick.kontschak\@gmail.com",
name => "Notifier",
description => "Simple script that will trigger Mac OS X 10.8's Notification Center",
license => "GPL",
url => "http://www.codinggoat.com",
changed => "Wed 8 Aug 2012 14:40:15 EDT"
);
sub do_notifier {
my ($server, $title, $data) = @_;
if ($^O eq 'darwin') {
system('terminal-notifier', ('-message', $data, '-title', $title));
} else {
system('notify-send', ('--urgency', 'critical', '--expire-time', '1000', '--hint', 'int:transient:1', $title, $data));
}
return 1
}
sub notifier_it {
my ($server, $title, $data, $channel, $nick) = @_;
my $letter = substr($nick, 0, 1);
# ZNC spam fix
if ($letter != '*') {
my $filter = Irssi::settings_get_str('notifier_on_regex');
my $channel_filter = Irssi::settings_get_str('notifier_channel_regex');
my $notifier_on_nick = Irssi::settings_get_str('notifier_on_nick');
my $current_nick = $server->{nick};
if($filter) {
return 0 if $data !~ /$filter/;
}
if($channel_filter && $server->ischannel($channel)) {
return 0 if $channel !~ /$channel_filter/;
}
$title = $title . " " . $channel;
do_notifier($server, $title, $data);
}
}
# All the works
sub notifier_message {
my ($server, $data, $nick, $mask, $target) = @_;
notifier_it($server, $nick, $data, $target, $nick);
Irssi::signal_continue($server, $data, $nick, $mask, $target);
}
sub notifier_join {
my ($server, $channel, $nick, $address) = @_;
notifier_it($server, "Join", "$nick has joined", $channel, $nick);
Irssi::signal_continue($server, $channel, $nick, $address);
}
sub notifier_part {
my ($server, $channel, $nick, $address) = @_;
notifier_it($server, "Part", "$nick has parted", $channel, $nick);
Irssi::signal_continue($server, $channel, $nick, $address);
}
sub notifier_quit {
my ($server, $nick, $address, $reason) = @_;
notifier_it($server, "Quit", "$nick has quit: $reason", $server, $nick);
Irssi::signal_continue($server, $nick, $address, $reason);
}
sub notifier_invite {
my ($server, $channel, $nick, $address) = @_;
notifier_it($server, "Invite", "$nick has invited you on $channel", $channel, $nick);
Irssi::signal_continue($server, $channel, $address);
}
sub notifier_topic {
my ($server, $channel, $topic, $nick, $address) = @_;
notifier_it($server, "Topic: $topic", "$nick has changed the topic to $topic on $channel", $channel, $nick);
Irssi::signal_continue($server, $channel, $topic, $nick, $address);
}
sub notifier_privmsg {
# $server = server record where the message came
# $data = the raw data received from server, with PRIVMSGs it is:
# "target :text" where target is either your nick or #channel
# $nick = the nick who sent the message
# $host = host of the nick who sent the message
my ($server, $data, $nick, $host) = @_;
my ($target, $text) = split(/ :/, $data, 2);
# only notify if we're permitting notification on privmsg
if (Irssi::settings_get_str('notifier_on_privmsg') == 1) {
notifier_it($server, $nick, $data, $target, $nick);
}
Irssi::signal_continue($server, $data, $nick, $host);
}
# Hook me up
Irssi::settings_add_str('misc', 'notifier_on_regex', 0); # false
Irssi::settings_add_str('misc', 'notifier_channel_regex', 0); # false
Irssi::settings_add_str('misc', 'notifier_on_nick', 1); # true
Irssi::settings_add_str('misc', 'notifier_on_privmsg', 0); # false
Irssi::signal_add('message public', 'notifier_message');
Irssi::signal_add('message private', 'notifier_message');
Irssi::signal_add('message own_public', 'notifier_message');
Irssi::signal_add('message own_private', 'notifier_message');
Irssi::signal_add('message join', 'notifier_join');
Irssi::signal_add('message part', 'notifier_part');
Irssi::signal_add('message quit', 'notifier_quit');
Irssi::signal_add('message invite', 'notifier_invite');
Irssi::signal_add('message topic', 'notifier_topic');
Irssi::signal_add('event privmsg', 'notifier_privmsg');