mirror of
https://github.com/pragma-/pbot.git
synced 2025-10-14 15:07:22 +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(@_) }
|
subref => sub { $self->func_maybe_to(@_) }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{pbot}->{functions}->register(
|
$self->{pbot}->{functions}->register(
|
||||||
'maybe-on',
|
'maybe-on',
|
||||||
{
|
{
|
||||||
@ -113,6 +112,14 @@ sub initialize($self, %conf) {
|
|||||||
subref => sub { $self->func_maybe_on(@_) }
|
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;
|
$self->{tagger} = Lingua::EN::Tagger->new;
|
||||||
}
|
}
|
||||||
@ -285,4 +292,11 @@ sub func_maybe_on($self, @rest) {
|
|||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub func_length($self, @rest) {
|
||||||
|
my $text = "@rest";
|
||||||
|
my $count = 0;
|
||||||
|
while ($text =~ /\X/g) { $count++ }; # count graphemes
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user