for my $memo( @memos ) {
my @memo = @$memo;
my $t = time - $memo[1];
- my $response;
+ my $response = "";
if( $t > 86400 ) {
$response .= floor($t/86400)."d ";
$t = $t % 86400;
}
$response .= $t."s";
$kernel->post( $src, $replypath, "From: ".$memo[0].", $response ago: ".$memo[2], $dest );
+ print( "MEMO: Delivered from $memo[0] to $who after $response\n" );
}
delete $heap->{ 'memo' }->{ uc( $who ) };
DumpFile( "memos.yaml", $heap->{ 'memo' } );
}
+MEMOLIST: |-
+ sub {
+ my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+ if( !exists( $heap->{ 'memo' } ) ) {
+ $kernel->post( $src, $replypath, "No memos.", $dest );
+ return 0;
+ }
+ if( length $what > 0 ) {
+ if( !exists( $heap->{ "memo" }->{ uc( $what ) } ) ) {
+ $kernel->post( $src, $replypath, "No memos for $what.", $dest );
+ return 0;
+ }
+ my @memos = @{ $heap->{ "memo" }->{ uc( $what ) } };
+ my $i = 0;
+ my $j = scalar @memos;
+ for my $memo (@memos) {
+ my @memo = @$memo;
+ $i++;
+ $kernel->post( $src, $replypath, "($i/$j) From $memo[0] ".(time-$memo[1])."s ago: $memo[2]", $dest );
+ }
+ } else {
+ my $resp = "~MEMOLIST <name> to show user's memos. Users: ";
+ $resp .= join( ", ", keys( %{ $heap->{ "memo" } } ) );
+ $kernel->post( $src, $replypath, $resp, $dest );
+ }
+ }
+
+MEMOWIPE: |-
+ sub {
+ my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+ if( !exists( $heap->{ 'memo' } ) ) {
+ $kernel->post( $src, $replypath, "No memos.", $dest );
+ return 0;
+ }
+ if( length $what > 0 ) {
+ if( !exists( $heap->{ "memo" }->{ uc( $what ) } ) ) {
+ $kernel->post( $src, $replypath, "No memos for $what.", $dest );
+ return 0;
+ }
+ $kernel->post( $src, $replypath, "Poof.", $dest );
+ delete $heap->{ "memo" }->{ uc( $what ) };
+ } else {
+ $kernel->post( $src, $replypath, "Usage: MEMOWIPE <user>", $dest );
+ }
+ }
+
+MEMOMOVE: |-
+ sub {
+ my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+ if( !exists( $heap->{ 'memo' } ) ) {
+ $kernel->post( $src, $replypath, "No memos.", $dest );
+ return 0;
+ }
+ my @args = split( / /, $what );
+ if( scalar @args == 2 ) {
+ if( !exists( $heap->{ "memo" }->{ uc( $args[0] ) } ) ) {
+ $kernel->post( $src, $replypath, "No memos for $args[0].", $dest );
+ return 0;
+ }
+ $kernel->post( $src, $replypath, "Mail forwarded. Eat your heart out, USPS.", $dest );
+ push @{ $heap->{ "memo" }->{ uc( $args[1] ) } }, @{ $heap->{ "memo" }->{ uc( $args[0] ) } };
+ delete $heap->{ "memo" }->{ uc( $args[0] ) };
+ } else {
+ $kernel->post( $src, $replypath, "Usage: MEMOMOVE <from> <to>", $dest );
+ }
+ }
+
MEMO: |-
sub {
my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
return;
}
my( $rec, $msg ) = split( / /, $what, 2 );
+ $rec =~ s/:$//;
+ print( "MEMO: From $who for $rec\n" );
if( !exists( $heap->{ 'memo' } ) ) {
$heap->{ 'memo' } = {};
}
}
}
for my $k( keys %{ $heap->{ "karma" } } ) {
- if( $k =~ /[[:space:]]/ ) {
+ if( $k =~ /[[:space:]]/ || $k =~ /^$/ ) {
delete $heap->{ "karma" }->{ $k };
}
}
my $mult = ($1 eq "-"?-1:1);
my @response;
my %karma = %{ $heap->{ "karma" } };
+ my $count = scalar keys %karma;
+ if( $target > $count ) {
+ $target = $count;
+ }
for( my $i = 0; $i < $target; $i++ ) {
- push @response, [0,""];
+ push @response, [0,undef];
}
for my $key (keys %karma) {
INNER:
for( my $i = 0; $i < $target; $i++ ) {
- if( $response[ $i ]->[0]*$mult < $karma{ $key }*$mult ) {
+ if( !defined( $response[ $i ]->[1] ) || $response[ $i ]->[0]*$mult < $karma{ $key }*$mult ) {
$response[ $i ] = [ $karma{ $key }, $key ];
last INNER;
}