From 684b756d29447f5c658a2e410880765da59b7b40 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Wed, 12 Sep 2007 14:17:58 +0000 Subject: [PATCH] Add more debugging to DICT git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@22 088b83a4-0077-4247-935c-42ec02c2848b --- commands.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/commands.yaml b/commands.yaml index 400707d..fd52a91 100644 --- a/commands.yaml +++ b/commands.yaml @@ -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 [/][<#>.]\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; -- 2.11.0