-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #871 from terminaldweller/server_status
added server_status.pl, gives a count of connected/disconnected servers as an expando
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use Irssi; | ||
use strict; | ||
use warnings; | ||
|
||
our $VERSION = "1.0.0"; | ||
our %IRSSI = ( | ||
authors => 'terminaldweller', | ||
contact => 'https://terminaldweller.com', | ||
name => 'server_status', | ||
description => 'gives you the count of connected and unconnected servers as an expando', | ||
license => 'GPL3 or newer', | ||
url => 'https://github.com/irssi/scripts.irssi.org', | ||
); | ||
|
||
my $server_status_count = ""; | ||
my $timeout; | ||
|
||
Irssi::settings_add_int('misc', 'server_status_count_freq', 100000); | ||
|
||
sub server_status { | ||
Irssi::timeout_remove($timeout); | ||
my $connected_count = 0; | ||
my $unconnected_count = 0; | ||
|
||
for my $server (Irssi::servers()) { | ||
if ($server->{'connected'}) { | ||
$connected_count++; | ||
} else { | ||
$unconnected_count++; | ||
} | ||
} | ||
|
||
$server_status_count = $connected_count."/".$unconnected_count; | ||
|
||
$timeout = Irssi::timeout_add_once(Irssi::settings_get_int('server_status_count_freq'), 'server_status' , undef); | ||
} | ||
|
||
Irssi::expando_create('server_status_count', sub { | ||
return $server_status_count; | ||
}, {}); | ||
|
||
$timeout = Irssi::timeout_add(Irssi::settings_get_int('server_status_count_freq'), 'server_status' , undef); | ||
server_status(); |