From b8c77abd4797a5b9cb305a0e128c32df570acaaa Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 4 Sep 2019 20:18:32 -0700 Subject: [PATCH] Improve and simplify pipe/subcmd logic --- PBot/Commands.pm | 10 ---------- PBot/Factoids.pm | 12 +----------- PBot/Interpreter.pm | 26 +++++++++++--------------- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/PBot/Commands.pm b/PBot/Commands.pm index 66bcd8f2..da0a128a 100644 --- a/PBot/Commands.pm +++ b/PBot/Commands.pm @@ -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}) { diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 74712acf..17980a9a 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -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"); diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index 3a552019..52506918 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -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}) {