From a4d72d55acd3b7004a2726ea03d2192ab7982160 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Wed, 11 Feb 2009 20:40:07 +0000 Subject: [PATCH] Use HTML::Entities to decode entities from urban dictionary responses. Also implememnt and secure a DICTCLEAN command to wipe the dict cache. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@84 088b83a4-0077-4247-935c-42ec02c2848b --- cmdaccess.yaml | 1 + commands.yaml | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/cmdaccess.yaml b/cmdaccess.yaml index a1d108b..05c94cc 100644 --- a/cmdaccess.yaml +++ b/cmdaccess.yaml @@ -7,6 +7,7 @@ CMDACCESS: 2 CONFIG: 2 DECLASSIFY: 2 DEFINE: 1 +DICTCLEAN: 2 DIE: 2 FLUSHURLS: 1 IGNORE: 2 diff --git a/commands.yaml b/commands.yaml index 310516a..b7548dd 100644 --- a/commands.yaml +++ b/commands.yaml @@ -430,6 +430,13 @@ LISTKEYS: |- $kernel->post( $src, $replypath, $reply, $dest ); } +DICTCLEAN: |- + sub { + my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; + $heap->{ 'DICT_cache' } = {}; + $kernel->post( $src, $replypath, "Cleaned.", $dest ); + } + DICT: |- sub { require WWW::Search; @@ -464,6 +471,7 @@ DICT: |- } if( $dict =~ m/^urban/i ) { + use HTML::Entities; print( "DICT: Urban Dictionary", "\n" ); my $key = "84d324f8a5fcae301ec4aefcd258dff2"; @@ -497,6 +505,7 @@ DICT: |- 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; -- 2.11.0