1use strict; 2use vars qw($VERSION %IRSSI); 3use Irssi qw(command_bind command_runsub); 4 5$VERSION = '2002121801'; 6%IRSSI = ( 7 authors => 'Daniel K. Gebhart, Marcus R�ckert', 8 contact => 'dkg@con-fuse.org, darix@irssi.org', 9 name => 'BMI Calculator', 10 description => 'a simple body mass index calculator for depression ;)', 11 license => 'GPLv2', 12 url => 'http://dkg.con-fuse.org/irssi/scripts/', 13 changed => $VERSION, 14); 15 16sub bmi_help () { 17 print ( CLIENTCRAP "\nBMI <weigth_in_kg> <height_in_cm> [<precision>]\n" ); 18 print ( CLIENTCRAP "please specify weight in kilograms (10-999kg) and height in cm (10-999cm). you can use decimal places. output precision (0-9).\n" ); 19 print ( CLIENTCRAP "The optimal BMI is 19-24 for women and 20-25 for men.\n" ); 20} 21 22command_bind 'bmi help' => sub { bmi_help(); }; 23 24command_bind 'bmi' => sub { 25 my ($data, $server, $item) = @_; 26 $data =~ s/\s+$//g; 27 $data =~ s/,/./g; 28 if ($data eq '') { 29 bmi_help(); 30 } 31 elsif ( $data =~ m/^help/i ) { 32 command_runsub ( 'bmi', $data, $server, $item ); 33 } 34 else { 35 if ( $data =~ m/^(\d{2,3}(\.\d+)?)\s+(\d{2,3}(\.\d+)?)(\s+(\d))?$/ ) { 36 my ($kg, $cm) = ($1, $3); 37 my $precision = ( defined ($6) ) ? $6 : 2; 38 print ( CRAP "with $kg kg at $cm cm you have a bmi of " . sprintf("%." . $precision . "f", ( ( $kg/$cm**2 ) *10000 ) ) ); 39 } 40 else { 41 print ( CRAP "please specify weight in kilograms (10-999kg) and height in cm (10-999cm). you can use decimal places. output precision (0-9)." ); 42 print ( CRAP "params were: $data" ); 43 } 44 } 45}; 46