3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-23 04:19:27 +01:00

regex factoids now trigger properly

This commit is contained in:
Pragmatic Software 2010-06-30 03:48:13 +00:00
parent 1f82cbc285
commit 5f5cd6ec08
2 changed files with 11 additions and 5 deletions

View File

@ -169,6 +169,7 @@ sub find_factoid {
} else {
next unless $from =~ m/$channel/i;
}
foreach my $trigger (keys %{ $self->factoids->hash->{$channel} }) {
if(not $exact_trigger and $self->factoids->hash->{$channel}->{$trigger}->{type} eq 'regex') {
if($string =~ m/$trigger/i) {
@ -339,10 +340,11 @@ sub interpreter {
}
} elsif($self->factoids->hash->{$channel}->{$keyword}->{type} eq 'regex') {
$result = eval {
my $string = "$keyword" . (defined $arguments ? " $arguments" : "");
my $string = "$original_keyword" . (defined $arguments ? " $arguments" : "");
my $cmd;
if($string =~ m/$keyword/i) {
$self->{pbot}->logger->log("[$string] matches [$keyword] - calling [" . $self->factoids->hash->{$channel}->{$keyword}->{action} . "$']\n");
my $cmd = $self->factoids->hash->{$channel}->{$keyword}->{action} . $';
$cmd = $self->factoids->hash->{$channel}->{$keyword}->{action} . $';
my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $before, $after) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $`, $');
$cmd =~ s/\$1/$a/g;
$cmd =~ s/\$2/$b/g;
@ -357,10 +359,14 @@ sub interpreter {
$cmd =~ s/\$'/$after/g;
$cmd =~ s/^\s+//;
$cmd =~ s/\s+$//;
} else {
$cmd = $self->factoids->hash->{$channel}->{$keyword}->{action};
}
$result = $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $cmd);
return $result;
}
};
if($@) {
$self->{pbot}->logger->log("Regex fail: $@\n");
return "/msg $nick Fail.";

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 218,
BUILD_REVISION => 219,
BUILD_DATE => "2010-06-29",
};