Print auditing info for karma stuff. Use the Google translate API for translation.
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 5 Nov 2008 06:43:21 +0000 (06:43 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 5 Nov 2008 06:43:21 +0000 (06:43 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@78 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml

index 4519b50..f877c2e 100644 (file)
@@ -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] <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/&#39;/'/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: |-