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 );
if( $dict =~ m/^urban/i ) {
print( "DICT: Urban Dictionary", "\n" );
- use WWW::Search;
my $key = "84d324f8a5fcae301ec4aefcd258dff2";
my $search = WWW::Search->new('UrbanDictionary', key=>$key );
# 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" );
$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;