From 67f53466bc435b976dc1a4dd76fb1ba45b85c55f Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 10 Apr 2018 11:26:22 +1200 Subject: Improve matching in timezone.pm --- plugin/timezone.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'plugin') diff --git a/plugin/timezone.pm b/plugin/timezone.pm index db6bada..39ff3f0 100644 --- a/plugin/timezone.pm +++ b/plugin/timezone.pm @@ -22,14 +22,18 @@ sub message { my $who_nick = ( split /!/, $who )[0]; my @known_zones = (keys %{$config{timezone}}); - if ($what =~ /^%time\s(.+)$/) { - my $nick = $1; - if (grep {$_ eq $nick} @known_zones) { - my $d = DateTime->now(); - $d->set_time_zone($config{timezone}->{$nick}); - return "$who_nick: $nick\'s clock reads $d"; + if ($what =~ /^%time\s/) { + if ($what =~ /^%time\s+(.+?)\s*$/) { + my $nick = $1; + if (grep {$_ eq $nick} @known_zones) { + my $d = DateTime->now(); + $d->set_time_zone($config{timezone}->{$nick}); + return "$who_nick: $nick\'s clock reads $d"; + } else { + return "$who_nick: I don't know what timezone $nick is in"; + } } else { - return "$who_nick: I don't know what timezone $nick is in"; + return "$who_nick: Syntax: %time [nick]"; } } } -- cgit v1.1