]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Google.pl
1fab907e866ff0dee3e933edf99eaac177dba958
[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     my $data    = $Search->responseData;
40     my $cursor  = $data->cursor;
41     my @results = $data->results;
42
43     my $count;
44     $retval = "$where says \"\002$what\002\" is at ";
45     foreach my $r (@results) {
46         my $url = $r->url;
47         $retval .= " \002or\002 " if ( $count > 0 );
48         $retval .= $url;
49         last if ++$count >= $maxshow;
50     }
51
52     &::performStrictReply($retval);
53 }
54
55 1;
56  
57 # vim:ts=4:sw=4:expandtab:tw=80