mirror of
https://github.com/pragma-/pbot.git
synced 2025-10-18 17:17:24 +02:00
Factoids: variable expansions update ref-count and last-referenced
This commit is contained in:
parent
bda93505f3
commit
8f1ac5b5ba
@ -52,6 +52,8 @@ sub expand_factoid_vars($self, $context, $action, %opts) {
|
|||||||
my $result = '';
|
my $result = '';
|
||||||
my $rest = $action;
|
my $rest = $action;
|
||||||
|
|
||||||
|
my $needs_save = 0;
|
||||||
|
|
||||||
while (++$depth < 100) {
|
while (++$depth < 100) {
|
||||||
$rest =~ s/(?<!\\)\$0/$root_keyword/g;
|
$rest =~ s/(?<!\\)\$0/$root_keyword/g;
|
||||||
|
|
||||||
@ -106,6 +108,18 @@ sub expand_factoid_vars($self, $context, $action, %opts) {
|
|||||||
if (@factoids && $factoids[0]) {
|
if (@factoids && $factoids[0]) {
|
||||||
($var_chan, $var) = ($factoids[0]->[0], $factoids[0]->[1]);
|
($var_chan, $var) = ($factoids[0]->[0], $factoids[0]->[1]);
|
||||||
|
|
||||||
|
my $ref_count = $self->{pbot}->{factoids}->{data}->{storage}->get_data($var_chan, $var, 'ref_count');
|
||||||
|
|
||||||
|
my $data = {
|
||||||
|
ref_count => $ref_count + 1,
|
||||||
|
ref_user => $context->{hostmask},
|
||||||
|
last_referenced_in => $context->{from},
|
||||||
|
last_referenced_on => time
|
||||||
|
};
|
||||||
|
|
||||||
|
$self->{pbot}->{factoids}->{data}->{storage}->add($var_chan, $var, $data, 1);
|
||||||
|
$needs_save = 1;
|
||||||
|
|
||||||
if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($var_chan, $var, 'action') =~ m{^/call (.*)}ms) {
|
if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($var_chan, $var, 'action') =~ m{^/call (.*)}ms) {
|
||||||
$var = $1;
|
$var = $1;
|
||||||
|
|
||||||
@ -206,6 +220,11 @@ sub expand_factoid_vars($self, $context, $action, %opts) {
|
|||||||
$replacement = $fixed_article . $trailing . $replacement;
|
$replacement = $fixed_article . $trailing . $replacement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# prevent double-spaces when joining replacement to result
|
||||||
|
if ($result =~ m/ $/ && (!length($replacement) || $replacement =~ m/^ /)) {
|
||||||
|
$result =~ s/ $//;
|
||||||
|
}
|
||||||
|
|
||||||
$result .= $replacement;
|
$result .= $replacement;
|
||||||
|
|
||||||
$expansions++;
|
$expansions++;
|
||||||
@ -229,6 +248,10 @@ sub expand_factoid_vars($self, $context, $action, %opts) {
|
|||||||
# unescape certain symbols
|
# unescape certain symbols
|
||||||
$result =~ s/(?<!\\)\\([\$\:\|])/$1/g;
|
$result =~ s/(?<!\\)\\([\$\:\|])/$1/g;
|
||||||
|
|
||||||
|
if ($needs_save) {
|
||||||
|
$self->{pbot}->{factoids}->{data}->{storage}->save;
|
||||||
|
}
|
||||||
|
|
||||||
return validate_string($result, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
|
return validate_string($result, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -803,7 +803,7 @@ sub remove($self, $index1, $index2 = undef, $data_index = undef, $dont_save = 0)
|
|||||||
return "$name2.$data_index is not set.";
|
return "$name2.$data_index is not set.";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set($self, $index1, $index2, $key = undef, $value = undef) {
|
sub set($self, $index1, $index2, $key = undef, $value = undef, $dont_save = 0) {
|
||||||
if (not $self->exists($index1)) {
|
if (not $self->exists($index1)) {
|
||||||
my $result = "$self->{name}: $index1 not found; similiar matches: ";
|
my $result = "$self->{name}: $index1 not found; similiar matches: ";
|
||||||
$result .= $self->levenshtein_matches($index1);
|
$result .= $self->levenshtein_matches($index1);
|
||||||
@ -862,7 +862,7 @@ sub set($self, $index1, $index2, $key = undef, $value = undef) {
|
|||||||
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $value;
|
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->save;
|
$self->save unless $dont_save;
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($@) {
|
if ($@) {
|
||||||
|
@ -25,8 +25,8 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4892,
|
BUILD_REVISION => 4894,
|
||||||
BUILD_DATE => "2025-09-24",
|
BUILD_DATE => "2025-09-25",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub initialize {}
|
sub initialize {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user