]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Google.pl
* Retired the old broken W3Search module in favour of a working Google search
[infobot.git] / src / Modules / Google.pl
1 # W3Search drastically altered back to GoogleSearch as Search::Google 
2 # was deprecated and requires a key that google no longer provides. 
3 # This new module uses REST::Google::Search 
4 # Modified by db <db@cave.za.net> 12-01-2008. 
5  
6 package Google;
7
8 use strict;
9
10 my $maxshow = 5;
11
12 sub GoogleSearch {
13     my ( $what, $type ) = @_;
14     my $where  = "Google";
15     my $retval = "$where can't find \002$what\002";
16     my $Search;
17
18     return unless &::loadPerlModule("REST::Google::Search");
19
20     REST::Google::Search->http_referer('http://infobot.sourceforge.net/');
21     $Search = REST::Google::Search->new( q => $what );
22
23     if ( !defined $Search ) {
24         &::msg( $::who, "$where is invalid search." );
25         return;
26     }
27
28     if ( $Search->responseStatus != 200 ) {
29         &::msg( $::who, "http error returned." );
30         return;
31     }
32
33     my $data    = $Search->responseData;
34     my $cursor  = $data->cursor;
35     my @results = $data->results;
36
37     my $count;
38     $retval = "$where says \002$what\002 is at ";
39     foreach my $r (@results) {
40         my $url = $r->url;
41         $retval .= ' or ' if ( $count > 0 );
42         $retval .= $url;
43         last if ++$count >= $maxshow;
44     }
45
46     &::performStrictReply($retval);
47 }
48
49 1;
50  
51 # vim:ts=4:sw=4:expandtab:tw=80