diff --git a/lib/PBot/Core/Factoids/Interpreter.pm b/lib/PBot/Core/Factoids/Interpreter.pm index b63eb7a4..349b452c 100644 --- a/lib/PBot/Core/Factoids/Interpreter.pm +++ b/lib/PBot/Core/Factoids/Interpreter.pm @@ -95,6 +95,11 @@ sub interpreter($self, $context) { # if multiple channels have this keyword, then ask user to disambiguate if (@chanlist> 1) { + # but only if the bot is explicitly invoked + if (not $context->{addressed}) { + $self->{pbot}->{logger}->log("Factoid found in multiple channels; disregarding disambiguation because bot not explicitly invoked\n"); + return ''; + } return "Factoid `$original_keyword` exists in " . join(', ', @chanlist) . "; use `fact $original_keyword` to choose one."; } @@ -107,7 +112,12 @@ sub interpreter($self, $context) { return $self->interpreter($context); } - # keyword still not found, try regex factoids + # keyword still not found, try regex factoids if the bot was explicitly invoked + if (not $context->{addressed}) { + $self->{pbot}->{logger}->log("No factoid found; disregarding error message because bot not explicitly invoked\n"); + return ''; + } + ($channel, $keyword) = $self->{pbot}->{factoids}->{data}->find( $context->{ref_from} ? $context->{ref_from} : $context->{from}, diff --git a/lib/PBot/Core/Interpreter.pm b/lib/PBot/Core/Interpreter.pm index 2bac88ad..75c6f484 100644 --- a/lib/PBot/Core/Interpreter.pm +++ b/lib/PBot/Core/Interpreter.pm @@ -121,15 +121,18 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma # but for now let's see how this goes and if people can figure it # out with minimal confusion. $command = $cmd_text if not length $command; + $context->{addressed} = 1; goto CHECK_EMBEDDED_CMD; } # otherwise try to parse any potential commands if ($cmd_text =~ m/^\s*($nick_regex)[,:]?\s+$bot_trigger\{\s*(.+?)\s*\}\s*$/) { # "somenick: !{command}" + $context->{addressed} = 1; goto CHECK_EMBEDDED_CMD; } elsif ($cmd_text =~ m/^\s*$bot_trigger\{\s*(.+?)\s*\}\s*$/) { # "!{command}" + $context->{addressed} = 1; goto CHECK_EMBEDDED_CMD; } elsif ($cmd_text =~ m/^\s*($nick_regex)[,:]\s+$bot_trigger\s*(.+)$/) { # "somenick: !command" @@ -146,15 +149,27 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma $self->{pbot}->{logger}->log("No similar nick for $possible_nick_prefix; disregarding command.\n"); return 0; } + $context->{addressed} = 1; } elsif ($cmd_text =~ m/^$bot_trigger\s*(.+)$/) { # "!command" $command = $1; - } elsif ($cmd_text =~ m/^.?\s*$botnick\s*[[:punct:]]?\s+(.+)$/i) { + $context->{addressed} = 1; + } elsif ($cmd_text =~ m/^.?\s*$botnick\s*[,:]\s+(.+)$/i) { # "botnick: command" $command = $1; - } elsif ($cmd_text =~ m/^(.+?),?\s+$botnick[?!.]*$/i) { + $context->{addressed} = 1; + } elsif ($cmd_text =~ m/^.?\s*$botnick\s+(.+)$/i) { + # "botnick command" + $command = $1; + $context->{addressed} = 0; + } elsif ($cmd_text =~ m/^(.+?),\s+$botnick[?!.]*$/i) { # "command, botnick?" $command = $1; + $context->{addressed} = 1; + } elsif ($cmd_text =~ m/^(.+?)\s+$botnick[?!.]*$/i) { + # "command botnick?" + $command = $1; + $context->{addressed} = 0; } # check for embedded commands diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index db00ccd8..acc8deff 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4686, - BUILD_DATE => "2023-09-21", + BUILD_REVISION => 4687, + BUILD_DATE => "2023-09-23", }; sub initialize {}