From 6544e6f7430a04b386507c117e8817924dd01fa8 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Wed, 5 Nov 2008 06:43:21 +0000 Subject: [PATCH] Print auditing info for karma stuff. Use the Google translate API for translation. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@78 088b83a4-0077-4247-935c-42ec02c2848b --- commands.yaml | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/commands.yaml b/commands.yaml index 4519b50..f877c2e 100644 --- a/commands.yaml +++ b/commands.yaml @@ -839,38 +839,27 @@ QDB: |- 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] [to] ", $dest ); + $kernel->post( $src, $replypath, "Usage: translate -- 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: |- @@ -1143,7 +1132,7 @@ FANDANGO: |- } if( $#args == 0 ) { if( $args[0] =~ /^[0-9]{5}$/ ) { - my $site + my $site; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(5); @@ -1632,6 +1621,7 @@ KARMADOWN: |- $heap->{ "karma" }->{ uc( $what ) }--; } DumpFile( "karma.yaml", $heap->{ 'karma' } ); + print( "KARMA: <$who> $what--\n" ); } KARMAUP: |- @@ -1653,6 +1643,7 @@ KARMAUP: |- $heap->{ "karma" }->{ uc( $what ) }++; } DumpFile( "karma.yaml", $heap->{ 'karma' } ); + print( "KARMA: <$who> $what++\n" ); } KARMACLEAN: |- -- 2.11.0