]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/W3Search.pl
Initial revision
[infobot.git] / src / Modules / W3Search.pl
1 # WWWSearch backend, with queries updating the is-db (optionally)
2 # Uses WWW::Search::Google and WWW::Search
3 # originally Google.pl, drastically altered.
4
5 package W3Search;
6
7 use strict;
8
9 my $maxshow     = 3;
10
11 sub W3Search {
12     my ($where, $what, $type) = @_;
13     my $retval = "$where can't find \002$what\002";
14
15     return unless &main::loadPerlModule("WWW::Search");
16
17     my @matches = grep { lc($_) eq lc($where) ? $_ : undef } @main::W3Search_engines;
18     if (@matches) {
19         $where = shift @matches;
20     } else {
21         &main::msg($main::who, "i don't know how to check '$where'");
22     }
23
24     my $Search  = new WWW::Search($where);
25     my $Query   = WWW::Search::escape_query($what);
26     $Search->native_query($Query,
27 #       {
28 #               search_debug => 2,
29 #               search_parse_debug => 2,
30 #       }
31     );
32     $Search->http_proxy($main::param{'httpProxy'}) if (&main::IsParam("httpProxy"));
33     my $max = $Search->maximum_to_retrieve(10); # DOES NOT WORK.
34
35     my ($Result, $count);
36     my $r;
37     ### TODO: don't duplicate hosts. minimize like with the files
38     ###         function.
39     while ($r = $Search->next_result()) {
40         if ($Result) {
41             $Result .= " or ".$r->url();
42         } else {
43             $Result = $r->url();
44         }
45         last if ++$count >= $maxshow;
46     }
47
48     if ($Result) {
49         $retval = "$where says \002$what\002 is at $Result";
50     }
51
52     &main::performStrictReply($retval);
53 }
54
55 1;