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.
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";
18 my $referer = "irc://$::server/$::chan/$::who";
20 return unless &::loadPerlModule("REST::Google::Search");
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 );
27 if ( !defined $Search ) {
28 &::msg( $::who, "$where is invalid search." );
29 &::WARN( "Google::GoogleSearch> $::who generated an invalid search: $where");
33 if ( $Search->responseStatus != 200 ) {
34 &::msg( $::who, "http error returned." );
35 &::WARN( "Google::GoogleSearch> http error returned: $Search->responseStatus");
40 if ( not $Search->responseData->results ) {
41 &::DEBUG( "Google::GoogleSearch> $retval" );
42 &::msg( $::who, $retval);
46 my $data = $Search->responseData;
47 my $cursor = $data->cursor;
48 my @results = $data->results;
51 $retval = "$where says \"\002$what\002\" is at ";
52 foreach my $r (@results) {
55 # Returns a string with each %XX sequence replaced with the actual byte
56 # (octet). From URI::Escape uri_unescape()
57 $url =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
59 $retval .= " \002or\002 " if ( $count > 0 );
61 last if ++$count >= $maxshow; # Only seems to return max of 4?
64 &::performStrictReply($retval);
69 # vim:ts=4:sw=4:expandtab:tw=80