3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 20:09:43 +01:00

Improve and simplify pipe/subcmd logic

This commit is contained in:
Pragmatic Software 2019-09-04 20:18:32 -07:00
parent bc1cc61d06
commit b8c77abd47
3 changed files with 12 additions and 36 deletions

View File

@ -109,16 +109,6 @@ 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

@ -873,16 +873,6 @@ sub interpreter {
return $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 {
@ -997,7 +987,7 @@ sub handle_action {
if (defined $self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'}) {
if ($self->{factoids}->hash->{$channel}->{$keyword}->{'locked'}) {
$self->{pbot}->{logger}->log("Effective-level set to $self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'}\n");
$self->{pbot}->{logger}->log("Effective-level set to $self->{factoids}->{hash}->{$channel}->{$keyword}->{'effective-level'}\n");
$stuff->{'effective-level'} = $self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'};
} else {
$self->{pbot}->{logger}->log("Ignoring effective-level of $self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'} on unlocked factoid\n");

View File

@ -768,6 +768,17 @@ sub handle_result {
$stuff->{prepend} = $1;
}
if ($stuff->{pipe} and not $stuff->{authorized}) {
my ($pipe, $pipe_rest) = (delete $stuff->{pipe}, delete $stuff->{pipe_rest});
if (not $stuff->{alldone}) {
$stuff->{command} = "$pipe $result $pipe_rest";
$result = $self->interpret($stuff);
$stuff->{result} = $result;
}
$self->handle_result($stuff, $result);
return 0;
}
if (exists $stuff->{subcmd}) {
my $command = pop @{$stuff->{subcmd}};
@ -781,25 +792,11 @@ sub handle_result {
$stuff->{command} = $command;
$result = $self->interpret($stuff);
$stuff->{result}= $result;
$self->{pbot}->{logger}->log("subcmd result [$result]\n");
}
$self->handle_result($stuff);
return 0;
}
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->{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;
}
if ($stuff->{prepend}) {
$result = "$stuff->{prepend} $result";
}
@ -807,7 +804,6 @@ sub handle_result {
if ($stuff->{command_split}) {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
$stuff->{command} = delete $stuff->{command_split};
$self->{pbot}->{logger}->log("Handling split [$result][$stuff->{command}]\n");
$result =~ s#^/say #\n#i;
$result =~ s#^/me #\n* $botnick #i;
if (not length $stuff->{split_result}) {