This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irssi-prowl.pl
105 lines (83 loc) · 2.98 KB
/
irssi-prowl.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
# Copyright 2011 Josh Kearney
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use strict;
use warnings;
use Irssi;
use LWP::Simple;
use vars qw($VERSION %IRSSI);
$VERSION = "0.0.3";
%IRSSI = (
authors => "Josh Kearney",
contact => "josh\@jk0.org",
name => "irssi-prowl",
description => "Send Prowl notifications upon new mentions or PMs when away.",
license => "Apache License, Version 2.0",
url => "https://github.com/jk0/irssi-prowl"
);
sub is_away {
my ($server) = @_;
return $server->{usermode_away};
}
sub msg_public {
my ($dest, $text, $stripped) = @_;
my ($nick, $message) = split(/ +/, $stripped, 2);
my $level = $dest->{level};
my $server = $dest->{server};
my $channel = $dest->{target};
$nick = substr($nick, 1, -1) if $nick;
if(is_away($server) && ($level & MSGLEVEL_HILIGHT) && ($level & MSGLEVEL_NOHILIGHT) == 0) {
send_notification($server->{chatnet}, "[$channel:$nick] $message");
}
}
sub msg_private {
my ($server, $msg, $nick, $mask, $channel) = @_;
if(is_away($server)) {
send_notification($server->{chatnet}, "[$nick] $msg");
}
}
sub send_notification {
my ($chatnet, $notice) = @_;
my $enabled = Irssi::settings_get_bool("prowl_enabled");
my $api_key = Irssi::settings_get_str("prowl_api_key");
return unless($enabled && (length($api_key) > 0));
$notice =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
my $url = sprintf("http://prowlapp.com/publicapi/add?apikey=%s&"
. "application=Irssi&event=%s&description=%s",
$api_key, $chatnet, $notice);
get($url);
}
sub proxy_connect {
my (@servers) = Irssi::servers();
foreach my $server (@servers) {
if(is_away($server)) {
$server->command("AWAY -one");
}
}
}
sub proxy_disconnect {
my (@servers) = Irssi::servers();
my $away_msg = Irssi::settings_get_str("prowl_away_msg");
foreach my $server (@servers) {
if(!is_away($server)) {
$server->command("AWAY -one $away_msg");
}
}
}
Irssi::settings_add_str("prowl", "prowl_api_key", "");
Irssi::settings_add_str("prowl", "prowl_away_msg", "afk");
Irssi::settings_add_bool("prowl", "prowl_enabled", 0);
Irssi::signal_add_last("print text", "msg_public");
Irssi::signal_add_last("message private", "msg_private");
Irssi::signal_add_last("proxy client connected", "proxy_connect");
Irssi::signal_add_last("proxy client disconnected", "proxy_disconnect");