]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/W3Search.pl
fix chanlimitChange time
[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 use vars qw(@W3Search_engines $W3Search_regex);
9 @W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek
10                 Lycos Magellan PLweb SFgate Simple Verity Google);
11 $W3Search_regex = join '|', @W3Search_engines;
12
13 my $maxshow     = 3;
14
15 sub W3Search {
16     my ($where, $what, $type) = @_;
17     my $retval = "$where can't find \002$what\002";
18
19     my @matches = grep { lc($_) eq lc($where) ? $_ : undef } @W3Search_engines;
20     if (@matches) {
21         $where = shift @matches;
22     } else {
23         &::msg($::who, "i don't know how to check '$where'");
24         return;
25     }
26
27     return unless &::loadPerlModule("WWW::Search");
28
29     my $Search  = new WWW::Search($where);
30     my $Query   = WWW::Search::escape_query($what);
31     $Search->native_query($Query,
32 #       {
33 #               search_debug => 2,
34 #               search_parse_debug => 2,
35 #       }
36     );
37     $Search->http_proxy($::param{'httpProxy'}) if (&::IsParam("httpProxy"));
38     my $max = $Search->maximum_to_retrieve(10); # DOES NOT WORK.
39
40     my (%results, $count, $r);
41     while ($r = $Search->next_result()) {
42         my $url = $r->url();
43
44         ### TODO: fix regex.
45         ### TODO: use array to preserve order.
46         if ($url =~ /^http:\/\/([\w\.]*)/) {
47             my $hostname = $1;
48             next if (exists $results{$hostname});
49             $results{$hostname} = $url;
50         } else {
51             &::DEBUG("W3S: url isn't good? ($url).");
52         }
53
54         last if ++$count >= $maxshow;
55     }
56
57     if (scalar keys %results) {
58         $retval = "$where says \002$what\002 is at ".
59                 join(' or ', map { $results{$_} } sort keys %results);
60     }
61
62     &::performStrictReply($retval);
63 }
64
65 1;