Sort positives differently, and add a command to sanitize the Karma database.
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 15 Oct 2008 05:00:05 +0000 (05:00 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 15 Oct 2008 05:00:05 +0000 (05:00 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@68 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml

index e43884b..7947413 100644 (file)
@@ -1629,6 +1629,26 @@ KARMAUP: |-
     DumpFile( "karma.yaml", $heap->{ 'karma' } );
   }
 
+KARMACLEAN: |-
+  sub {
+    my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+    if( !exists( $heap->{ "karma" } ) ) {
+      if( -e "karma.yaml" ) {
+        $heap->{ "karma" } = LoadFile( "karma.yaml" );
+      } else {
+        $kernel->post( $src, $replypath, "Karma has begun anew.", $dest );
+        return;
+      }
+    }
+    for my $k( keys %{ $heap->{ "karma" } } ) {
+      if( $k =~ /[[:space:]]/ ) {
+        delete $heap->{ "karma" }->{ $k };
+      }
+    }
+    $kernel->post( $src, $replypath, "Squeak squeak.", $dest );
+    DumpFile( "karma.yaml", $heap->{ 'karma' } );
+  }
+
 KARMA: |-
   sub {
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
@@ -1651,7 +1671,7 @@ KARMA: |-
       my $mult = ($1 eq "-"?-1:1);
       my @response;
       my %karma = %{ $heap->{ "karma" } };
-
+  
       for( my $i = 0; $i < $target; $i++ ) {
         push @response, [0,""];
       }
@@ -1665,7 +1685,11 @@ KARMA: |-
           }
         }
       }
-      @response = sort { $a->[0] <=> $b->[0] } @response;
+      if( $mult == 1 ) {
+        @response = sort { $b->[0] <=> $a->[0] } @response;
+      } else {
+        @response = sort { $a->[0] <=> $b->[0] } @response;
+      }
       my $resp = $response[0]->[1]." (".$response[0]->[0].")";
       for( my $i = 1; $i < scalar @response; $i++ ) {
         $resp .= ", ".$response[ $i ]->[1]." (".$response[ $i ]->[0].")";