X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FW3Search.pl;h=4ce84743c7c3e335e2c5f50e143b84f98f717397;hb=b0a6ff9382a857f183319b77f7a352c377da59bd;hp=8f216b808aee93796022f0aac91b8b7c25eb5da3;hpb=a523737c588a01cf74076ae2a3c06a669389ddcb;p=infobot.git diff --git a/src/Modules/W3Search.pl b/src/Modules/W3Search.pl index 8f216b8..4ce8474 100644 --- a/src/Modules/W3Search.pl +++ b/src/Modules/W3Search.pl @@ -7,61 +7,55 @@ package W3Search; use strict; use vars qw(@W3Search_engines $W3Search_regex); @W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek - Lycos Magellan PLweb SFgate Simple Verity Google); + Lycos Magellan PLweb SFgate Simple Verity Google z); $W3Search_regex = join '|', @W3Search_engines; -my $maxshow = 3; +my $maxshow = 5; sub W3Search { my ($where, $what, $type) = @_; my $retval = "$where can't find \002$what\002"; - - return unless &::loadPerlModule("WWW::Search"); - - if (defined $type) { - &::DEBUG("W3S: type => $type"); - } + my $Search; my @matches = grep { lc($_) eq lc($where) ? $_ : undef } @W3Search_engines; if (@matches) { $where = shift @matches; } else { &::msg($::who, "i don't know how to check '$where'"); + return; + } + + 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; } - my $Search = new WWW::Search($where); 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 $max = $Search->maximum_to_retrieve(10); # DOES NOT WORK. - my (%results, $count, $r); + my (@results, $count, $r); + $retval = "$where says \002$what\002 is at "; while ($r = $Search->next_result()) { my $url = $r->url(); - - ### TODO: fix regex. - ### TODO: use array to preserve order. - if ($url =~ /^http:\/\/([\w\.]*)/) { - my $hostname = $1; - next if (exists $results{$hostname}); - $results{$hostname} = $url; - } else { - &::DEBUG("W3S: url isn't good? ($url)."); - } - + $retval .= ' or ' if ($count > 0); + $retval .= $url; last if ++$count >= $maxshow; } - if (scalar keys %results) { - $retval = "$where says \002$what\002 is at ". - join(' or ', map { $results{$_} } sort keys %results); - } - &::performStrictReply($retval); }