aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Timezone.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Plugin/Timezone.pm')
-rw-r--r--Plugin/Timezone.pm40
1 files changed, 40 insertions, 0 deletions
diff --git a/Plugin/Timezone.pm b/Plugin/Timezone.pm
new file mode 100644
index 0000000..eaea907
--- /dev/null
+++ b/Plugin/Timezone.pm
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+
+package Plugin::Timezone;
+
+use strict;
+use warnings;
+
+use DateTime;
+
+my %config;
+
+sub configure {
+ my $self = $_[0];
+ my $cmdref = $_[1];
+ my $cref = $_[2];
+ %config = %$cref;
+
+ $cmdref->("time", sub { $self->time(@_); } );
+
+ return $self;
+}
+
+sub time {
+ my ($self, $logger, $who, $where, $rest, @arguments) = @_;
+
+ my $requester = ( split /!/, $who)[0];
+ my @known_zones = (keys %{$config{timezone}});
+
+ 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;