diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:19:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:19:02 +0000 |
commit | 03929dac2a29664878d2c971648a4fe1fb698462 (patch) | |
tree | 02c5e2b3e006234aa29545f7a93a1ce01b291a8b /scripts/sping.pl | |
parent | Initial commit. (diff) | |
download | irssi-scripts-74dedaab1f75de511e9ded8f64dcf9a4c7d2946f.tar.xz irssi-scripts-74dedaab1f75de511e9ded8f64dcf9a4c7d2946f.zip |
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/sping.pl')
-rw-r--r-- | scripts/sping.pl | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/sping.pl b/scripts/sping.pl new file mode 100644 index 0000000..4842454 --- /dev/null +++ b/scripts/sping.pl @@ -0,0 +1,41 @@ +use Irssi; +use Irssi::Irc; +use strict; + +use vars qw($VERSION %IRSSI); +$VERSION = "1.0"; +%IRSSI = ( + authors => "Maciek \'fahren\' Freudenheim, David Leadbeater", + contact => "fahren\@bochnia.pl", + name => "Server Ping", + description => "/SPING [server] - checks latency between current server and [server]", + license => "GNU GPLv2 or later", + changed => "Sun 15 Jun 18:56:52 BST 2014", +); + +# us. /SPING [server] + +use Time::HiRes qw(gettimeofday); + +my %askping; + +sub cmd_sping { + my ($target, $server, $winit) = @_; + + $target = $server->{address} unless $target; + $askping{$target} = gettimeofday(); + # using nickname rather than server seems to work better here + $server->send_raw("PING $server->{nick} $target"); +} + +sub event_pong { + my ($server, $args, $sname) = @_; + return unless exists $askping{$sname}; + + Irssi::signal_stop(); + Irssi::print(">> $sname latency: " . sprintf("%0.3f",gettimeofday() - $askping{$sname}) . "s"); + delete $askping{$sname}; +} + +Irssi::signal_add("event pong", "event_pong"); +Irssi::command_bind("sping", "cmd_sping"); |