]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/W3Search.pl
* Update Changlog to reflect babelfish fix
[infobot.git] / src / Modules / W3Search.pl
index 72d78d3ccef5ed8a19ec85404b7586cfa24780be..27bdbd7d2b0c1437fb65208e3c7ca833c666847b 100644 (file)
@@ -5,51 +5,63 @@
 package W3Search;
 
 use strict;
+use vars qw(@W3Search_engines $W3Search_regex);
 
-my $maxshow    = 3;
+@W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek
+  Lycos Magellan PLweb SFgate Simple Verity Google z);
+$W3Search_regex = join '|', @W3Search_engines;
+
+my $maxshow = 5;
 
 sub W3Search {
-    my ($where, $what, $type) = @_;
+    my ( $where, $what, $type ) = @_;
     my $retval = "$where can't find \002$what\002";
+    my $Search;
 
-    return unless &main::loadPerlModule("WWW::Search");
-
-    my @matches = grep { lc($_) eq lc($where) ? $_ : undef } @main::W3Search_engines;
+    my @matches = grep { lc($_) eq lc($where) ? $_ : undef } @W3Search_engines;
     if (@matches) {
-       $where = shift @matches;
-    } else {
-       &main::msg($main::who, "i don't know how to check '$where'");
+        $where = shift @matches;
+    }
+    else {
+        &::msg( $::who, "i don't know how to check '$where'" );
+        return;
     }
 
-    my $Search = new WWW::Search($where);
-    my $Query  = WWW::Search::escape_query($what);
-    $Search->native_query($Query,
-#      {
-#              search_debug => 2,
-#              search_parse_debug => 2,
-#      }
-    );
-    $Search->http_proxy($main::param{'httpProxy'}) if (&main::IsParam("httpProxy"));
-    my $max = $Search->maximum_to_retrieve(10);        # DOES NOT WORK.
-
-    my ($Result, $count);
-    my $r;
-    ### TODO: don't duplicate hosts. minimize like with the files
-    ###                function.
-    while ($r = $Search->next_result()) {
-       if ($Result) {
-           $Result .= " or ".$r->url();
-       } else {
-           $Result = $r->url();
-       }
-       last if ++$count >= $maxshow;
+    return unless &::loadPerlModule("WWW::Search");
+
+    eval { $Search = new WWW::Search( $where, agent_name => 'Mozilla/4.5' ); };
+
+    if ( !defined $Search ) {
+        &::msg( $::who, "$where is invalid search." );
+        return;
     }
 
-    if ($Result) {
-       $retval = "$where says \002$what\002 is at $Result";
+    my $Query = WWW::Search::escape_query($what);
+    $Search->native_query(
+        $Query,
+        {
+            num => 10,
+
+            #          search_debug => 2,
+            #          search_parse_debug => 2,
+        }
+    );
+    $Search->http_proxy( $::param{'httpProxy'} ) if ( &::IsParam('httpProxy') );
+
+    #my $max = $Search->maximum_to_retrieve(10);       # DOES NOT WORK.
+
+    my ( @results, $count, $r );
+    $retval = "$where says \002$what\002 is at ";
+    while ( $r = $Search->next_result() ) {
+        my $url = $r->url();
+        $retval .= ' or ' if ( $count > 0 );
+        $retval .= $url;
+        last if ++$count >= $maxshow;
     }
 
-    &main::performStrictReply($retval);
+    &::performStrictReply($retval);
 }
 
 1;
+
+# vim:ts=4:sw=4:expandtab:tw=80