From 720fb66af37a2514f4cdfa9d31959c1850452160 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Thu, 27 Mar 2008 15:49:26 +0000 Subject: [PATCH] Allow searching through keys with a regex, and retrieving the first 354 characters of a website. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@41 088b83a4-0077-4247-935c-42ec02c2848b --- commands.yaml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/commands.yaml b/commands.yaml index e549093..73b1802 100644 --- a/commands.yaml +++ b/commands.yaml @@ -401,8 +401,12 @@ LISTKEYS: |- sub { my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; my $reply = "The following factoids were found: "; - foreach( keys( %{ $heap->{ 'db' } } ) ) { - $reply .= "'$_' "; + my @keys = keys( %{ $heap->{ 'db' } } ); + @keys = sort @keys; + foreach( @keys ) { + if( length( $what ) > 0 && m/^$what/i ) { + $reply .= "'$_' "; + } } $kernel->post( $src, $replypath, $reply, $dest ); } @@ -1472,3 +1476,18 @@ FLUSHURLS: |- $heap->{ 'urls' } = {}; $kernel->post( $src, $replypath, "URL cache flushed.", $dest ); } +GETLINE: |- + sub { + use LWP::Simple; + my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; + if( length( $what ) == 0 ) { + $kernel->post( $src, $replypath, "Usage: GETLINE ", $dest ); + return; + } + my $text = get( $what ); + if( !$text ) { + $kernel->post( $src, $replypath, "Failed to retrieve URL.", $dest ); + return; + } + $kernel->post( $src, $replypath, substr( $text, 0, 354 ), $dest ); + } -- 2.11.0