3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-17 09:29:30 +01:00

FuncBuiltins: add maybe-on

This commit is contained in:
Pragmatic Software 2024-11-05 02:13:39 -08:00
parent ead34c81c9
commit a71f29be1a
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
2 changed files with 43 additions and 4 deletions

View File

@ -105,6 +105,15 @@ sub initialize($self, %conf) {
} }
); );
$self->{pbot}->{functions}->register(
'maybe-on',
{
desc => 'prepend "on" in front of text depending on the part-of-speech of the first word in text',
usage => 'maybe-to <text>',
subref => sub { $self->func_maybe_on(@_) }
}
);
$self->{tagger} = Lingua::EN::Tagger->new; $self->{tagger} = Lingua::EN::Tagger->new;
} }
@ -120,6 +129,7 @@ sub unload($self) {
$self->{pbot}->{functions}->unregister('ana'); $self->{pbot}->{functions}->unregister('ana');
$self->{pbot}->{functions}->unregister('maybe-the'); $self->{pbot}->{functions}->unregister('maybe-the');
$self->{pbot}->{functions}->unregister('maybe-to'); $self->{pbot}->{functions}->unregister('maybe-to');
$self->{pbot}->{functions}->unregister('maybe-on');
} }
sub func_unquote($self, @rest) { sub func_unquote($self, @rest) {
@ -225,7 +235,6 @@ sub func_maybe_to($self, @rest) {
my ($word) = $text =~ m/^\s*([^',.;: ]+)/; my ($word) = $text =~ m/^\s*([^',.;: ]+)/;
# don't prepend if a proper-noun nick follows
if ($self->{pbot}->{nicklist}->is_present_any_channel($word)) { if ($self->{pbot}->{nicklist}->is_present_any_channel($word)) {
return "to $text"; return "to $text";
} }
@ -240,7 +249,37 @@ sub func_maybe_to($self, @rest) {
if ($tagged !~ m/^\s*<(?:det|prps?|cd|in|nnp|to|rb|wdt|rbr|jjr)>/) { if ($tagged !~ m/^\s*<(?:det|prps?|cd|in|nnp|to|rb|wdt|rbr|jjr)>/) {
$text = "to the $text"; $text = "to the $text";
} else { } else {
$text = "to $text"; unless ($tagged =~ m/^\s*<(?:in)>/) {
$text = "to $text";
}
}
return $text;
}
sub func_maybe_on($self, @rest) {
my $text = "@rest";
$text =~ s/^on (?:the )?//;
my ($word) = $text =~ m/^\s*([^',.;: ]+)/;
if ($self->{pbot}->{nicklist}->is_present_any_channel($word)) {
return "on $text";
}
# special-case some indefinite nouns that Lingua::EN::Tagger treats as plain nouns
if ($word =~ m/(?:some|any|every|no)(?:thing|one|body|how|way|where|when|time|place)/i) {
return "on $text";
}
my $tagged = $self->{tagger}->add_tags($word);
if ($tagged !~ m/^\s*<(?:det|prps?|cd|in|nnp|to|rb|wdt|rbr|jjr)>/) {
$text = "on the $text";
} else {
unless ($tagged =~ m/^\s*<(?:in)>/) {
$text = "on $text";
}
} }
return $text; return $text;

View File

@ -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 => 4834, BUILD_REVISION => 4835,
BUILD_DATE => "2024-11-04", BUILD_DATE => "2024-11-05",
}; };
sub initialize {} sub initialize {}