blob: c3823950c9ee348807d2ad20c88cc7fc00181325 (
plain)
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
|
use strict;
require LWP::UserAgent;
use Irssi;
use HTTP::Request::Common;
use vars qw($VERSION %IRSSI);
$VERSION = "20180123";
%IRSSI = (
authors => "Carsten Otto",
contact => "c-otto\@gmx.de",
name => "mldonkey bandwidth script",
description => "Shows your mldonkey's current down- and upload rate",
license => "GPLv2",
url => "http://www.c-otto.de",
changed => "$VERSION",
commands => "mlbw"
);
Irssi::settings_add_str('mldonkey_bandwidth', 'mldonkey_bandwidth_host' ,'127.0.0.1:4080');
my $host = Irssi::settings_get_str('mldonkey_bandwidth_host');
sub cmd_mlbw
{
my ($args, $server, $target) = @_;
my $ua = LWP::UserAgent->new(timeout => 5);
my $req = GET "http://$host/submit?q=bw_stats";
my $resp = $ua->request($req);
my $output = $resp->content();
my $down = $output;
my $up = $output;
$down =~ s/.*Down: ([0-9]*\.*[0-9]) KB.*/$1/s;
$up =~ s/.*Up: ([0-9]*\.*[0-9]) KB.*/$1/s;
if ($down eq "") { $down = "(off)"; }
if ($up eq "") { $up = $down; }
$output = "-MLdonkey bandwidth stats- Down: $down - Up: $up";
if (!$server || !$server->{connected} || !$target)
{
Irssi::print $output;
} else
{
Irssi::active_win() -> command('say ' . $output);
}
}
sub cmd_changed
{
$host = Irssi::settings_get_str('mldonkey_bandwidth_host');
}
Irssi::command_bind('mlbw', 'cmd_mlbw');
Irssi::signal_add('setup changed', 'cmd_changed');
|