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.
6 # Usage: 'chanset _default +Google' in query window with your bot
7 # to enable it in all channels
8 # /msg botnick google <query> OR <addressCharacter>google <query> to use
17 my ( $what, $type ) = @_;
18 # $where set to official google colors ;)
19 my $where = "\00312G\0034o\0038o\00312g\0033l\0034e\003";
20 my $retval = "$where can't find \002$what\002";
22 my $referer = "irc://$::server/$::chan/$::who";
24 return unless &::loadPerlModule("REST::Google::Search");
26 &::DEBUG( "Google::GoogleSearch->referer = $referer" );
27 &::status( "Google::GoogleSearch> Searching Google for: $what");
28 REST::Google::Search->http_referer( $referer );
29 $Search = REST::Google::Search->new( q => $what );
31 if ( !defined $Search ) {
32 &::msg( $::who, "$where is invalid search." );
33 &::WARN( "Google::GoogleSearch> $::who generated an invalid search: $where");
37 if ( $Search->responseStatus != 200 ) {
38 &::msg( $::who, "http error returned." );
39 &::WARN( "Google::GoogleSearch> http error returned: $Search->responseStatus");
44 if ( not $Search->responseData->results ) {
45 &::DEBUG( "Google::GoogleSearch> $retval" );
46 &::msg( $::who, $retval);
50 my $data = $Search->responseData;
51 my $cursor = $data->cursor;
52 my @results = $data->results;
55 $retval = "$where says \"\002$what\002\" is at ";
56 foreach my $r (@results) {
59 # Returns a string with each %XX sequence replaced with the actual byte
60 # (octet). From URI::Escape uri_unescape()
61 $url =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
63 $retval .= " \002or\002 " if ( $count > 0 );
65 last if ++$count >= $maxshow; # Only seems to return max of 4?
68 &::performStrictReply($retval);
73 # vim:ts=4:sw=4:expandtab:tw=80
78 # indent-tabs-mode: nil