}
if( $dict =~ m/^urban/i ) {
+ use JSON;
+ use LWP::Simple;
use HTML::Entities;
- print( "DICT: Urban Dictionary", "\n" );
-
- my $key = "84d324f8a5fcae301ec4aefcd258dff2";
- my $search = WWW::Search->new('UrbanDictionary', key=>$key );
-
- if( $num > 0 ) {
- $search->maximum_to_retrieve( $num + 1 );
- } else {
- $search->maximum_to_retrieve( 1 );
- }
- $search->timeout( 10 );
- # 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" );
- if( $num == 0 ) {
- $kernel->post( $src, $replypath, "No result for '$what'.", $dest );
+ $num += 1;
+ my $page = get( 'http://www.urbandictionary.com/iphone/search/define?term='.$what );
+ my $response = decode_json $page;
+ if( $num > $response->{ "total" } ) {
+ if( $num == 1 ) {
+ $kernel->post( $src, $replypath, "There is no definition for '".$what."'", $dest );
} else {
- $kernel->post( $src, $replypath, "No entry #".$num." for '$what'.", $dest );
+ $kernel->post( $src, $replypath, "There is no definition #".$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->{ 'definition' };
- $response = decode_entities( $response );
- $response =~ s/\n/ /g;
- print( "DICT: Fetched result\n" );
- $heap->{ 'DICT_cache' }->{ 'URBAN' }->{ "$num.$what" } = $response;
- $kernel->post( $src, $replypath, $response, $dest );
+ return;
+ }
+ my $result = $response->{ "list" }->[ $num-1 ]->{ "word" }.": ".$response->{ "list" }->[ $num-1 ]->{ "definition" };
+ $result = decode_entities( $result );
+ $result =~ s/\n/ /g;
+ $heap->{ 'DICT_cache' }->{ 'URBAN' }->{ "$num.$what" } = $result;
+ $kernel->post( $src, $replypath, $result, $dest );
} else {
use Net::Dict;
print( "DICT: Establish connection.\n" );
$kernel->post( $src, $replypath, "An error occured: ".$imdb->error(), $dest );
}
}
+
+VERSION: |-
+ sub {
+ my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+ $what =~ s/(^\s+)|(\s+$)//g;
+ my @args = split(/ /, $what);
+ if( (scalar @args) != 2 ) {
+ $kernel->post( $src, $replypath, "VERSION displays the current version of a Debian package.", $dest );
+ $kernel->post( $src, $replypath, "Usage: VERSION <release name> <package name>", $dest );
+ return;
+ }
+ use LWP::Simple;
+ my $page = get( "http://packages.debian.org/".join( '/', @args ) );
+ $page =~ m/<h1>(Package: .*?)<\/h1>/s;
+ $kernel->post( $src, $replypath, $1, $dest );
+ }