mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-08 03:40:42 -04:00
Make prefixed factoid commands unable to learn
This commit is contained in:
parent
c87e3ecc6a
commit
711c8c6d21
1 changed files with 37 additions and 36 deletions
|
@ -231,27 +231,27 @@ sub sub_command {
|
||||||
|
|
||||||
my $subject = $said->{body};
|
my $subject = $said->{body};
|
||||||
|
|
||||||
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; # used to capture return values
|
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 (
|
elsif (
|
||||||
($subject =~ m{\w\s*=~\s*s /.+ / .* /[gi]*\s*$}ix) ||
|
($subject =~ m{\w\s*=~\s*s /.+ / .* /[gi]*\s*$}ix) ||
|
||||||
($subject =~ m{\w\s*=~\s*s\|.+\| .*\|[gi]*\s*$}ix) ||
|
($subject =~ m{\w\s*=~\s*s\|.+\| .*\|[gi]*\s*$}ix) ||
|
||||||
($subject =~ m{\w\s*=~\s*s\{.+\}\{.*\}[gi]*\s*$}ix) ||
|
($subject =~ m{\w\s*=~\s*s\{.+\}\{.*\}[gi]*\s*$}ix) ||
|
||||||
($subject =~ m{\w\s*=~\s*s <.+ > <.* >[gi]*\s*$}ix) ||
|
($subject =~ m{\w\s*=~\s*s <.+ > <.* >[gi]*\s*$}ix) ||
|
||||||
($subject =~ m{\w\s*=~\s*s\(.+\)\(.*\)[gi]*\s*$}ix)
|
($subject =~ m{\w\s*=~\s*s\(.+\)\(.*\)[gi]*\s*$}ix)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$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+/ ) {
|
elsif( !$call_only and $subject =~ /\s+$COPULA_RE\s+/ ) {
|
||||||
return if $said->{nolearn};
|
return if $said->{nolearn};
|
||||||
my @ret = $self->store_factoid( $said );
|
my @ret = $self->store_factoid( $said );
|
||||||
|
|
||||||
$fact_string = "Failed to store $said->{body}" unless @ret;
|
$fact_string = "Failed to store $said->{body}" unless @ret;
|
||||||
|
@ -279,7 +279,7 @@ sub handle {
|
||||||
|
|
||||||
$said->{body} =~ s/^\s*(what|who|where|how|when|why)\s+($COPULA_RE)\s+(?<fact>.*?)\??\s*$/$+{fact}/i;
|
$said->{body} =~ s/^\s*(what|who|where|how|when|why)\s+($COPULA_RE)\s+(?<fact>.*?)\??\s*$/$+{fact}/i;
|
||||||
|
|
||||||
my $prefix = $conf->{prefix_command};
|
my $prefix = $conf->{prefix_command};
|
||||||
return unless $prefix;
|
return unless $prefix;
|
||||||
|
|
||||||
# TODO make this channel configurable and make it work properly to learn shit with colors later.
|
# TODO make this channel configurable and make it work properly to learn shit with colors later.
|
||||||
|
@ -287,26 +287,27 @@ sub handle {
|
||||||
|
|
||||||
if ($said->{body} =~ /^\Q$prefix\E(?<fact>[^@]*?)(?:\s@\s*(?<user>\S*)\s*)?$/ ||
|
if ($said->{body} =~ /^\Q$prefix\E(?<fact>[^@]*?)(?:\s@\s*(?<user>\S*)\s*)?$/ ||
|
||||||
$said->{body} =~ /^\Q$prefix\E!@(?<user>\S+)\s+(?<fact>.+)$/) {
|
$said->{body} =~ /^\Q$prefix\E!@(?<user>\S+)\s+(?<fact>.+)$/) {
|
||||||
my $fact = $+{fact};
|
my $fact = $+{fact};
|
||||||
my $user = $+{user};
|
my $user = $+{user};
|
||||||
|
|
||||||
my $newsaid = +{$said->%*};
|
my $newsaid = +{$said->%*};
|
||||||
$newsaid->{body} = $fact;
|
$newsaid->{body} = $fact;
|
||||||
|
|
||||||
if ($fact =~ /^\s*(?<channel>#\S+)\s+(?<fact>.*)$/) {
|
if ($fact =~ /^\s*(?<channel>#\S+)\s+(?<fact>.*)$/) {
|
||||||
my ($fact, $channel) = @+{qw/fact channel/};
|
my ($fact, $channel) = @+{qw/fact channel/};
|
||||||
$newsaid->{body} = $fact;
|
$newsaid->{body} = $fact;
|
||||||
$newsaid->{channel} = $channel;
|
$newsaid->{channel} = $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newsaid->{addressed} = 1;
|
$newsaid->{addressed} = 1;
|
||||||
|
$newsaid->{nolearn} = 1;
|
||||||
|
|
||||||
my ($s, $r) = $self->command($newsaid, $pm);
|
my ($s, $r) = $self->command($newsaid, $pm);
|
||||||
if ($s) {
|
if ($s) {
|
||||||
$r = "$user: $r" if $user;
|
$r = "$user: $r" if $user;
|
||||||
$r = "\0".$r;
|
$r = "\0".$r;
|
||||||
return ($r, 'handled');
|
return ($r, 'handled');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue