3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-04 18:38:47 +02:00

Factoid usage metadata can now interrupt pipes to display usage message as appropriate

This commit is contained in:
Pragmatic Software 2019-06-02 19:30:35 -07:00
parent 838b52f6b5
commit bb08250673
3 changed files with 51 additions and 12 deletions

View File

@ -108,6 +108,16 @@ sub interpreter {
$level = $stuff->{'effective-level'};
}
if (exists $stuff->{pipe_result}) {
my $pipe_result = $stuff->{pipe_result};
if (length $stuff->{arguments}) {
$stuff->{arguments} .= " $pipe_result";
} else {
$stuff->{arguments} = $pipe_result;
}
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($stuff->{arguments});
}
foreach my $ref (@{ $self->{handlers} }) {
if ($ref->{name} eq $keyword) {
if ($level >= $ref->{level}) {

View File

@ -806,7 +806,6 @@ sub interpreter {
$self->{pbot}->{logger}->log(Dumper $stuff);
}
#$self->{pbot}->{logger}->log("enter factoid interpreter [$keyword][" . (defined $arguments ? $arguments : '') . "] referenced = $referenced\n");
return undef if not length $stuff->{keyword} or $stuff->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion');
$stuff->{from} = lc $stuff->{from};
@ -937,6 +936,21 @@ sub interpreter {
my $action;
if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{usage} and not length $stuff->{arguments}) {
$stuff->{alldone} = 1;
return $self->{factoids}->hash->{$channel}->{$keyword}->{usage};
}
if (exists $stuff->{pipe_result}) {
my $pipe_result = $stuff->{pipe_result};
if (length $stuff->{arguments}) {
$stuff->{arguments} .= " $pipe_result";
} else {
$stuff->{arguments} = $pipe_result;
}
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($stuff->{arguments});
}
if (length $stuff->{arguments} and exists $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args}) {
$action = $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args};
} else {
@ -947,6 +961,7 @@ sub interpreter {
my ($lang, $code) = ($1, $2);
if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{usage} and not length $stuff->{arguments}) {
$stuff->{alldone} = 1;
return $self->{factoids}->hash->{$channel}->{$keyword}->{usage};
}
@ -1014,6 +1029,7 @@ sub handle_action {
# no arguments supplied, replace $args with $nick/$tonick, etc
if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{usage}) {
$action = "/say " . $self->{factoids}->hash->{$channel}->{$keyword}->{usage};
$stuff->{alldone} = 1;
} else {
if ($self->{factoids}->hash->{$channel}->{$keyword}->{'allow_empty_args'}) {
$action = $self->expand_action_arguments($action, undef, '');

View File

@ -308,7 +308,6 @@ sub interpret {
}
$stuff->{keyword} = $keyword;
$stuff->{original_arguments} = $arguments;
# unescape any escaped substituted commands
$arguments =~ s/\\&\s*\{/&{/g if defined $arguments;
@ -320,12 +319,21 @@ sub interpret {
# set arguments as a plain string
$stuff->{arguments} = $arguments;
$stuff->{original_arguments} = $arguments;
# set arguments as an array
$stuff->{arglist} = $self->make_args($arguments);
# handle this shit
return $self->SUPER::execute_all($stuff);
# execute all registered interpreters
my $result;
foreach my $func (@{$self->{handlers}}) {
$result = &{$func->{subref}}($stuff);
last if defined $result;
# reset any manipulated arguments
$stuff->{arguments} = $stuff->{original_arguments};
}
return $result;
}
# extracts a bracketed substring, gracefully handling unbalanced quotes
@ -752,16 +760,18 @@ sub handle_result {
if (exists $stuff->{subcmd}) {
my $command = pop @{$stuff->{subcmd}};
if (@{$stuff->{subcmd}} == 0) {
if (@{$stuff->{subcmd}} == 0 or $stuff->{alldone}) {
delete $stuff->{subcmd};
}
$command =~ s/&\{subcmd\}/$result/;
$stuff->{command} = $command;
$result = $self->interpret($stuff);
$stuff->{result}= $result;
$self->{pbot}->{logger}->log("subcmd result [$result]\n");
if (not $stuff->{alldone}) {
$stuff->{command} = $command;
$result = $self->interpret($stuff);
$stuff->{result}= $result;
$self->{pbot}->{logger}->log("subcmd result [$result]\n");
}
$self->handle_result($stuff);
return 0;
}
@ -769,9 +779,12 @@ sub handle_result {
if ($stuff->{pipe} and not $stuff->{authorized}) {
my ($pipe, $pipe_rest) = (delete $stuff->{pipe}, delete $stuff->{pipe_rest});
$self->{pbot}->{logger}->log("Handling pipe [$result][$pipe][$pipe_rest]\n");
$stuff->{command} = "$pipe $result$pipe_rest";
$result = $self->interpret($stuff);
$stuff->{result} = $result;
$stuff->{pipe_result} = $result;
if (not $stuff->{alldone}) {
$stuff->{command} = "$pipe$pipe_rest";
$result = $self->interpret($stuff);
$stuff->{result} = $result;
}
$self->handle_result($stuff, $result);
return 0;
}