3
0
mirror of https://github.com/pragma-/pbot.git synced 2026-03-19 21:58:06 +01:00

Factoids: factfind can now limit search to keywords or contents

This commit is contained in:
Pragmatic Software 2026-03-15 16:08:00 -07:00
parent 1064900f00
commit 0ef979f829
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
3 changed files with 29 additions and 14 deletions

View File

@ -675,9 +675,9 @@ To search the database for a factoid, use the 'factfind` command. You may optio
If there is only one match for the query, it will display that factoid and its text, otherwise it will list all matching keywords.
Usage: `factfind [-channel channel] [-owner nick] [-by nick] [-regex] [text]`
Usage: `factfind [-channel channel] [-owner regex] [-editby regex] [-refby regex] [-keywords] [-contents] [-regex] [text]`
If you specify the `-regex` flag, the `text` argument will be treated as a regex.
If you specify the `-regex` flag, the `text` argument will be treated as a regex. Use `-keywords` or `-contents` to limit the search respectively.
<pragma-> !factfind cast
<PBot> 3 factoids match: [##c] NULL casting dontcastmalloc

View File

@ -892,6 +892,12 @@ sub cmd_factadd($self, $context) {
$from_chan = '.*' if $from_chan !~ /^#/;
$keyword =~ s/^\s+|\s+$//g;
if (!length $keyword) {
return "/say $context->{nick}: Specify a factoid name.";
}
if (length $keyword > $self->{pbot}->{registry}->get_value('factoids', 'max_name_length')) {
return "/say $context->{nick}: I don't think the factoid name needs to be that long.";
}
@ -1239,16 +1245,23 @@ sub quotemeta2($text) {
sub cmd_factfind($self, $context) {
my $arguments = $context->{arguments};
my $usage = "Usage: factfind [-channel channel] [-owner regex] [-editby regex] [-refby regex] [-regex] [text]";
my $usage = "Usage: factfind [-channel channel] [-owner regex] [-editby regex] [-refby regex] [-keywords] [-contents] [-regex] [text]";
return $usage if not length $arguments;
my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my ($channel, $owner, $refby, $editby, $use_regex);
my ($channel, $owner, $refby, $editby, $use_regex, $keywords, $contents);
$channel = $1 if $arguments =~ s/\s*-channel\s+([^\b\s]+)//i;
$owner = $1 if $arguments =~ s/\s*-owner\s+([^\b\s]+)//i;
$refby = $1 if $arguments =~ s/\s*-refby\s+([^\b\s]+)//i;
$editby = $1 if $arguments =~ s/\s*-editby\s+([^\b\s]+)//i;
$use_regex = 1 if $arguments =~ s/\s*-regex\b//i;
$keywords = 1 if $arguments =~ s/\s*-keywords\b//i;
$contents = 1 if $arguments =~ s/\s*-contents\b//i;
if (!$keywords && !$contents) {
$keywords = 1;
$contents = 1;
}
$arguments =~ s/^\s+//;
$arguments =~ s/\s+$//;
@ -1271,14 +1284,10 @@ sub cmd_factfind($self, $context) {
}
if ($arguments ne "") {
my $unquoted_args = $arguments;
$unquoted_args =~ s/(?:\\(?!\\))//g;
$unquoted_args =~ s/(?:\\\\)/\\/g;
if (not defined $argtype) {
$argtype = "containing '$unquoted_args'";
$argtype = "containing '$arguments'";
} else {
$argtype .= " and containing '$unquoted_args'";
$argtype .= " and containing '$arguments'";
}
}
@ -1320,8 +1329,14 @@ sub cmd_factfind($self, $context) {
$match = 1 if $factoid->{edited_by} =~ /^$editby/i;
}
if ($arguments ne "" && ($factoid->{action} =~ /$regex/i || $factoid->{index2} =~ /$regex/i)) {
$match = 1;
if ($arguments ne "") {
if ($keywords && $factoid->{index2} =~ /$regex/i) {
$match = 1;
}
if ($contents && $factoid->{action} =~ /$regex/i) {
$match = 1;
}
}
if ($match) {

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 => 4940,
BUILD_DATE => "2026-03-11",
BUILD_REVISION => 4941,
BUILD_DATE => "2026-03-15",
};
sub initialize {}