3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 05:49:27 +01:00

Plugins/Date: now accepts -u to override user account for timezone setting

This commit is contained in:
Pragmatic Software 2020-01-29 12:40:45 -08:00
parent 43f2c38863
commit 7c467a78fa

View File

@ -14,6 +14,7 @@ use strict;
use feature 'unicode_strings'; use feature 'unicode_strings';
use Getopt::Long qw(GetOptionsFromString);
use Carp (); use Carp ();
sub new { sub new {
@ -39,11 +40,36 @@ sub unload {
sub datecmd { sub datecmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $usage = "date [-u <user account>] [timezone]";
Getopt::Long::Configure("bundling");
my $getopt_error;
local $SIG{__WARN__} = sub {
$getopt_error = shift;
chomp $getopt_error;
};
my ($user_override, $show_usage);
my ($ret, $args) = GetOptionsFromString($arguments,
'u=s' => \$user_override,
'h' => \$show_usage
);
return $usage if $show_usage;
return "/say $getopt_error -- $usage" if defined $getopt_error;
$arguments = "@$args";
my $hostmask = defined $user_override ? $user_override : "$nick!$user\@$host";
my $tz_override = $self->{pbot}->{users}->get_loggedin_user_metadata($from, $hostmask, 'timezone') // '';
my $timezone = $self->{pbot}->{registry}->get_value('date', 'default_timezone') // 'UTC'; my $timezone = $self->{pbot}->{registry}->get_value('date', 'default_timezone') // 'UTC';
my $tz_override = $self->{pbot}->{users}->get_loggedin_user_metadata($from, "$nick!$user\@$host", 'timezone');
$timezone = $tz_override if $tz_override; $timezone = $tz_override if $tz_override;
$timezone = $arguments if length $arguments; $timezone = $arguments if length $arguments;
if (defined $user_override and not length $tz_override) {
return "No timezone set or user account does not exist.";
}
my $newstuff = { my $newstuff = {
from => $from, nick => $nick, user => $user, host => $host, from => $from, nick => $nick, user => $user, host => $host,
command => "date_module $timezone", root_channel => $from, root_keyword => "date_module", command => "date_module $timezone", root_channel => $from, root_keyword => "date_module",