diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index bc0a0d62..a0f00fce 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -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}"); } } diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index e0c843f3..a9251a44 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -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");