Skip to content

Commit

Permalink
'assign rotor': Allow /force to override unavailability
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfsage committed Aug 25, 2020
1 parent 3c1b9a8 commit 49b2553
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/Synergy/Reactor/Rototron.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,21 @@ after register_with_hub => sub ($self, @) {
};

sub handle_manual_assignment ($self, $event) {
my ($username, $rotor_name, $from, $to);
my ($username, $rotor_name, $from, $to, $force);

my $ymd_re = qr{ [0-9]{4} - [0-9]{2} - [0-9]{2} }x;
if ($event->text =~ /^assign rotor (\S+) to (\S+) on ($ymd_re)\z/) {
if ($event->text =~ /^assign rotor (\S+) to (\S+) on ($ymd_re) (\/f(?:orce))?\z/) {
$rotor_name = $1;
$username = $2;
$from = parse_date_for_user($3, $event->from_user);
$to = parse_date_for_user($3, $event->from_user);
} elsif ($event->text =~ /^assign rotor (\S+) to (\S+) from ($ymd_re) to ($ymd_re)\z/) {
$force = $4;
} elsif ($event->text =~ /^assign rotor (\S+) to (\S+) from ($ymd_re) to ($ymd_re) (\/f(?:orce))?\z/) {
$rotor_name = $1;
$username = $2;
$from = parse_date_for_user($3, $event->from_user);
$to = parse_date_for_user($4, $event->from_user);
$force = $5;
} else {
return;
}
Expand Down Expand Up @@ -164,24 +166,34 @@ sub handle_manual_assignment ($self, $event) {
my (@okay, @errors);

for my $date (@dates) {
my $debug = [];
if ($self->availability_checker->user_is_available_on($assign_to, $date, $debug)) {
push @okay, $date;
if ($force) {
# Remove any 'unavailable on' overrides
$self->availability_checker->set_user_available_on(
$assign_to,
$date,
);
} else {
push @errors, @$debug;
my $debug = [];
if ($self->availability_checker->user_is_available_on($assign_to, $date, $debug)) {
push @okay, $date;
} else {
push @errors, @$debug;
}
}
}

@dates = @okay;

unless (@dates) {
$event->reply("$username was not available for any of those dates:\n" . join("\n", @errors));
$event->reply("retry with /force at the end to override");

return;
}

if (@errors) {
$event->reply("$username was not available for these dates:\n" . join("\n", @errors));
$event->reply("retry with /force at the end to override");
}

$self->availability_checker->update_manual_assignments({
Expand Down

0 comments on commit 49b2553

Please sign in to comment.