Allow searching through keys with a regex, and retrieving the first 354 characters...
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Thu, 27 Mar 2008 15:49:26 +0000 (15:49 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Thu, 27 Mar 2008 15:49:26 +0000 (15:49 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@41 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml

index e549093..73b1802 100644 (file)
@@ -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 <URL>", $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 );
+  }