3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 11:59:43 +01:00

Factoids: disregard error messages when not explicitly invoked

This commit is contained in:
Pragmatic Software 2023-09-23 13:52:10 -07:00
parent 53e990bd32
commit 5ffde32d46
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
3 changed files with 30 additions and 5 deletions

View File

@ -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 <channel> $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},

View File

@ -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

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 => 4686,
BUILD_DATE => "2023-09-21",
BUILD_REVISION => 4687,
BUILD_DATE => "2023-09-23",
};
sub initialize {}