forked from nchowning/multinotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultinotify-client.pl
109 lines (89 loc) · 2.52 KB
/
multinotify-client.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
#!/usr/bin/perl
######
# Multinotify Desktop Client
# nchowning, 2011 - [email protected]
######
# Set the app name and load the socket module
use constant APP_NAME => 'multinotify-client';
use IO::Socket::INET;
my $os = $^O;
my $IPADDRESS = 'IP ADDRESS IN HERE';
my $PORT = 'PORT IN HERE';
my $notifier;
# Check to see which notification modules are installed
# If none are installed, die
if (eval{ require Gtk2::Notify; })
{
$notifier = 'libnotify';
}
elsif (eval{ require Cocoa::Growl; })
{
$notifier = 'growl';
}
else
{
print "!!!No notifier module installed!!!\n
Multinotify currently has built-in support for libnotify (Gtk2::Notify) and Growl (Cocoa::Growl).\n";
die;
}
# Flush
$| = 1;
my ($socket,$client_socket);
# Socket variable initialization
$socket = new IO::Socket::INET (
PeerHost => "$IPADDRESS",
PeerPort => "$PORT",
Proto => 'tcp',
) or die "ERROR in Socket Creation : $!\n";
print "Connection Successful.\n";
$data = "receive";
print $socket "$data\n";
while(<$socket>)
{
# my ($username,$message);
# Store the username in $username and chomp it to remove the newline
chomp($username = $_);
# Be courteous and tell the server "thanks"
$data = "thanks";
print $socket "$data\n";
# Store the message in $message and chomp it to remove the newline
chomp($message = <$socket>);
# Send the username and message to notify
notify($username, $message);
print "$username: $message\n";
}
$socket->close();
sub notify
{
# Set the username & message that is passed to this function
my($username, $message) = @_;
if ($notifier eq 'libnotify')
{
######
# Need to add line breaks at a certain point as libnotify doesn't
# clean that up for you (like growl does).
######
# Strip '<' and '>' from the message
$message =~ s/<//g;
$message =~ s/>//g;
# Create the notification
my $notification = Gtk2::Notify->new($username, $message, 'irssi.png');
# Show the notification
$notification->show;
}
elsif ($notifier eq 'growl')
{
# Create growl notifier
Cocoa::Growl::growl_register(
app => 'irssi',
icon => 'irssi.png',
notifications => [qw(irssi)],
);
# Show growl notification
Cocoa::Growl::growl_notify(
name => 'irssi',
title => "Message from: $username",
description => "$message"
);
}
}