3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-10-14 06:57:25 +02:00

Plugin/FuncBuiltins: add length function

This commit is contained in:
Pragmatic Software 2025-10-05 06:34:04 -07:00
parent 483a782021
commit 7f2736a604
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE

View File

@ -104,7 +104,6 @@ sub initialize($self, %conf) {
subref => sub { $self->func_maybe_to(@_) }
}
);
$self->{pbot}->{functions}->register(
'maybe-on',
{
@ -113,6 +112,14 @@ sub initialize($self, %conf) {
subref => sub { $self->func_maybe_on(@_) }
}
);
$self->{pbot}->{functions}->register(
'length',
{
desc => 'print length of text',
usage => 'length <text>',
subref => sub { $self->func_length(@_) }
}
);
$self->{tagger} = Lingua::EN::Tagger->new;
}
@ -285,4 +292,11 @@ sub func_maybe_on($self, @rest) {
return $text;
}
sub func_length($self, @rest) {
my $text = "@rest";
my $count = 0;
while ($text =~ /\X/g) { $count++ }; # count graphemes
return $count;
}
1;