3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 19:52:34 +01:00

Factoid rate-limit no longer affects factoids piped/substituted/splitted within the same command

This commit is contained in:
Pragmatic Software 2020-05-02 23:49:29 -07:00
parent aee7f706c7
commit 33f8c5aeab
2 changed files with 14 additions and 15 deletions

View File

@ -870,19 +870,16 @@ sub interpreter {
}
}
if ($self->{factoids}->exists($channel, $keyword, 'last_referenced_on')) {
if ($self->{factoids}->exists($channel, $keyword, 'last_referenced_in')) {
if ($self->{factoids}->get_data($channel, $keyword, 'last_referenced_in') eq $context->{from}) {
my $ratelimit = $self->{pbot}->{registry}->get_value($context->{from}, 'ratelimit_override');
$ratelimit = $self->{factoids}->get_data($channel, $keyword, 'rate_limit') if not defined $ratelimit;
if (gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) {
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
return
"/msg $context->{nick} $ref_from'$trigger_name' is rate-limited; try again in "
. duration($ratelimit - int(gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on'))) . "."
unless $self->{pbot}->{users}->loggedin_admin($channel, "$context->{nick}!$context->{user}\@$context->{host}");
}
}
$self->{pbot}->{logger}->log("$keyword $context->{interpret_depth}\n");
if ($context->{interpret_depth} <= 1 and $self->{factoids}->get_data($channel, $keyword, 'last_referenced_in') eq $context->{from}) {
my $ratelimit = $self->{pbot}->{registry}->get_value($context->{from}, 'ratelimit_override');
$ratelimit = $self->{factoids}->get_data($channel, $keyword, 'rate_limit') if not defined $ratelimit;
if (gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) {
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
return
"/msg $context->{nick} $ref_from'$trigger_name' is rate-limited; try again in "
. duration($ratelimit - int(gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on'))) . "."
unless $self->{pbot}->{users}->loggedin_admin($channel, "$context->{nick}!$context->{user}\@$context->{host}");
}
}

View File

@ -154,7 +154,7 @@ sub process_line {
}
$context->{referenced} = $embedded;
$context->{interpret_depth} = 1;
$context->{interpret_depth} = 0;
$context->{preserve_whitespace} = $preserve_whitespace;
$context->{result} = $self->interpret($context);
@ -170,6 +170,8 @@ sub interpret {
my $text;
my $pbot = $self->{pbot};
$context->{interpret_depth}++;
$pbot->{logger}->log("=== [$context->{interpret_depth}] Got command: ("
. (defined $context->{from} ? $context->{from} : "undef")
. ") $context->{nick}!$context->{user}\@$context->{host}: $context->{command}\n");
@ -183,7 +185,7 @@ sub interpret {
$self->{pbot}->{logger}->log(Dumper $context);
}
return "Too many levels of recursion, aborted." if (++$context->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion'));
return "Too many levels of recursion, aborted." if ($context->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion'));
if (not defined $context->{nick} || not defined $context->{user} || not defined $context->{host} || not defined $context->{command}) {
$pbot->{logger}->log("Error 1, bad parameters to interpret_command\n");