3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

Improve handling of /say, etc, in output text

This commit is contained in:
Pragmatic Software 2017-12-04 21:22:19 -08:00
parent 45421aaf30
commit 1378e41c1b
2 changed files with 12 additions and 25 deletions

View File

@ -166,6 +166,8 @@ sub execute_module {
$stuff->{result} = `./$module $stuff->{arguments} 2>> $module-stderr`;
chomp $stuff->{result};
$stuff->{result} = "/say $stuff->{result}";
my $json = encode_json $stuff;
print $writer "$json\n";
exit 0;

View File

@ -275,8 +275,6 @@ sub interpret {
$self->{pbot}->{logger}->log("piping: [$args][$pipe][$rest]\n");
$stuff->{prepend} = '/say ' unless exists $self->{pipe};
$arguments = $args;
if (exists $stuff->{pipe}) {
@ -377,6 +375,12 @@ sub handle_result {
return 0;
}
if ($result =~ s#^(/say|/me) ##) {
$stuff->{prepend} = $1;
} elsif ($result =~ s#^(/msg \S+) ##) {
$stuff->{prepend} = $1;
}
if (exists $stuff->{subcmd}) {
my $command = pop @{$stuff->{subcmd}};
@ -389,28 +393,15 @@ 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) = ($stuff->{pipe}, $stuff->{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");
if ($result =~ s{^(/say |/me )}{}i) {
$stuff->{prepend} = $1;
}
=cut
elsif ($result =~ s{^/msg ([^ ]+) }{}i) {
$stuff->{prepend} = "/msg $1 ";
}
=cut
$stuff->{command} = "$pipe $result$pipe_rest";
$result = $self->interpret($stuff);
$stuff->{result} = $result;
$self->handle_result($stuff, $result);
@ -418,14 +409,8 @@ sub handle_result {
}
if ($stuff->{prepend}) {
# FIXME: do this better
if ($result =~ m{^(/say |/me )}i) {
# } elsif ($result =~ m{^/msg ([^ ]+) }i) {
} elsif ($result =~ m{^/kick }i) {
} else {
$result = "$stuff->{prepend}$result";
$self->{pbot}->{logger}->log("Prepending [$stuff->{prepend}] to result [$result]\n");
}
$result = "$stuff->{prepend} $result";
$self->{pbot}->{logger}->log("Prepending [$stuff->{prepend}] to result [$result]\n");
}
my $original_result = $result;