use Irssi;

use vars qw($VERSION %IRSSI);

$VERSION = "1.0";
%IRSSI = (
    author => 'pleia2',
    contact => 'lyz@princessleia.com ',
    name => 'conversion',
    description => 'Converts a few popular metric and standard measurements.',
    license => 'GNU GPL v2 or later',
    url => 'http://www.princessleia.com'
);

sub event_privmsg {
my ($server, $data, $nick, $mask) =@_;
my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
    	return if ( $text !~ /^!tempcon C |^!tempcon F |^!lengthcon cm |^!lengthcon in |^!weightcon lb |^!weightcon kg /i );
        if ( $text =~ /^!tempcon C /i ) {
                my ($temp) = $text =~ /!tempcon C (.*)/i;
                $newtemp = sprintf( "%4.1f", ($temp * 9 / 5 + 32) );
                        $server->command ( "msg $target $temp C is equal to $newtemp F" );
}                       
        elsif ( $text =~ /^!tempcon F /i ) {
                my ($temp) = $text =~ /!tempcon F (.*)/i;
                $newtemp = sprintf( "%4.1f", (($temp - 32) / 9 * 5) );
                        $server->command ( "msg $target $temp F is equal to $newtemp C" );
}                       
        elsif ( $text =~ /^!lengthcon cm /i ) {
                my ($length) = $text =~ /!lengthcon cm (.*)/i;
                $newlength = sprintf( "%4.1f", ($length * 0.39) );
                        $server->command ( "msg $target $length cm is equal to $newlength in" );
}                       
        elsif ( $text =~ /^!lengthcon in /i ) {
                my ($length) = $text =~ /!lengthcon in (.*)/i;
                $newlength = sprintf( "%4.1f", ($length * 2.54) );
                        $server->command ( "msg $target $length in is equal to $newlength cm" );
}                       
        elsif ( $text =~ /^!weightcon lb /i ) {
                my ($weight) = $text =~ /!weightcon lb (.*)/i;
                $newweight = sprintf( "%4.1f", ($weight / 2.203) );
                        $server->command ( "msg $target $weight lb is equal to $newweight kg" );
}                       
        elsif ( $text =~ /^!weightcon kg /i ) {
                my ($weight) = $text =~ /!weightcon kg (.*)/i;
                $newweight = sprintf( "%4.1f", ($weight * 2.203) );
                        $server->command ( "msg $target $weight kg is equal to $newweight lb" );
}
}

Irssi::signal_add('event privmsg', 'event_privmsg');
