3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-17 01:19:31 +01:00

Plugin/Date: use existing context when launching date applet

This preserves the pipe/cmd-substitution/etc to allow post-processing
of the `date` output.

Interpreter: Reset `interpreted` contextual metadata when handling
result to allow recursion for continued command processing.
This commit is contained in:
Pragmatic Software 2024-11-05 23:57:48 -08:00
parent 7f49321e29
commit 54ef6b14ce
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
4 changed files with 14 additions and 16 deletions

View File

@ -96,7 +96,9 @@ sub launch_applet($self, $context) {
my $start = gettimeofday; my $start = gettimeofday;
$self->{pbot}->{logger}->log("Starting applet run @cmdline\n"); $self->{pbot}->{logger}->log("Starting applet run @cmdline\n");
run \@cmdline, \$stdin, \$stdout, \$stderr, timeout($timeout); run \@cmdline, \$stdin, \$stdout, \$stderr, timeout($timeout);
my $duration = sprintf "%0.3f", gettimeofday - $start; my $duration = sprintf "%0.3f", gettimeofday - $start;
$self->{pbot}->{logger}->log("Finished applet run @cmdline; duration: $duration\n"); $self->{pbot}->{logger}->log("Finished applet run @cmdline; duration: $duration\n");

View File

@ -585,9 +585,12 @@ sub interpret($self, $context) {
# sends final command output to appropriate queues. # sends final command output to appropriate queues.
# use context result if no result argument given. # use context result if no result argument given.
sub handle_result($self, $context, $result = $context->{result}) { sub handle_result($self, $context, $result = $context->{result}) {
# condensation of consecutive whitespace is disable by default # condensation of consecutive whitespace is disabled by default
$context->{'condense-whitespace'} //= 0; $context->{'condense-whitespace'} //= 0;
# reset interpreted to allow pipes/command-substitutions to finish
delete $context->{'interpreted'};
# debug flag to trace $context location and contents # debug flag to trace $context location and contents
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
use Data::Dumper; use Data::Dumper;

View File

@ -78,23 +78,16 @@ sub cmd_date($self, $context) {
return "No timezone set or user account does not exist."; return "No timezone set or user account does not exist.";
} }
# execute `date_applet` # override command fields to execute date_applet
my $newcontext = { $context->{keyword} = "date_applet";
from => $context->{from}, $context->{command} = "date_applet $timezone";
nick => $context->{nick}, $context->{arguments} = $timezone;
user => $context->{user},
host => $context->{host},
hostmask => $context->{hostmask},
command => "date_applet $timezone",
root_channel => $context->{from},
root_keyword => "date_applet",
keyword => "date_applet",
arguments => "$timezone",
};
# tell Interpreter::interpret() that this command has been interpreted
$context->{interpreted} = 1; $context->{interpreted} = 1;
$self->{pbot}->{applets}->execute_applet($newcontext); # fork to execute applet
$self->{pbot}->{applets}->execute_applet($context);
} }
1; 1;

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script # These are set by the /misc/update_version script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 4838, BUILD_REVISION => 4839,
BUILD_DATE => "2024-11-05", BUILD_DATE => "2024-11-05",
}; };