]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/W3Search.pl
* Missed DebianBugs.pl in the previous merge
[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
10 @W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek
11   Lycos Magellan PLweb SFgate Simple Verity Google z);
12 $W3Search_regex = join '|', @W3Search_engines;
13
14 my $maxshow = 5;
15
16 sub W3Search {
17     my ( $where, $what, $type ) = @_;
18     my $retval = "$where can't find \002$what\002";
19     my $Search;
20
21     my @matches = grep { lc($_) eq lc($where) ? $_ : undef } @W3Search_engines;
22     if (@matches) {
23         $where = shift @matches;
24     }
25     else {
26         &::msg( $::who, "i don't know how to check '$where'" );
27         return;
28     }
29
30     return unless &::loadPerlModule("WWW::Search");
31
32     eval { $Search = new WWW::Search( $where, agent_name => 'Mozilla/4.5' ); };
33
34     if ( !defined $Search ) {
35         &::msg( $::who, "$where is invalid search." );
36         return;
37     }
38
39     my $Query = WWW::Search::escape_query($what);
40     $Search->native_query(
41         $Query,
42         {
43             num => 10,
44
45             #           search_debug => 2,
46             #           search_parse_debug => 2,
47         }
48     );
49     $Search->http_proxy( $::param{'httpProxy'} ) if ( &::IsParam('httpProxy') );
50
51     #my $max = $Search->maximum_to_retrieve(10);        # DOES NOT WORK.
52
53     my ( @results, $count, $r );
54     $retval = "$where says \002$what\002 is at ";
55     while ( $r = $Search->next_result() ) {
56         my $url = $r->url();
57         $retval .= ' or ' if ( $count > 0 );
58         $retval .= $url;
59         last if ++$count >= $maxshow;
60     }
61
62     &::performStrictReply($retval);
63 }
64
65 1;
66
67 # vim:ts=4:sw=4:expandtab:tw=80