# HG changeset patch # User Dominic Cleal # Date 1230232463 0 # Node ID d5872370102ab4d616c70e6164ee21525446a194 # Parent 0f8275723d81b6af730df09ac1b7cb9027b38f74 Sorting !eta output for multiple characters, tidying filtering diff -r 0f8275723d81 -r d5872370102a skillbot.pl --- a/skillbot.pl Tue Dec 23 16:41:59 2008 +0000 +++ b/skillbot.pl Thu Dec 25 19:14:23 2008 +0000 @@ -228,38 +228,46 @@ # lists the current chars in training of the caller if ($msg =~ /^\!eta(\s+(.+))?/i) { my $found = 0; - for my $f (@friends) { - if ((defined $2 && (lc($f->{char}->name) eq lc($2) - || lc($2) eq 'all' || lc($2) eq '*')) - || (!defined $2 && $f->{nick} eq $their_nick)) { - check_friend($self, $f); - my $text; - if (defined $f->{skill}) { - my $downtime = ''; - if (skill_finish_in_downtime($f->{skill})) { - $downtime = ", coincides with downtime"; - } - my $finish = DateTime->from_epoch( - epoch => $f->{skill}->finish_time, - time_zone => $f->{tz}); + my @filtered = + sort { + $a->{skill}->finish_time <=> $b->{skill}->finish_time + } + grep { + ((defined $2 && (lc($_->{char}->name) eq lc($2) + || lc($2) eq 'all' || lc($2) eq '*')) + || (!defined $2 && $_->{nick} eq $their_nick)) + } @friends; - $text = sprintf("Currently training %s %s ". - "(finish in %s, %s %s%s)", - $f->{skill}->name, $f->{skill}->level, - $f->{skill}->time_remaining, - $finish->strftime("%A %R"), - $finish->time_zone_short_name(), - $downtime); - } else { - $text = "No skill currently training"; + for my $f (@filtered) + { + check_friend($self, $f); + my $text; + if (defined $f->{skill}) { + my $downtime = ''; + if (skill_finish_in_downtime($f->{skill})) { + $downtime = ", coincides with downtime"; } - $self->privmsg('#' . $config{channel}, sprintf( - "\002%s:\002 %s", $f->{char}->name, - encode("utf8", $text))); - $found++; + my $finish = DateTime->from_epoch( + epoch => $f->{skill}->finish_time, + time_zone => $f->{tz}); + + $text = sprintf("Currently training %s %s ". + "(finish in %s, %s %s%s)", + $f->{skill}->name, $f->{skill}->level, + $f->{skill}->time_remaining, + $finish->strftime("%A %R"), + $finish->time_zone_short_name(), + $downtime); + } else { + $text = "No skill currently training"; } + + $self->privmsg('#' . $config{channel}, sprintf( + "\002%s:\002 %s", $f->{char}->name, + encode("utf8", $text))); + $found++; } if ($found == 0) {