]> git.donarmstrong.com Git - infobot.git/commitdiff
- fixes for babelfish
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 2 Feb 2001 13:10:01 +0000 (13:10 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 2 Feb 2001 13:10:01 +0000 (13:10 +0000)
- typo of IsChanConf for wwwsearch.
- parseCmdHooks return vals fixed.
- babel.pl: regex fixed -- works!!!

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@299 c11ca15a-4712-0410-83d8-924469b57eb5

src/CommandStubs.pl
src/Modules/babel.pl

index c420031551b1bac34269c078151521988fb26208..705223a6c1566a3018e4dc2cd1e86ca2d549e453 100644 (file)
@@ -4,9 +4,9 @@
 
 if (&IsParam("useStrict")) { use strict; }
 
-$babel::lang_regex = "";       # lame fix.
+$babel_lang_regex = "fr|sp|po|pt|it|ge|de|gr|en";
 
-### PROPOSED COMMAND HOOK IMPLEMENTATION.
+### COMMAND HOOK IMPLEMENTATION.
 # addCmdHook("SECTION", 'TEXT_HOOK',
 #      (CODEREF        => 'Blah', 
 #      Forker          => 1,
@@ -83,12 +83,12 @@ sub parseCmdHook {
 
        ### IDENTIFIER.
        if (exists $hash{'Identifier'}) {
-           return unless (&hasParam($hash{'Identifier'}));
+           return unless (&hasParam($hash{'Identifier'}));
        }
 
        ### USER FLAGS.
        if (exists $hash{'UserFlag'}) {
-           return unless (&hasFlag($hash{'UserFlag'}));
+           return unless (&hasFlag($hash{'UserFlag'}));
        }
 
        ### FORKER,IDENTIFIER,CODEREF.
@@ -207,13 +207,13 @@ sub Modules {
     }
 
     # babel bot: Jonathan Feinberg++
-    if (&IsParam("babelfish") and $message =~ m{
+    if (&IsChanConf("babelfish") and $message =~ m{
                ^\s*
                (?:babel(?:fish)?|x|xlate|translate)
                \s+
                (to|from)               # direction of translation (through)
                \s+
-               ($babel::lang_regex)\w* # which language?
+               ($babel_lang_regex)\w*  # which language?
                \s*
                (.+)                    # The phrase to be translated
        }xoi) {
@@ -224,7 +224,7 @@ sub Modules {
        return;
     }
 
-    if (&IsParam("debian")) {
+    if (&IsChanConf("debian")) {
        my $debiancmd    = 'conflicts?|depends?|desc|file|info|provides?';
        $debiancmd      .= '|recommends?|suggests?|maint|maintainer';
        if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
@@ -241,7 +241,7 @@ sub Modules {
     }
 
     # google searching. Simon++
-    if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
+    if (&IsChanConf("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
        return unless (&hasParam("wwwsearch"));
 
        &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
index a75a19a2a1b0970c82c05a6ccef99ca91f7d28be..c2c7de91fbbecabd0a436ad689493d923c70807f 100644 (file)
@@ -35,47 +35,52 @@ BEGIN {
 sub babelfish {
     my ($direction, $lang, $phrase) = @_;
 
-    return unless &loadPerlModule("URI::Escape");
+    return unless &::loadPerlModule("URI::Escape");
+    return unless &::loadPerlModule("LWP::UserAgent");
 
     $lang = $lang_code{$lang};
 
     my $ua = new LWP::UserAgent;
     $ua->timeout(10);
+    $ua->proxy('http', $::param{'httpProxy'}) if &::IsParam("httpProxy");
 
-    my $url = 'http://babelfish.altavista.digital.com/cgi-bin/translate';
+    my $url = 'http://babelfish.altavista.com/raging/translate.dyn';
     my $req = HTTP::Request->new('POST',$url);
+
     $req->content_type('application/x-www-form-urlencoded');
 
     my $tolang = "en_$lang";
     my $toenglish = "${lang}_en";
 
     if ($direction eq 'to') {
-       &::performStrictReply( translate($phrase, $tolang, $req, $ua) );
+       my $xlate = translate($phrase, $tolang, $req, $ua);
+       &::pSReply($xlate) if ($xlate);
        return;
     } elsif ($direction eq 'from') {
-       &::performStrictReply( translate($phrase, $toenglish, $req, $ua) );
+       my $xlate = translate($phrase, $toenglish, $req, $ua);
+       &::pStReply($xlate) if ($xlate);
        return;
     }
+    &DEBUG("what's this junk?");
 
     my $last_english = $phrase;
     my $last_lang;
     my %results = ();
     my $i = 0;
     while ($i++ < 7) {
-       last if $results{$phrase}++;
+       last if $results{$phrase}++;    # REMOVE!
        $last_lang = $phrase = translate($phrase, $tolang, $req, $ua);
-       last if $results{$phrase}++;
+       last if $results{$phrase}++;    # REMOVE!
        $last_english = $phrase = translate($phrase, $toenglish, $req, $ua);
     }
 
-    &::performStrictReply($last_english);
+    &::pSReply($last_english);
 }
 
 sub translate {
-    return '' if $no_babel;
     my ($phrase, $languagepair, $req, $ua) = @_;
 
-    my $urltext = uri_escape($phrase);
+    my $urltext = URI::Escape::uri_escape($phrase);
     $req->content("urltext=$urltext&lp=$languagepair&doit=done");
 
     my $res = $ua->request($req);
@@ -83,25 +88,23 @@ sub translate {
     my $translated;
     if ($res->is_success) {            # success.
        my $html = $res->content;
-       # This method subject to change with the whims of Altavista's design
-       # staff.
-
-       $translated =
-         ($html =~ m{<br>
-                         \s+
-                             <font\ face="arial,\ helvetica">
-                                 \s*
-                                     (?:\*\*\s+time\ out\s+\*\*)?
-                                         \s*
-                                             ([^<]*)
-                                             }sx);
-
-       $translated =~ s/\n/ /g;
-       $translated =~ s/\s*$//;
+       $html   =~ s/\cM//g;
+       $html   =~ s/\n\s*\n/\n/g;
+       $html   =~ s/\n/ /g;    # ...
+
+       if ($html =~ /<textarea.*?>(.*?)<\/textarea/si) {
+           $translated = $1;
+           $translated =~ s/^[\n ]|[\n ]$//g;
+       } else {
+           &::WARN("failed regex for babelfish.");
+       }
+
     } else {                           # failure
-       $translated = ":(";
+       $translated = "FAILURE w/ babelfish";
     }
 
+    $translated        ||= "NULL reply from babelfish.";
+
     return $translated;
 }