diff --git a/modules/cjeopardy/cjeopardy_scores.pl b/modules/cjeopardy/cjeopardy_scores.pl index f5bb3531..d84d1ab7 100755 --- a/modules/cjeopardy/cjeopardy_scores.pl +++ b/modules/cjeopardy/cjeopardy_scores.pl @@ -12,7 +12,7 @@ use IRCColors; my $nick = shift @ARGV; my $channel = shift @ARGV; my $command = shift @ARGV; -my $opt = shift @ARGV; +my $opt = join ' ', @ARGV; if ($channel !~ /^#/) { print "Sorry, C Jeopardy must be played in a channel. Feel free to join #cjeopardy.\n"; @@ -146,11 +146,11 @@ if (lc $command eq 'rank') { hints => { sort => \&sort_hints, print => \&print_hints, title => 'hints used' } , ); - if (not defined $opt) { - print "Usage: rank [+-] or rank ; available keywords: "; + if (not $opt) { + print "Usage: rank [-] [offset] or rank [-]; available keywords: "; print join ', ', sort keys %ranks; print ".\n"; - print "For example, to rank by quickest answers in descending order: rank -quickest\n"; + print "Prefixing the keyword or nick with a dash will invert the sort direction for each category. Specifying an offset will start ranking at that offset.\n"; goto END; } @@ -160,6 +160,11 @@ if (lc $command eq 'rank') { $rank_direction = $1; } + my $offset = 1; + if ($opt =~ s/\s+(\d+)$//) { + $offset = $1; + } + if (not exists $ranks{$opt}) { my $player_id = $scores->get_player_id($opt, $channel, 1); my $player_nick = $scores->get_player_data($player_id, 'nick'); @@ -214,15 +219,23 @@ if (lc $command eq 'rank') { @$players = sort $sort_method @$players; my @ranking; + my $i = 0; + $offset--; foreach my $player (@$players) { next if $player->{nick} eq 'keep2play'; + next if $i++ < $offset; my $entry = $ranks{$opt}->{print}->($player); - push @ranking, $entry if defined $entry; + push @ranking, "#$i $entry" if defined $entry; last if scalar @ranking >= 15; } if (not scalar @ranking) { - print "No rankings available for $channel yet.\n"; + if ($offset) { + $offset++; + print "No rankings available for $channel at offset #$offset.\n"; + } else { + print "No rankings available for $channel yet.\n"; + } } else { print "Rankings for $ranks{$opt}->{title}: "; print join ', ', @ranking;