diff options
author | David Phillips <david@sighup.nz> | 2018-04-10 15:06:10 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-04-10 15:06:29 +1200 |
commit | bb1808b1ef92af9a14a073f2e14973ac132b7e7e (patch) | |
tree | 5cf3fb9174e07242ed258ae327d3506df1a5355c /plugin/timezone.pm | |
parent | 5aad7b27d5145d4f459ab36d3ffe4a576d3f4ea6 (diff) | |
download | idalius-bb1808b1ef92af9a14a073f2e14973ac132b7e7e.tar.xz |
Add command modules, map command
Diffstat (limited to 'plugin/timezone.pm')
-rw-r--r-- | plugin/timezone.pm | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/plugin/timezone.pm b/plugin/timezone.pm index ecbbd73..8807d54 100644 --- a/plugin/timezone.pm +++ b/plugin/timezone.pm @@ -11,30 +11,30 @@ my %config; sub configure { my $self = $_[0]; - my $cref = $_[1]; + my $cmdref = $_[1]; + my $cref = $_[2]; %config = %$cref; + + $cmdref->("time", sub { $self->time(@_); } ); + return $self; } -sub message { - my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_; - - my $requester = ( split /!/, $who )[0]; +sub time { + my ($self, $logger, $who, $where, $rest, @arguments) = @_; + my $requester = ( split /!/, $who)[0]; my @known_zones = (keys %{$config{timezone}}); - 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 "$requester: $nick\'s clock reads $d"; - } else { - return "$requester: I don't know what timezone $nick is in"; - } - } else { - return "$requester: Syntax: %time [nick]"; - } + + return "Syntax: time [nick]" unless @arguments == 1; + + my $nick = $arguments[0]; + if (grep {$_ eq $nick} @known_zones) { + my $d = DateTime->now(); + $d->set_time_zone($config{timezone}->{$nick}); + return "$requester: $nick\'s clock reads $d"; + } else { + return "$requester: I don't know what timezone $nick is in"; } } 1; |