From: pdbogen Date: Fri, 26 Sep 2008 15:33:11 +0000 (+0000) Subject: SnipURL is doing weird stuff. Also, add the ability to fetch the top/bottom N karmas. X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=56f674cb2518b8632c0c36b41a0e4cdad153c7a0;p=destult.git SnipURL is doing weird stuff. Also, add the ability to fetch the top/bottom N karmas. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@61 088b83a4-0077-4247-935c-42ec02c2848b --- diff --git a/commands.yaml b/commands.yaml index d36f09a..e8c3805 100644 --- a/commands.yaml +++ b/commands.yaml @@ -1533,12 +1533,12 @@ SHORTEN: |- my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; my( $service, $url ) = split( / /, $what, 2 ); if( !defined( $service ) ) { - $kernel->post( $src, $replypath, "USAGE: SHORTEN [] , where is one of (potentially) BabyURL, Linkz, MakeAShorterLink, Metamark, NotLong, OneShortLink, Shorl, SnipURL*, TinyClick, TinyLink, or TinyURL. (* designates the default service.) Many of these do not work.", $dest ); + $kernel->post( $src, $replypath, "USAGE: SHORTEN [] , where is one of (potentially) BabyURL, Linkz, MakeAShorterLink, Metamark, NotLong, OneShortLink, Shorl, SnipURL, TinyClick, TinyLink, or TinyURL*. (* designates the default service.) Many of these do not work.", $dest ); return; } if( !defined( $url ) ) { $url = $service; - $service = "SnipURL"; + $service = "TinyURL"; } $service =~ s/[^a-z]//gi; eval "use WWW::Shorten::$service"; @@ -1627,13 +1627,42 @@ KARMA: |- if( -e "karma.yaml" ) { $heap->{ "karma" } = LoadFile( "karma.yaml" ); } else { - $kernel->post( $src, $replypath, "$what has no karma.", $dest ); + $kernel->post( $src, $replypath, "Karma has begun anew.", $dest ); return; } } - if( exists( $heap->{ "karma" }->{ uc( $what ) } ) ) { - $kernel->post( $src, $replypath, "$what has ".$heap->{ "karma" }->{ uc( $what ) }." karma", $dest ); + if( $what =~ /^([+-])([1-9][0-9]*)$/ ) { + my $target = $2; + my $thresh = 0; + my $tItem = 0; + my $mult = ($1 eq "-"?-1:1); + my @response; + my %karma = %{ $heap->{ "karma" } }; + + for( my $i = 0; $i < $target; $i++ ) { + push @response, [0,""]; + } + + for my $key (keys %karma) { + INNER: + for( my $i = 0; $i < $target; $i++ ) { + if( $response[ $i ]->[0]*$mult < $karma{ $key }*$mult ) { + $response[ $i ] = [ $karma{ $key }, $key ]; + last INNER; + } + } + } + @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].")"; + } + $kernel->post( $src, $replypath, ($mult eq "-1"?"Bottom":"Top")." $target: $resp", $dest ); } else { - $kernel->post( $src, $replypath, "$what has no karma.", $dest ); + if( exists( $heap->{ "karma" }->{ uc( $what ) } ) ) { + $kernel->post( $src, $replypath, "$what has ".$heap->{ "karma" }->{ uc( $what ) }." karma", $dest ); + } else { + $kernel->post( $src, $replypath, "$what has no karma.", $dest ); + } } }