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:
parent
483a782021
commit
7f2736a604
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user