X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FGoogle.pl;h=a8a66f93de1cdf2b4347e68c6fea0b0861d0ef5f;hb=82b7822f9140d90a6c714b1eec0fb8beb17e53dd;hp=f6762e2ae8994b3920a0a49a3f87b0284a787144;hpb=3ed9ef94139df2c011890b52f838643f0f8061e4;p=infobot.git diff --git a/src/Modules/Google.pl b/src/Modules/Google.pl index f6762e2..a8a66f9 100644 --- a/src/Modules/Google.pl +++ b/src/Modules/Google.pl @@ -11,34 +11,47 @@ my $maxshow = 5; sub GoogleSearch { my ( $what, $type ) = @_; - my $where = "Google"; + # $where set to official google colors ;) + my $where = "\00312G\0034o\0038o\00312g\0033l\0034e\003"; my $retval = "$where can't find \002$what\002"; my $Search; + my $referer = "irc://$::server/$::chan/$::who"; return unless &::loadPerlModule("REST::Google::Search"); - REST::Google::Search->http_referer('http://infobot.sourceforge.net/'); + &::DEBUG( "Google::GoogleSearch->referer = $referer" ); + &::status( "Google::GoogleSearch> Searching Google for: $what"); + REST::Google::Search->http_referer( $referer ); $Search = REST::Google::Search->new( q => $what ); if ( !defined $Search ) { &::msg( $::who, "$where is invalid search." ); + &::WARN( "Google::GoogleSearch> $::who generated an invalid search: $where"); return; } if ( $Search->responseStatus != 200 ) { &::msg( $::who, "http error returned." ); + &::WARN( "Google::GoogleSearch> http error returned: $Search->responseStatus"); + return; + } + + # No results found + if ( not $Search->responseData->results ) { + &::DEBUG( "Google::GoogleSearch> $retval" ); + &::msg( $::who, $retval); return; } my $data = $Search->responseData; my $cursor = $data->cursor; my @results = $data->results; - my $count; - $retval = "$where says \002$what\002 is at "; + + $retval = "$where says \"\002$what\002\" is at "; foreach my $r (@results) { my $url = $r->url; - $retval .= ' or ' if ( $count > 0 ); + $retval .= " \002or\002 " if ( $count > 0 ); $retval .= $url; last if ++$count >= $maxshow; }