/var/www/www.irssi.org-old/scripts/html/mldonkey_bandwidth.pl


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