1use strict; 2require LWP::UserAgent; 3use Irssi; 4use HTTP::Request::Common; 5use vars qw($VERSION %IRSSI); 6 7$VERSION = "20180123"; 8%IRSSI = ( 9 authors => "Carsten Otto", 10 contact => "c-otto\@gmx.de", 11 name => "mldonkey bandwidth script", 12 description => "Shows your mldonkey's current down- and upload rate", 13 license => "GPLv2", 14 url => "http://www.c-otto.de", 15 changed => "$VERSION", 16 commands => "mlbw" 17); 18 19Irssi::settings_add_str('mldonkey_bandwidth', 'mldonkey_bandwidth_host' ,'127.0.0.1:4080'); 20my $host = Irssi::settings_get_str('mldonkey_bandwidth_host'); 21 22sub cmd_mlbw 23{ 24 my ($args, $server, $target) = @_; 25 my $ua = LWP::UserAgent->new(timeout => 5); 26 my $req = GET "http://$host/submit?q=bw_stats"; 27 my $resp = $ua->request($req); 28 my $output = $resp->content(); 29 my $down = $output; 30 my $up = $output; 31 $down =~ s/.*Down: ([0-9]*\.*[0-9]) KB.*/$1/s; 32 $up =~ s/.*Up: ([0-9]*\.*[0-9]) KB.*/$1/s; 33 if ($down eq "") { $down = "(off)"; } 34 if ($up eq "") { $up = $down; } 35 $output = "-MLdonkey bandwidth stats- Down: $down - Up: $up"; 36 if (!$server || !$server->{connected} || !$target) 37 { 38 Irssi::print $output; 39 } else 40 { 41 Irssi::active_win() -> command('say ' . $output); 42 } 43} 44 45sub cmd_changed 46{ 47 $host = Irssi::settings_get_str('mldonkey_bandwidth_host'); 48} 49 50Irssi::command_bind('mlbw', 'cmd_mlbw'); 51Irssi::signal_add('setup changed', 'cmd_changed'); 52