Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
support multiple hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
jwm committed Feb 11, 2013
1 parent 477642d commit 3707a7a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -68,13 +68,16 @@ it to properly showup on the receiving computer
## Network Settings

### `growl_net_client`
Set to the hostname you want to send notifications to
A space-separated list of the hostname(s) you want to send notifications to

On a Mac network this may be computer.local

### `growl_net_port`
The port on the destination computer

### `growl_net_timeout`
The network timeout when sending notifications

### `growl_net_name`
The name of the computer running irssi

Expand Down
65 changes: 40 additions & 25 deletions growl-net.pl
Expand Up @@ -6,7 +6,7 @@
# Based on the original growl script by Nelson Elhage and Toby Peterson.

use strict;
use vars qw($VERSION %IRSSI $growl);
use vars qw($VERSION %IRSSI @growl);

use Irssi;
use Growl::GNTP;
Expand Down Expand Up @@ -38,6 +38,7 @@
Irssi::settings_add_str($IRSSI{'name'}, 'growl_net_pass', '');
Irssi::settings_add_str($IRSSI{'name'}, 'growl_net_client', 'localhost');
Irssi::settings_add_str($IRSSI{'name'}, 'growl_net_port', '23053');
Irssi::settings_add_str($IRSSI{'name'}, 'growl_net_timeout', '2');
Irssi::settings_add_str($IRSSI{'name'}, 'growl_net_name', 'irssi');
Irssi::settings_add_str($IRSSI{'name'}, 'growl_net_icon', '');
# Sticky Settings
Expand All @@ -58,6 +59,7 @@ sub cmd_help {
Irssi::print(' %ygrowl_net_client%n : Set to the hostname you want to recieve notifications on.');
Irssi::print(' %R>>>> (computer.local for a Mac network. Your \'localhost\').');
Irssi::print(' %ygrowl_net_port%n : Set to the port you want to recieve notifications on.');
Irssi::print(' %ygrowl_net_timeout%n : Set the timeout for sending notifications.');
Irssi::print(' %ygrowl_net_name%n : Set to the name you want to give the machine irssi is running on.');
Irssi::print(' %ygrowl_net_pass%n : Set to your destination\'s Growl password. (Your machine)');
Irssi::print(' %ygrowl_auto_register%n : Automatically send gntp registration on script load');
Expand Down Expand Up @@ -188,33 +190,43 @@ sub set_sticky {
sub setup {
my $GrowlHost = Irssi::settings_get_str('growl_net_client');
my $GrowlPort = Irssi::settings_get_str('growl_net_port');
my $GrowlTimeout = Irssi::settings_get_str('growl_net_timeout');
my $GrowlPass = Irssi::settings_get_str('growl_net_pass');
my $AppName = Irssi::settings_get_str('growl_net_name');
my $GrowlIcon = Irssi::settings_get_str('growl_net_icon');

Irssi::print("%G>>%n Registering to send messages to $GrowlHost:$GrowlPort");
$growl = Growl::GNTP->new(
AppName => $AppName,
PeerHost => $GrowlHost,
PeerPort => $GrowlPort,
Password => $GrowlPass,
AppIcon => $GrowlIcon,
);
foreach my $host (split /\s+/, $GrowlHost) {
Irssi::print("%G>>%n Registering to send messages to $host:$GrowlPort");
push(@growl,
Growl::GNTP->new(
AppName => $AppName,
PeerHost => $host,
PeerPort => $GrowlPort,
Timeout => $GrowlTimeout,
Password => $GrowlPass,
AppIcon => $GrowlIcon,
)
);
}
}

sub cmd_register {
$growl->register([
{ Name => "Private Message", },
{ Name => "Hilight", },
{ Name => "Join", },
{ Name => "Part", },
{ Name => "Topic", },
]);
foreach my $growl (@growl) {
$growl->register([
{ Name => "Private Message", },
{ Name => "Hilight", },
{ Name => "Join", },
{ Name => "Part", },
{ Name => "Topic", },
]);
}
}

sub check_connection {
my $GrowlHost = Irssi::settings_get_str('growl_net_client');
my $GrowlPort = Irssi::settings_get_str('growl_net_port');
my($host) = shift;
my $GrowlPort = Irssi::settings_get_str('growl_net_port');
my $GrowlTimeout = Irssi::settings_get_str('growl_net_timeout');

my %check = (
tcp => {
$GrowlPort => {
Expand All @@ -223,19 +235,22 @@ sub check_connection {
},
);

check_ports($GrowlHost, 5, \%check);
check_ports($host, $GrowlTimeout, \%check);
return $check{tcp}{$GrowlPort}{open};
}

sub growl_notify {
if (!check_connection()) {
Irssi::print("The Growl server is not responding.");
return;
}

my (%args) = @_;

$growl->notify(%args);
foreach my $growl (@growl) {
if (!check_connection($growl->{PeerHost})) {
next;
}
eval {
# Ignore failure and continue onto the next host.
$growl->notify(%args);
}
}
}

Irssi::command_bind('growl-net', 'cmd_help');
Expand Down

0 comments on commit 3707a7a

Please sign in to comment.