package Bot::BasicBot::Pluggable::Module::GoogleCalc;
use warnings;
use strict;
use Bot::BasicBot::Pluggable::Module::Base;
use base qw (Bot::BasicBot::Pluggable::Module::Base);

use WWW::Google::Calculator;

sub told
{
	my ($self, $mess, $pri) = @_;

	my $body = $mess->{body};
	if ($body =~ /^calc\b/) {
		
		# get the formula we need to calc
		my $mathbits = $body;
		$mathbits =~ s/^calc\s*//;

		my $googlecalc = WWW::Google::Calculator->new;
		my $content = $googlecalc->calc($mathbits);

		if ($content) {
			$content =~ s/[\r\n]//gs;
			$self->reply($mess, $content);
		} else { 
			$self->reply($mess, "Eh?");
		}
	}
}

1;

