Mercurial > hg > skillbot
comparison skillbot.pl @ 53:d5872370102a
Sorting !eta output for multiple characters, tidying filtering
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Thu, 25 Dec 2008 19:14:23 +0000 |
parents | 0f8275723d81 |
children | 9ed1e53a8d3e |
comparison
equal
deleted
inserted
replaced
52:0f8275723d81 | 53:d5872370102a |
---|---|
226 my ($their_nick, $msg) = ($event->nick, $event->args); | 226 my ($their_nick, $msg) = ($event->nick, $event->args); |
227 | 227 |
228 # lists the current chars in training of the caller | 228 # lists the current chars in training of the caller |
229 if ($msg =~ /^\!eta(\s+(.+))?/i) { | 229 if ($msg =~ /^\!eta(\s+(.+))?/i) { |
230 my $found = 0; | 230 my $found = 0; |
231 for my $f (@friends) { | 231 |
232 if ((defined $2 && (lc($f->{char}->name) eq lc($2) | 232 my @filtered = |
233 || lc($2) eq 'all' || lc($2) eq '*')) | 233 sort { |
234 || (!defined $2 && $f->{nick} eq $their_nick)) { | 234 $a->{skill}->finish_time <=> $b->{skill}->finish_time |
235 check_friend($self, $f); | 235 } |
236 my $text; | 236 grep { |
237 if (defined $f->{skill}) { | 237 ((defined $2 && (lc($_->{char}->name) eq lc($2) |
238 my $downtime = ''; | 238 || lc($2) eq 'all' || lc($2) eq '*')) |
239 if (skill_finish_in_downtime($f->{skill})) { | 239 || (!defined $2 && $_->{nick} eq $their_nick)) |
240 $downtime = ", coincides with downtime"; | 240 } @friends; |
241 } | 241 |
242 | 242 for my $f (@filtered) |
243 my $finish = DateTime->from_epoch( | 243 { |
244 epoch => $f->{skill}->finish_time, | 244 check_friend($self, $f); |
245 time_zone => $f->{tz}); | 245 my $text; |
246 | 246 if (defined $f->{skill}) { |
247 $text = sprintf("Currently training %s %s ". | 247 my $downtime = ''; |
248 "(finish in %s, %s %s%s)", | 248 if (skill_finish_in_downtime($f->{skill})) { |
249 $f->{skill}->name, $f->{skill}->level, | 249 $downtime = ", coincides with downtime"; |
250 $f->{skill}->time_remaining, | |
251 $finish->strftime("%A %R"), | |
252 $finish->time_zone_short_name(), | |
253 $downtime); | |
254 } else { | |
255 $text = "No skill currently training"; | |
256 } | 250 } |
257 | 251 |
258 $self->privmsg('#' . $config{channel}, sprintf( | 252 my $finish = DateTime->from_epoch( |
259 "\002%s:\002 %s", $f->{char}->name, | 253 epoch => $f->{skill}->finish_time, |
260 encode("utf8", $text))); | 254 time_zone => $f->{tz}); |
261 $found++; | 255 |
256 $text = sprintf("Currently training %s %s ". | |
257 "(finish in %s, %s %s%s)", | |
258 $f->{skill}->name, $f->{skill}->level, | |
259 $f->{skill}->time_remaining, | |
260 $finish->strftime("%A %R"), | |
261 $finish->time_zone_short_name(), | |
262 $downtime); | |
263 } else { | |
264 $text = "No skill currently training"; | |
262 } | 265 } |
266 | |
267 $self->privmsg('#' . $config{channel}, sprintf( | |
268 "\002%s:\002 %s", $f->{char}->name, | |
269 encode("utf8", $text))); | |
270 $found++; | |
263 } | 271 } |
264 | 272 |
265 if ($found == 0) { | 273 if ($found == 0) { |
266 $self->privmsg('#' . $config{channel}, "No characters found"); | 274 $self->privmsg('#' . $config{channel}, "No characters found"); |
267 } | 275 } |