3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +01:00

Factoids: look-up use_output_queue/preserve_whitespace properly

This commit is contained in:
Pragmatic Software 2021-09-10 11:03:20 -07:00
parent eba5766865
commit 74401977e1
4 changed files with 24 additions and 32 deletions

View File

@ -1112,8 +1112,12 @@ sub cmd_factfind {
my $unquoted_args = $arguments;
$unquoted_args =~ s/(?:\\(?!\\))//g;
$unquoted_args =~ s/(?:\\\\)/\\/g;
if (not defined $argtype) { $argtype = "containing '$unquoted_args'"; }
else { $argtype .= " and containing '$unquoted_args'"; }
if (not defined $argtype) {
$argtype = "containing '$unquoted_args'";
} else {
$argtype .= " and containing '$unquoted_args'";
}
}
if (not defined $argtype) { return $usage; }
@ -1128,8 +1132,10 @@ sub cmd_factfind {
eval {
use re::engine::RE2 -strict => 1;
my $regex;
if ($use_regex) { $regex = $arguments; }
else {
if ($use_regex) {
$regex = $arguments;
} else {
$regex = ($arguments =~ m/^\w/) ? '\b' : '\B';
$regex .= quotemeta $arguments;
$regex .= ($arguments =~ m/\w$/) ? '\b' : '\B';

View File

@ -219,6 +219,16 @@ sub interpreter {
return $usage;
}
# turn on context->{use_output_queue}?
if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'use_output_queue')) {
$context->{use_output_queue} = 1;
}
# turn on context->{preserve_whitespace}?
if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'preserve_whitespace')) {
$context->{preserve_whitespace} = 1;
}
# tell PBot::Core::Interpreter to prepend caller's nick to output
if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'add_nick')) {
$context->{add_nick} = 1;

View File

@ -663,30 +663,6 @@ sub handle_result {
# nothing more to do here if we have no result or keyword
return 0 if not length $result or not exists $context->{keyword};
# set preserve_whitespace and use_output_queue
# TODO: this should be in Factoids.pm and update $context's flags
my $use_output_queue = 0;
if (not $self->{pbot}->{commands}->exists($context->{keyword})) {
my @factoids = $self->{pbot}->{factoids}->{data}->find($context->{from}, $context->{keyword},
arguments => $context->{arguments},
exact_channel => 0,
exact_trigger => 0,
find_alias => 1
);
if (@factoids == 1) {
my ($chan, $trigger) = ($factoids[0]->[0], $factoids[0]->[1]);
if ($context->{preserve_whitespace} == 0) {
$context->{preserve_whitespace} = $self->{pbot}->{factoids}->{data}->{storage}->get_data($chan, $trigger, 'preserve_whitespace') // 0;
}
$use_output_queue = $self->{pbot}->{factoids}->{data}->{storage}->get_data($chan, $trigger, 'use_output_queue') // 0;
}
}
my $preserve_newlines = $self->{pbot}->{registry}->get_value($context->{from}, 'preserve_newlines');
my $original_result = $result;
@ -711,7 +687,7 @@ sub handle_result {
my $message = "And that's all I have to say about that. See $link for full text.";
if ($use_output_queue) {
if ($context->{use_output_queue}) {
my $message = {
nick => $context->{nick},
user => $context->{user},
@ -732,7 +708,7 @@ sub handle_result {
last;
}
if ($use_output_queue) {
if ($context->{use_output_queue}) {
my $delay = rand(10) + 5;
my $message = {
nick => $context->{nick},

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4382,
BUILD_DATE => "2021-09-08",
BUILD_REVISION => 4384,
BUILD_DATE => "2021-09-10",
};
sub initialize {}