]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Google.pl
* Accidentally left in a debug output
[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     # $where set to official google colors ;)
15     my $where  = "\00312G\0034o\0038o\00312g\0033l\0034e\003";
16     my $retval = "$where can't find \002$what\002";
17     my $Search;
18     my $referer = "irc://$::server/$::chan/$::who";
19
20     return unless &::loadPerlModule("REST::Google::Search");
21
22     &::DEBUG( "Google::GoogleSearch->referer = $referer" );
23     &::status( "Google::GoogleSearch> Searching Google for: $what");
24     REST::Google::Search->http_referer( $referer );
25     $Search = REST::Google::Search->new( q => $what );
26
27     if ( !defined $Search ) {
28         &::msg( $::who, "$where is invalid search." );
29         &::WARN( "Google::GoogleSearch> $::who generated an invalid search: $where");
30         return;
31     }
32
33     if ( $Search->responseStatus != 200 ) {
34         &::msg( $::who, "http error returned." );
35         &::WARN( "Google::GoogleSearch> http error returned: $Search->responseStatus");
36         return;
37     }
38
39     # No results found
40     if ( not $Search->responseData->results ) {
41         &::DEBUG( "Google::GoogleSearch> $retval" );
42         &::msg( $::who, $retval);
43         return;
44     }
45
46     my $data    = $Search->responseData;
47     my $cursor  = $data->cursor;
48     my @results = $data->results;
49     my $count;
50
51     $retval = "$where says \"\002$what\002\" is at ";
52     foreach my $r (@results) {
53         my $url = $r->url;
54         $retval .= " \002or\002 " if ( $count > 0 );
55         $retval .= $url;
56         last if ++$count >= $maxshow;
57     }
58
59     &::performStrictReply($retval);
60 }
61
62 1;
63  
64 # vim:ts=4:sw=4:expandtab:tw=80