mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
find_factoid() can now be told to return found alias instead
This commit is contained in:
parent
5457e129b0
commit
6701ee67f9
@ -235,7 +235,7 @@ sub export_factoids {
|
||||
}
|
||||
|
||||
sub find_factoid {
|
||||
my ($self, $from, $keyword, $arguments, $exact_channel, $exact_trigger) = @_;
|
||||
my ($self, $from, $keyword, $arguments, $exact_channel, $exact_trigger, $find_alias) = @_;
|
||||
|
||||
my $debug = 0;
|
||||
|
||||
@ -251,6 +251,7 @@ sub find_factoid {
|
||||
$self->{pbot}->{logger}->log("string: $string\n") if $debug;
|
||||
|
||||
my @result = eval {
|
||||
for (my $depth = 0; $depth < 5; $depth++) {
|
||||
# check factoids
|
||||
foreach my $channel (sort keys %{ $self->{factoids}->hash }) {
|
||||
if($exact_channel) {
|
||||
@ -260,6 +261,18 @@ sub find_factoid {
|
||||
foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) {
|
||||
if($keyword =~ m/^\Q$trigger\E$/i) {
|
||||
$self->{pbot}->{logger}->log("return $channel: $trigger\n") if $debug;
|
||||
|
||||
if($find_alias && $self->{factoids}->hash->{$channel}->{$trigger}->{action} =~ /^\/call\s+(.*)$/) {
|
||||
my $command;
|
||||
if(length $arguments) {
|
||||
$command = "$1 $arguments";
|
||||
} else {
|
||||
$command = $1;
|
||||
}
|
||||
($keyword, $arguments) = split / /, $command, 2;
|
||||
goto NEXT_DEPTH;
|
||||
}
|
||||
|
||||
return ($channel, $trigger);
|
||||
}
|
||||
}
|
||||
@ -277,6 +290,14 @@ sub find_factoid {
|
||||
$self->{pbot}->{logger}->log("checking regex $string =~ m/$trigger/i\n") if $debug;
|
||||
if($string =~ m/$trigger/i) {
|
||||
$self->{pbot}->{logger}->log("return regex $channel: $trigger\n") if $debug;
|
||||
|
||||
if($find_alias) {
|
||||
my $command = $self->{factoids}->hash->{$channel}->{$trigger}->{action};
|
||||
($keyword, $arguments) = split / /, $command, 2;
|
||||
$string = $keyword . (length $arguments ? " $arguments" : "");
|
||||
goto NEXT_DEPTH;
|
||||
}
|
||||
|
||||
return ($channel, $trigger);
|
||||
}
|
||||
}
|
||||
@ -284,6 +305,10 @@ sub find_factoid {
|
||||
}
|
||||
}
|
||||
|
||||
NEXT_DEPTH:
|
||||
last if not $find_alias;
|
||||
}
|
||||
|
||||
$self->{pbot}->{logger}->log("find_factoid: no match\n") if $debug;
|
||||
return undef;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user