mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-09 03:15:41 -04:00
fixes up the command parsing, now copulas will be less likely to be stolen accidentally
This commit is contained in:
parent
51b77ffc87
commit
e6fd9d4ea0
1 changed files with 30 additions and 29 deletions
|
@ -108,31 +108,32 @@ sub command {
|
||||||
|
|
||||||
my $subject = $said->{body};
|
my $subject = $said->{body};
|
||||||
|
|
||||||
if( !$call_only and $subject =~ /\s+$COPULA_RE\s+/ ) {
|
|
||||||
my @ret = $self->store_factoid( $said );
|
|
||||||
|
|
||||||
return( 'handled', "Failed to store $said->{body}" ) unless @ret;
|
|
||||||
|
|
||||||
return ('handled', "@ret") if ($ret[0] =~ /^insuff/i);
|
|
||||||
return( 'handled', "Stored @ret" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
my $commands_re = join '|', keys %commandhash;
|
my $commands_re = join '|', keys %commandhash;
|
||||||
$commands_re = qr/$commands_re/;
|
$commands_re = qr/$commands_re/;
|
||||||
|
|
||||||
my $fact_string;
|
my $fact_string; # used to capture return values
|
||||||
|
|
||||||
if( !$call_only && $subject =~ s/^\s*($commands_re)\s+// ) {
|
if( !$call_only && $subject =~ s/^\s*($commands_re)\s+// ) {
|
||||||
#i lost the object oriented calling here, but i don't care too much, BECAUSE this avoids using strings for the calling, i might change that.
|
#i lost the object oriented calling here, but i don't care too much, BECAUSE this avoids using strings for the calling, i might change that.
|
||||||
$fact_string = $commandhash{$1}->($self,$subject, $said->{name}, $said);
|
$fact_string = $commandhash{$1}->($self,$subject, $said->{name}, $said);
|
||||||
}
|
}
|
||||||
elsif ($subject =~ m|^\s*(.*?)\s*=~\s*s/([^/]+)/([^/]*)/([gi]*)|i)
|
elsif (($subject =~ m|^\s*(.*?)\s*=~\s*s/([^/]+)/([^/]*)/([gi]*)|i) ||
|
||||||
|
($subject =~ m/^\s*(.*?)\s*=~\s*s\{(.+)\}\{(.*)\}([gi]*)/i))
|
||||||
{
|
{
|
||||||
$fact_string = $self->get_fact_substitute( $subject, $said->{name}, $said);
|
$fact_string = $self->get_fact_substitute( $subject, $said->{name}, $said);
|
||||||
}
|
}
|
||||||
|
elsif( !$call_only and $subject =~ /\s+$COPULA_RE\s+/ ) {
|
||||||
|
my @ret = $self->store_factoid( $said );
|
||||||
|
|
||||||
|
$fact_string = "Failed to store $said->{body}" unless @ret;
|
||||||
|
|
||||||
|
$fact_string = "@ret" if ($ret[0] =~ /^insuff/i);
|
||||||
|
$fact_string = "Stored @ret";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$fact_string = $self->get_fact( $pm, $said, $subject, $said->{name}, $call_only );
|
$fact_string = $self->get_fact( $pm, $said, $subject, $said->{name}, $call_only );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $fact_string ) {
|
if( $fact_string ) {
|
||||||
return( 'handled', $fact_string );
|
return( 'handled', $fact_string );
|
||||||
}
|
}
|
||||||
|
@ -140,7 +141,6 @@ sub command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
sub _clean_subject {
|
sub _clean_subject {
|
||||||
my( $subject ) = @_;
|
my( $subject ) = @_;
|
||||||
|
@ -371,7 +371,8 @@ sub _fact_substitute
|
||||||
sub get_fact_substitute {
|
sub get_fact_substitute {
|
||||||
my( $self, $subject, $name, $said ) = @_;
|
my( $self, $subject, $name, $said ) = @_;
|
||||||
|
|
||||||
if ($said->{body} =~ m|^(?:\s*substitute)?\s*(.*?)\s*=~\s*s/([^/]+)/([^/]*)/([gi]*)\s*$|i)
|
if (($said->{body} =~ m|^(?:\s*substitute)?\s*(.*?)\s*=~\s*s/([^/]+)/([^/]*)/([gi]*)\s*$|i) ||
|
||||||
|
($said->{body} =~ m/^(?:\s*substitute)?\s*(.*?)\s*=~\s*s\{(.+)\}\{(.*?)\}([gi]*)\s*$/i))
|
||||||
{
|
{
|
||||||
my ($subject, $match, $subst, $flags) = ($1, $2, $3, $4);
|
my ($subject, $match, $subst, $flags) = ($1, $2, $3, $4);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue