- 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
if (&IsParam("useStrict")) { use strict; }
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,
# addCmdHook("SECTION", 'TEXT_HOOK',
# (CODEREF => 'Blah',
# Forker => 1,
### IDENTIFIER.
if (exists $hash{'Identifier'}) {
### IDENTIFIER.
if (exists $hash{'Identifier'}) {
- return unless (&hasParam($hash{'Identifier'}));
+ return 1 unless (&hasParam($hash{'Identifier'}));
}
### USER FLAGS.
if (exists $hash{'UserFlag'}) {
}
### USER FLAGS.
if (exists $hash{'UserFlag'}) {
- return unless (&hasFlag($hash{'UserFlag'}));
+ return 1 unless (&hasFlag($hash{'UserFlag'}));
}
### FORKER,IDENTIFIER,CODEREF.
}
### FORKER,IDENTIFIER,CODEREF.
}
# babel bot: Jonathan Feinberg++
}
# 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+
^\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) {
\s*
(.+) # The phrase to be translated
}xoi) {
- if (&IsParam("debian")) {
+ if (&IsChanConf("debian")) {
my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
$debiancmd .= '|recommends?|suggests?|maint|maintainer';
if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
$debiancmd .= '|recommends?|suggests?|maint|maintainer';
if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
}
# google searching. Simon++
}
# 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); } );
return unless (&hasParam("wwwsearch"));
&Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
sub babelfish {
my ($direction, $lang, $phrase) = @_;
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);
$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);
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') {
$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') {
return;
} elsif ($direction eq 'from') {
- &::performStrictReply( translate($phrase, $toenglish, $req, $ua) );
+ my $xlate = translate($phrase, $toenglish, $req, $ua);
+ &::pStReply($xlate) if ($xlate);
+ &DEBUG("what's this junk?");
my $last_english = $phrase;
my $last_lang;
my %results = ();
my $i = 0;
while ($i++ < 7) {
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_lang = $phrase = translate($phrase, $tolang, $req, $ua);
- last if $results{$phrase}++;
+ last if $results{$phrase}++; # REMOVE!
$last_english = $phrase = translate($phrase, $toenglish, $req, $ua);
}
$last_english = $phrase = translate($phrase, $toenglish, $req, $ua);
}
- &::performStrictReply($last_english);
+ &::pSReply($last_english);
- return '' if $no_babel;
my ($phrase, $languagepair, $req, $ua) = @_;
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);
$req->content("urltext=$urltext&lp=$languagepair&doit=done");
my $res = $ua->request($req);
my $translated;
if ($res->is_success) { # success.
my $html = $res->content;
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.");
+ }
+
+ $translated = "FAILURE w/ babelfish";
+ $translated ||= "NULL reply from babelfish.";
+