Add more debugging to DICT
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 12 Sep 2007 14:17:58 +0000 (14:17 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 12 Sep 2007 14:17:58 +0000 (14:17 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@22 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml

index 400707d..fd52a91 100644 (file)
@@ -321,6 +321,9 @@ LISTKEYS: |-
 
 DICT: |-
   sub {
+    require WWW::Search;
+    require WWW::Search::UrbanDictionary;
+
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
     if( $what =~ /^$/ ) {
        $kernel->post( $src, $replypath, "USAGE: dict [<dictionary>/][<#>.]<query>\nSee also: dicts",$dest );
@@ -351,7 +354,6 @@ DICT: |-
   
     if( $dict =~ m/^urban/i ) {
       print( "DICT: Urban Dictionary", "\n" );
-      use WWW::Search;
   
       my $key = "84d324f8a5fcae301ec4aefcd258dff2";
       my $search = WWW::Search->new('UrbanDictionary', key=>$key );
@@ -365,6 +367,11 @@ DICT: |-
       # SOAP::Lite, which is the Urban Dictionary backend, is smart enough to escape queries on its own.
       $search->native_query( $what );
       $search->seek_result( $num );
+      if( !$search->response->is_success ) {
+        print( "DICT: Error while searching: ".$search->response->as_string(), "\n" );
+        $kernel->post( $src, $replypath, "Error while searching: ".$search->response->as_string(), $dest );
+        return;
+      }
       my $result;
       if( !( $result = $search->next_result() ) ) {
         print( "DICT: No result", "\n" );
@@ -374,6 +381,9 @@ DICT: |-
           $kernel->post( $src, $replypath, "No entry #".$num." for '$what'.", $dest );
         }
        return;
+      } else {
+       my $hits = $search->approximate_result_count();
+        print( "DICT: Backend reports $hits hit".($hits==1:""?"s"), "\n" );
       }
       my $response = $result->{ 'word' }.": ".$result->{ 'description' };
       $response =~ s/\n/ /g;