# File: FuncBuiltins.pm # # Purpose: Registers the basic built-in Functions # SPDX-FileCopyrightText: 2021 Pragmatic Software # SPDX-License-Identifier: MIT package PBot::Plugin::FuncBuiltins; use parent 'PBot::Plugin::Base'; use PBot::Imports; use PBot::Core::Utils::Indefinite; use Lingua::EN::Tagger; use URI::Escape qw/uri_escape_utf8/; sub initialize { my ($self, %conf) = @_; $self->{pbot}->{functions}->register( 'title', { desc => 'Title-cases text', usage => 'title ', subref => sub { $self->func_title(@_) } } ); $self->{pbot}->{functions}->register( 'ucfirst', { desc => 'Uppercases first character', usage => 'ucfirst ', subref => sub { $self->func_ucfirst(@_) } } ); $self->{pbot}->{functions}->register( 'uc', { desc => 'Uppercases all characters', usage => 'uc ', subref => sub { $self->func_uc(@_) } } ); $self->{pbot}->{functions}->register( 'lc', { desc => 'Lowercases all characters', usage => 'lc ', subref => sub { $self->func_lc(@_) } } ); $self->{pbot}->{functions}->register( 'unquote', { desc => 'removes unescaped surrounding quotes and strips escapes from escaped quotes', usage => 'unquote ', subref => sub { $self->func_unquote(@_) } } ); $self->{pbot}->{functions}->register( 'uri_escape', { desc => 'percent-encode unsafe URI characters', usage => 'uri_escape ', subref => sub { $self->func_uri_escape(@_) } } ); $self->{pbot}->{functions}->register( 'ana', { desc => 'fix-up a/an article at front of text', usage => 'ana ', subref => sub { $self->func_ana(@_) } } ); $self->{pbot}->{functions}->register( 'maybe-the', { desc => 'prepend "the" in front of text depending on the part-of-speech of the first word in text', usage => 'maybe-the ', subref => sub { $self->func_maybe_the(@_) } } ); $self->{tagger} = Lingua::EN::Tagger->new; } sub unload { my $self = shift; $self->{pbot}->{functions}->unregister('title'); $self->{pbot}->{functions}->unregister('ucfirst'); $self->{pbot}->{functions}->unregister('uc'); $self->{pbot}->{functions}->unregister('lc'); $self->{pbot}->{functions}->unregister('unquote'); $self->{pbot}->{functions}->unregister('uri_escape'); $self->{pbot}->{functions}->unregister('ana'); $self->{pbot}->{functions}->unregister('maybe-the'); } sub func_unquote { my $self = shift; my $text = "@_"; $text =~ s/^"(.*?)(?{pbot}->{nicklist}->is_present_any_channel($word)) { return $text; } my $tagged = $self->{tagger}->add_tags($word); if ($tagged !~ m/^\s*<(?:det|prps?|cd|in|nnp|to|rb|wdt|vbg)>/) { $text = "the $text"; } return $text; } 1;