From 4dbb9752708ca966d668022caeb0f3fbe88cec04 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 9 Apr 2018 17:38:38 +1200 Subject: Add prototype timezone functionality --- plugin/timezone.pm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 plugin/timezone.pm (limited to 'plugin') diff --git a/plugin/timezone.pm b/plugin/timezone.pm new file mode 100644 index 0000000..db6bada --- /dev/null +++ b/plugin/timezone.pm @@ -0,0 +1,36 @@ +#!/usr/bin/env perl + +package plugin::timezone; + +use strict; +use warnings; + +use DateTime; + +my %config; + +sub configure { + my $self = $_[0]; + my $cref = $_[1]; + %config = %$cref; + return $self; +} + +sub message { + my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_; + + 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"; + } else { + return "$who_nick: I don't know what timezone $nick is in"; + } + } +} +1; -- cgit v1.1