diff --git a/Plugins/FuncSed.pm b/Plugins/FuncSed.pm new file mode 100644 index 00000000..a5838204 --- /dev/null +++ b/Plugins/FuncSed.pm @@ -0,0 +1,65 @@ +# File: FuncSed.pm +# Author: pragma- +# +# Purpose: Registers the sed Function + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package Plugins::FuncSed; +use parent 'Plugins::Plugin'; + +use warnings; use strict; +use feature 'unicode_strings'; + +sub initialize { + my ($self, %conf) = @_; + $self->{pbot}->{functions}->register( + 'sed', + { + desc => 'a sed-like stream editor', + usage => 'sed s///[Pig]; P preserve case; i ignore case; g replace all', + subref => sub { $self->func_sed(@_) } + } + ); +} + +sub unload { + my $self = shift; + $self->{pbot}->{functions}->unregister('sed'); +} + +# near-verbatim insertion of krok's `sed` factoid +no warnings; +sub func_sed { + my $self = shift; + my $text = "@_"; + + if ($text =~ /^s(.)(.*?)(?