#!/usr/local/bin/perl

# This module allows you to make the bot retreive a new or updated module from the internet and place it in it's modules directory.
# The returned result is the raw wget return status, so 0 mean everything went ok.
# See http://www.gnu.org/software/wget/manual/html_node/Exit-Status.html for more information on the return status.

# These are the variables passed to each function call.
#
# $_[0] = name for this module (surely you already know this, but still)
# $_[1] = sending nickname
# $_[2] = sending username
# $_[3] = sending hostmask
# $_[4] = sending channel (or botnick in case of PM)
# $_[5] = current value for $modchan
# $_[6] = current value for $botnick
# $_[7] = first argument given in IRC
# $_[8] = second argument given in IRC etc.

package wget;

sub file {
	my (@list) = split(/\//, $_[7]);
	my $file = pop(@list);

	my ($fname, $ext) = split(/\./, $file);
	if($ext eq 'pm') {
			my @result = system( "wget $_[7] -O modules/$file" );
			nanobot::snd("NOTICE $_[1] :Result: @result");
	} else {
		nanobot::snd("NOTICE $_[1] :We can't download files like that, .pm only!");
	}
}

sub help {
	nanobot::snd("NOTICE $_[1] :Syntax: !download.file http://someaddress.com/module.pm");
}

1;
