mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-22 18:52:40 +01:00
FuncBuiltins: add maybe-on
This commit is contained in:
parent
ead34c81c9
commit
a71f29be1a
@ -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;
|
||||
}
|
||||
|
||||
@ -120,6 +129,7 @@ sub unload($self) {
|
||||
$self->{pbot}->{functions}->unregister('ana');
|
||||
$self->{pbot}->{functions}->unregister('maybe-the');
|
||||
$self->{pbot}->{functions}->unregister('maybe-to');
|
||||
$self->{pbot}->{functions}->unregister('maybe-on');
|
||||
}
|
||||
|
||||
sub func_unquote($self, @rest) {
|
||||
@ -225,7 +235,6 @@ sub func_maybe_to($self, @rest) {
|
||||
|
||||
my ($word) = $text =~ m/^\s*([^',.;: ]+)/;
|
||||
|
||||
# don't prepend if a proper-noun nick follows
|
||||
if ($self->{pbot}->{nicklist}->is_present_any_channel($word)) {
|
||||
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)>/) {
|
||||
$text = "to the $text";
|
||||
} 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;
|
||||
|
@ -25,8 +25,8 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4834,
|
||||
BUILD_DATE => "2024-11-04",
|
||||
BUILD_REVISION => 4835,
|
||||
BUILD_DATE => "2024-11-05",
|
||||
};
|
||||
|
||||
sub initialize {}
|
||||
|
Loading…
Reference in New Issue
Block a user