3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 20:09:43 +01:00

Check commands table for keyword before searching regexs

This commit is contained in:
Pragmatic Software 2015-04-03 15:33:19 -07:00
parent d8c12522ed
commit 17afac5908
3 changed files with 25 additions and 10 deletions

View File

@ -74,6 +74,16 @@ sub unregister_by_name {
@{ $self->{handlers} } = grep { $_->{name} ne $name } @{ $self->{handlers} };
}
sub exists {
my $self = shift;
my ($keyword) = @_;
foreach my $ref (@{ $self->{handlers} }) {
return 1 if $ref->{name} eq $keyword;
}
return 0;
}
sub interpreter {
my $self = shift;
my ($from, $nick, $user, $host, $depth, $keyword, $arguments, $tonick) = @_;

View File

@ -252,6 +252,10 @@ sub find_factoid {
my @result = eval {
for (my $depth = 0; $depth < 5; $depth++) {
if ($self->{pbot}->{commands}->exists($keyword)) {
return undef;
}
# check factoids
foreach my $channel (sort keys %{ $self->{factoids}->hash }) {
if($exact_channel) {
@ -483,7 +487,6 @@ sub interpreter {
while ($action =~ /(?<!\\)\$([a-zA-Z0-9_\-]+)/g) {
my $v = $1;
print "v = [$v]\n";
next if $v =~ m/^[0-9]+$/;
my ($var_chan, $var) = $self->find_factoid($from, $v, undef, 0, 1);
@ -498,7 +501,7 @@ sub interpreter {
$mylist[$line] =~ s/"//g;
$action =~ s/\$$var/$mylist[$line]/;
} else {
$action =~ s/\$$var/$var/g;
$action =~ s/(?<!\\)\$$var/$var/;
}
}

View File

@ -222,15 +222,17 @@ sub handle_result {
if (defined $command) {
my ($cmd, $args) = split / /, $command, 2;
my ($chan, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $cmd, $args, 0, 0, 1);
if(defined $trigger) {
if ($preserve_whitespace == 0) {
$preserve_whitespace = $self->{pbot}->{factoids}->{factoids}->hash->{$chan}->{$trigger}->{preserve_whitespace};
$preserve_whitespace = 0 if not defined $preserve_whitespace;
}
if (not $self->{pbot}->{commands}->exists($cmd)) {
my ($chan, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $cmd, $args, 0, 0, 1);
if(defined $trigger) {
if ($preserve_whitespace == 0) {
$preserve_whitespace = $self->{pbot}->{factoids}->{factoids}->hash->{$chan}->{$trigger}->{preserve_whitespace};
$preserve_whitespace = 0 if not defined $preserve_whitespace;
}
$use_output_queue = $self->{pbot}->{factoids}->{factoids}->hash->{$chan}->{$trigger}->{use_output_queue};
$use_output_queue = 0 if not defined $use_output_queue;
$use_output_queue = $self->{pbot}->{factoids}->{factoids}->hash->{$chan}->{$trigger}->{use_output_queue};
$use_output_queue = 0 if not defined $use_output_queue;
}
}
}