mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-23 10:34:52 +01:00
Factoid usage
metadata can now interrupt pipes to display usage message as appropriate
This commit is contained in:
parent
838b52f6b5
commit
bb08250673
@ -108,6 +108,16 @@ sub interpreter {
|
|||||||
$level = $stuff->{'effective-level'};
|
$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} }) {
|
foreach my $ref (@{ $self->{handlers} }) {
|
||||||
if ($ref->{name} eq $keyword) {
|
if ($ref->{name} eq $keyword) {
|
||||||
if ($level >= $ref->{level}) {
|
if ($level >= $ref->{level}) {
|
||||||
|
@ -806,7 +806,6 @@ sub interpreter {
|
|||||||
$self->{pbot}->{logger}->log(Dumper $stuff);
|
$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');
|
return undef if not length $stuff->{keyword} or $stuff->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion');
|
||||||
|
|
||||||
$stuff->{from} = lc $stuff->{from};
|
$stuff->{from} = lc $stuff->{from};
|
||||||
@ -937,6 +936,21 @@ sub interpreter {
|
|||||||
|
|
||||||
my $action;
|
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}) {
|
if (length $stuff->{arguments} and exists $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args}) {
|
||||||
$action = $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args};
|
$action = $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args};
|
||||||
} else {
|
} else {
|
||||||
@ -947,6 +961,7 @@ sub interpreter {
|
|||||||
my ($lang, $code) = ($1, $2);
|
my ($lang, $code) = ($1, $2);
|
||||||
|
|
||||||
if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{usage} and not length $stuff->{arguments}) {
|
if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{usage} and not length $stuff->{arguments}) {
|
||||||
|
$stuff->{alldone} = 1;
|
||||||
return $self->{factoids}->hash->{$channel}->{$keyword}->{usage};
|
return $self->{factoids}->hash->{$channel}->{$keyword}->{usage};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1014,6 +1029,7 @@ sub handle_action {
|
|||||||
# no arguments supplied, replace $args with $nick/$tonick, etc
|
# no arguments supplied, replace $args with $nick/$tonick, etc
|
||||||
if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{usage}) {
|
if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{usage}) {
|
||||||
$action = "/say " . $self->{factoids}->hash->{$channel}->{$keyword}->{usage};
|
$action = "/say " . $self->{factoids}->hash->{$channel}->{$keyword}->{usage};
|
||||||
|
$stuff->{alldone} = 1;
|
||||||
} else {
|
} else {
|
||||||
if ($self->{factoids}->hash->{$channel}->{$keyword}->{'allow_empty_args'}) {
|
if ($self->{factoids}->hash->{$channel}->{$keyword}->{'allow_empty_args'}) {
|
||||||
$action = $self->expand_action_arguments($action, undef, '');
|
$action = $self->expand_action_arguments($action, undef, '');
|
||||||
|
@ -308,7 +308,6 @@ sub interpret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$stuff->{keyword} = $keyword;
|
$stuff->{keyword} = $keyword;
|
||||||
$stuff->{original_arguments} = $arguments;
|
|
||||||
|
|
||||||
# unescape any escaped substituted commands
|
# unescape any escaped substituted commands
|
||||||
$arguments =~ s/\\&\s*\{/&{/g if defined $arguments;
|
$arguments =~ s/\\&\s*\{/&{/g if defined $arguments;
|
||||||
@ -320,12 +319,21 @@ sub interpret {
|
|||||||
|
|
||||||
# set arguments as a plain string
|
# set arguments as a plain string
|
||||||
$stuff->{arguments} = $arguments;
|
$stuff->{arguments} = $arguments;
|
||||||
|
$stuff->{original_arguments} = $arguments;
|
||||||
|
|
||||||
# set arguments as an array
|
# set arguments as an array
|
||||||
$stuff->{arglist} = $self->make_args($arguments);
|
$stuff->{arglist} = $self->make_args($arguments);
|
||||||
|
|
||||||
# handle this shit
|
# execute all registered interpreters
|
||||||
return $self->SUPER::execute_all($stuff);
|
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
|
# extracts a bracketed substring, gracefully handling unbalanced quotes
|
||||||
@ -752,16 +760,18 @@ sub handle_result {
|
|||||||
if (exists $stuff->{subcmd}) {
|
if (exists $stuff->{subcmd}) {
|
||||||
my $command = pop @{$stuff->{subcmd}};
|
my $command = pop @{$stuff->{subcmd}};
|
||||||
|
|
||||||
if (@{$stuff->{subcmd}} == 0) {
|
if (@{$stuff->{subcmd}} == 0 or $stuff->{alldone}) {
|
||||||
delete $stuff->{subcmd};
|
delete $stuff->{subcmd};
|
||||||
}
|
}
|
||||||
|
|
||||||
$command =~ s/&\{subcmd\}/$result/;
|
$command =~ s/&\{subcmd\}/$result/;
|
||||||
|
|
||||||
|
if (not $stuff->{alldone}) {
|
||||||
$stuff->{command} = $command;
|
$stuff->{command} = $command;
|
||||||
$result = $self->interpret($stuff);
|
$result = $self->interpret($stuff);
|
||||||
$stuff->{result}= $result;
|
$stuff->{result}= $result;
|
||||||
$self->{pbot}->{logger}->log("subcmd result [$result]\n");
|
$self->{pbot}->{logger}->log("subcmd result [$result]\n");
|
||||||
|
}
|
||||||
$self->handle_result($stuff);
|
$self->handle_result($stuff);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -769,9 +779,12 @@ sub handle_result {
|
|||||||
if ($stuff->{pipe} and not $stuff->{authorized}) {
|
if ($stuff->{pipe} and not $stuff->{authorized}) {
|
||||||
my ($pipe, $pipe_rest) = (delete $stuff->{pipe}, delete $stuff->{pipe_rest});
|
my ($pipe, $pipe_rest) = (delete $stuff->{pipe}, delete $stuff->{pipe_rest});
|
||||||
$self->{pbot}->{logger}->log("Handling pipe [$result][$pipe][$pipe_rest]\n");
|
$self->{pbot}->{logger}->log("Handling pipe [$result][$pipe][$pipe_rest]\n");
|
||||||
$stuff->{command} = "$pipe $result$pipe_rest";
|
$stuff->{pipe_result} = $result;
|
||||||
|
if (not $stuff->{alldone}) {
|
||||||
|
$stuff->{command} = "$pipe$pipe_rest";
|
||||||
$result = $self->interpret($stuff);
|
$result = $self->interpret($stuff);
|
||||||
$stuff->{result} = $result;
|
$stuff->{result} = $result;
|
||||||
|
}
|
||||||
$self->handle_result($stuff, $result);
|
$self->handle_result($stuff, $result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user