TRANSLATE: |-
sub {
- use Lingua::Translate;
+ use REST::Google::Translate;
+ REST::Google::Translate->http_referer( "http://cernu.us" );
my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
if( $what eq "" ) {
- my $bbl = Lingua::Translate::Babelfish->new( src=>"en", dest=>"en" );
- my @languages = $bbl->available();
- my $response = join( ', ', @languages );
- $response =~ s/_/->/g;
- $kernel->post( $src, $replypath, "I can translate these languages: ".$response, $dest );
- $kernel->post( $src, $replypath, "Usage: translate [from] <Src.Lang.> [to] <Dest.Lang.> <message>", $dest );
+ $kernel->post( $src, $replypath, "Usage: translate <source lang> <dest lang> <message> -- I have no idea what languages I know, so just try two-letter codes.", $dest );
return;
}
my @words = split( / /, $what );
- if( $words[0] eq "from" ) {
- shift @words;
- }
my $from = shift @words;
- if( $words[0] eq "to" ) {
- shift @words;
- }
my $to = shift @words;
- my $tlater;
- my $translation;
- eval {
- $tlater = Lingua::Translate->new( src => $from, dest => $to );
- $translation = $tlater->translate( join( ' ', @words ) );
- };
- if( $@ ) {
- chomp $@;
- $kernel->post( $src, $replypath, "Translation failed. Invalid arguments? Error message: '$@'", $dest );
+ my $result = REST::Google::Translate->new(
+ q => join( ' ', @words ),
+ langpair => "$from|$to"
+ );
+ if( $result->responseStatus != 200 ) {
+ $kernel->post( $src, $replypath, "Translation failed. Invalid arguments? Bad language? No clue.", $dest );
return;
}
- $kernel->post( $src, $replypath, $translation, $dest );
+ my $trtx = $result->responseData->translatedText;
+ $trtx =~ s/'/'/gi;
+ $kernel->post( $src, $replypath, $trtx, $dest );
}
RSS: |-
}
if( $#args == 0 ) {
if( $args[0] =~ /^[0-9]{5}$/ ) {
- my $site
+ my $site;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(5);
$heap->{ "karma" }->{ uc( $what ) }--;
}
DumpFile( "karma.yaml", $heap->{ 'karma' } );
+ print( "KARMA: <$who> $what--\n" );
}
KARMAUP: |-
$heap->{ "karma" }->{ uc( $what ) }++;
}
DumpFile( "karma.yaml", $heap->{ 'karma' } );
+ print( "KARMA: <$who> $what++\n" );
}
KARMACLEAN: |-