From 7f2736a6042e5981e66dc3f5608f8282243b2988 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 5 Oct 2025 06:34:04 -0700 Subject: [PATCH] Plugin/FuncBuiltins: add length function --- lib/PBot/Plugin/FuncBuiltins.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/PBot/Plugin/FuncBuiltins.pm b/lib/PBot/Plugin/FuncBuiltins.pm index f3e96b68..4f5175a3 100644 --- a/lib/PBot/Plugin/FuncBuiltins.pm +++ b/lib/PBot/Plugin/FuncBuiltins.pm @@ -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 ', + 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;