3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 19:52:34 +01:00

Factoids: fix expansion modifiers

This commit is contained in:
Pragmatic Software 2020-07-18 12:46:44 -07:00
parent 37bc84c79c
commit d6e81a4781

View File

@ -107,8 +107,7 @@ sub get_meta {
} }
sub add_factoid { sub add_factoid {
my $self = shift; my ($self, $type, $channel, $owner, $trigger, $action, $dont_save) = @_;
my ($type, $channel, $owner, $trigger, $action, $dont_save) = @_;
$type = lc $type; $type = lc $type;
$channel = '.*' if $channel !~ /^#/; $channel = '.*' if $channel !~ /^#/;
@ -504,7 +503,7 @@ sub parse_expansion_modifiers {
next; next;
} }
if ($$modifier =~ s/^(enumerate|comma|uc|lc|ucfirst|title)//) { if ($$modifier =~ s/^(enumerate|comma|ucfirst|lcfirst|title|uc|lc)//) {
$settings{$1} = 1; $settings{$1} = 1;
next; next;
} }
@ -794,7 +793,7 @@ sub expand_factoid_vars {
$matches++; $matches++;
# extract channel expansion modifier # extract channel expansion modifier
if ($rest =~ s/^\s*:\s*(#[^:]+|global)//i) { if ($rest =~ s/^:*(#[^:]+|global)//i) {
$from = $1; $from = $1;
$from = '.*' if lc $from eq 'global'; $from = '.*' if lc $from eq 'global';
} }
@ -823,6 +822,8 @@ sub expand_factoid_vars {
goto ALIAS; goto ALIAS;
} }
my %settings = $self->parse_expansion_modifiers(\$rest);
if ($self->{factoids}->get_data($var_chan, $var, 'type') eq 'text') { if ($self->{factoids}->get_data($var_chan, $var, 'type') eq 'text') {
my $change = $self->{factoids}->get_data($var_chan, $var, 'action'); my $change = $self->{factoids}->get_data($var_chan, $var, 'action');
my @list = $self->{pbot}->{interpreter}->split_line($change); my @list = $self->{pbot}->{interpreter}->split_line($change);
@ -844,6 +845,19 @@ sub expand_factoid_vars {
$replacement = $self->expand_factoid_vars($context, $replacement, %opts); $replacement = $self->expand_factoid_vars($context, $replacement, %opts);
} }
if ($settings{'uc'}) { $replacement = uc $replacement; }
if ($settings{'lc'}) { $replacement = lc $replacement; }
if ($settings{'ucfirst'}) { $replacement = ucfirst $replacement; }
if ($settings{'title'}) {
$replacement = ucfirst lc $replacement;
$replacement =~ s/ (\w)/' ' . uc $1/ge;
}
if ($settings{'json'}) { $replacement = $self->escape_json($replacement); }
if ($result =~ s/\b(a|an)(\s+)$//i) { if ($result =~ s/\b(a|an)(\s+)$//i) {
my ($article, $trailing) = ($1, $2); my ($article, $trailing) = ($1, $2);
my $fixed_article = select_indefinite_article $replacement; my $fixed_article = select_indefinite_article $replacement;