]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Google.pl
handle negative units
[infobot.git] / src / Modules / Google.pl
index 1fab907e866ff0dee3e933edf99eaac177dba958..dd585cc48b16cbe769dc156fad9739164b3a22c6 100644 (file)
@@ -2,7 +2,11 @@
 # was deprecated and requires a key that google no longer provides. 
 # This new module uses REST::Google::Search 
 # Modified by db <db@cave.za.net> 12-01-2008. 
+#
+# Usage: 'chanset _default +Google' in query window with your bot
+#        to enable it in all channels
+#        /msg botnick google <query> OR <addressCharacter>google <query> to use
+
 package Google;
 
 use strict;
@@ -36,17 +40,29 @@ sub GoogleSearch {
         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 ";
     foreach my $r (@results) {
         my $url = $r->url;
+
+        # Returns a string with each %XX sequence replaced with the actual byte
+        # (octet). From URI::Escape uri_unescape()
+        $url =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
+
         $retval .= " \002or\002 " if ( $count > 0 );
         $retval .= $url;
-        last if ++$count >= $maxshow;
+        last if ++$count >= $maxshow; # Only seems to return max of 4?
     }
 
     &::performStrictReply($retval);
@@ -55,3 +71,9 @@ sub GoogleSearch {
 1;
  
 # vim:ts=4:sw=4:expandtab:tw=80 
+# Local Variables:
+# mode: cperl
+# tab-width: 4
+# fill-column: 80
+# indent-tabs-mode: nil
+# End: