3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Use descriptive titles instead of keywords in ranking output

This commit is contained in:
Pragmatic Software 2015-02-13 15:36:45 -08:00
parent 2db21dd011
commit 23f2b10ca7

View File

@ -137,13 +137,13 @@ sub print_quickest {
if (lc $command eq 'rank') { if (lc $command eq 'rank') {
my %ranks = ( my %ranks = (
correct => { sort => \&sort_correct, print => \&print_correct }, correct => { sort => \&sort_correct, print => \&print_correct, title => 'correct answers' } ,
wrong => { sort => \&sort_wrong, print => \&print_wrong }, wrong => { sort => \&sort_wrong, print => \&print_wrong, title => 'wrong answers' } ,
quickest => { sort => \&sort_quickest, print => \&print_quickest }, quickest => { sort => \&sort_quickest, print => \&print_quickest, title => 'quickest answer' } ,
ratio => { sort => \&sort_ratio, print => \&print_ratio }, ratio => { sort => \&sort_ratio, print => \&print_ratio, title => 'correct/wrong ratio' } ,
correctstreak => { sort => \&sort_correctstreak, print => \&print_correctstreak }, correctstreak => { sort => \&sort_correctstreak, print => \&print_correctstreak, title => 'correct answer streak' } ,
wrongstreak => { sort => \&sort_wrongstreak, print => \&print_wrongstreak }, wrongstreak => { sort => \&sort_wrongstreak, print => \&print_wrongstreak, title => 'wrong answer streak' } ,
hints => { sort => \&sort_hints, print => \&print_hints }, hints => { sort => \&sort_hints, print => \&print_hints, title => 'hints used' } ,
); );
if (not defined $opt) { if (not defined $opt) {
@ -162,6 +162,7 @@ if (lc $command eq 'rank') {
if (not exists $ranks{$opt}) { if (not exists $ranks{$opt}) {
my $player_id = $scores->get_player_id($opt, $channel, 1); my $player_id = $scores->get_player_id($opt, $channel, 1);
my $player_nick = $scores->get_player_data($player_id, 'nick');
if (not defined $player_id) { if (not defined $player_id) {
print "I don't know anybody named $opt\n"; print "I don't know anybody named $opt\n";
@ -176,17 +177,26 @@ if (lc $command eq 'rank') {
@$players = sort $sort_method @$players; @$players = sort $sort_method @$players;
my $rank = 0; my $rank = 0;
my $stats;
foreach my $player (@$players) { foreach my $player (@$players) {
$rank++ if defined $ranks{$key}->{print}->($player); next if $player->{nick} eq 'keep2play';
$stats = $ranks{$key}->{print}->($player);
$rank++ if defined $stats;
last if lc $player->{nick} eq $opt; last if lc $player->{nick} eq $opt;
} }
if ($rank == 0) { if ($rank == 0) {
push @rankings, "$key: N/A"; push @rankings, "$key: N/A";
} else { } else {
push @rankings, "$key: #$rank"; $stats =~ s/[^:]+:\s+//;
push @rankings, "$ranks{$key}->{title}: #$rank ($stats)";
} }
} }
if (lc $nick ne $opt) {
print "$player_nick->{nick}'s rankings: "
} else {
print "Your rankings: "
}
print join ', ', @rankings; print join ', ', @rankings;
print "\n"; print "\n";
@ -200,6 +210,7 @@ if (lc $command eq 'rank') {
my @ranking; my @ranking;
foreach my $player (@$players) { foreach my $player (@$players) {
next if $player->{nick} eq 'keep2play';
my $entry = $ranks{$opt}->{print}->($player); my $entry = $ranks{$opt}->{print}->($player);
push @ranking, $entry if defined $entry; push @ranking, $entry if defined $entry;
last if scalar @ranking >= 15; last if scalar @ranking >= 15;
@ -208,6 +219,7 @@ if (lc $command eq 'rank') {
if (not scalar @ranking) { if (not scalar @ranking) {
print "No rankings available for $channel yet.\n"; print "No rankings available for $channel yet.\n";
} else { } else {
print "Rankings for $ranks{$opt}->{title}: ";
print join ', ', @ranking; print join ', ', @ranking;
print "\n"; print "\n";
} }