aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-04-09 17:38:38 +1200
committerDavid Phillips <david@sighup.nz>2018-04-09 17:38:38 +1200
commit4dbb9752708ca966d668022caeb0f3fbe88cec04 (patch)
tree361fdac692926666fb0e66a07869bc621407e6b9
parent12884b7556abfd848e42dfb40f6df55fb87c1ef9 (diff)
downloadidalius-4dbb9752708ca966d668022caeb0f3fbe88cec04.tar.xz
Add prototype timezone functionality
-rw-r--r--config_file.pm11
-rw-r--r--plugin/timezone.pm36
2 files changed, 47 insertions, 0 deletions
diff --git a/config_file.pm b/config_file.pm
index 2ad6620..5ee51d8 100644
--- a/config_file.pm
+++ b/config_file.pm
@@ -58,6 +58,16 @@ sub parse_config
$triggers{$match} = $response;
}
+ # special case: timezones hash
+ my %timezone;
+ foreach (split ',', $config->{_}->{timezone}) {
+ my ($who, $tz) = split /=>/;
+ # strip outer quotes
+ $who =~ s/^[^']*'|'[^']*$//g;
+ $tz =~ s/^[^']*'|'[^']*$//g;
+ $timezone{$who} = $tz;
+ }
+
$built_config{uid} = getpwnam($built_config{user})
or die "Cannot get uid of $built_config{user}: $!\n";
$built_config{gid} = getgrnam($built_config{group})
@@ -65,6 +75,7 @@ sub parse_config
$built_config{triggers} = \%triggers;
+ $built_config{timezone} = \%timezone;
return %built_config;
}
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;