my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
my( $service, $url ) = split( / /, $what, 2 );
if( !defined( $service ) ) {
- $kernel->post( $src, $replypath, "USAGE: SHORTEN [<service>] <URL>, where <service> 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 [<service>] <URL>, where <service> 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";
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 );
+ }
}
}