From 59c29977e617a81bb51af605497c8df745c8c860 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 10 Apr 2015 14:59:17 -0700 Subject: [PATCH] Improve handling of factoids Fix adding factoid to local channel when a factoid of same name already exists for global channel Fix calling factoid from another channel with `fact` command Do not prepend nick argument to aliases (/call factoids) --- PBot/FactoidCommands.pm | 14 +++++++------- PBot/Factoids.pm | 10 +++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index 6933ff27..47bc4c37 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -90,13 +90,13 @@ sub call_factoid { return "Usage: fact [arguments]"; } - my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $keyword, $args, 1); + my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $keyword, $args, 1, 1); if(not defined $trigger) { return "No such factoid '$keyword' exists for channel '$chan'"; } - return $self->{pbot}->{factoids}->interpreter($from, $nick, $user, $host, 1, $trigger, $args); + return $self->{pbot}->{factoids}->interpreter($from, $nick, $user, $host, 1, $trigger, $args, undef, $channel); } sub factset { @@ -133,7 +133,7 @@ sub factset { $channel = '.*' if $channel !~ /^#/; - my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1); + my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1, 1); if(defined $owner_channel) { my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger}; @@ -180,7 +180,7 @@ sub factunset { $channel = '.*' if $channel !~ /^#/; - my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1); + my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1, 1); if(defined $owner_channel) { my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger}; @@ -397,7 +397,7 @@ sub factalias { $chan = '.*' if $chan !~ /^#/; - my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $alias, undef, 1); + my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $alias, undef, 1, 1); if(defined $alias_trigger) { $self->{pbot}->{logger}->log("attempt to overwrite existing command\n"); @@ -433,7 +433,7 @@ sub add_regex { return "Usage: regex "; } - my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $keyword, undef, 1); + my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $keyword, undef, 1, 1); if(defined $trigger) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $trigger\n"); @@ -837,7 +837,7 @@ sub factchange { return "Usage: factchange s///"; } - ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $keyword, undef, 0, 1); + ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $keyword, undef, 1, 1); if(not defined $trigger) { return "$keyword not found in channel $from."; diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index e015aa40..13e45a52 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -259,7 +259,11 @@ sub find_factoid { # check factoids foreach my $channel (sort keys %{ $self->{factoids}->hash }) { if($exact_channel) { - next unless $from eq lc $channel or $channel eq '.*'; + if($exact_trigger) { + next unless $from eq lc $channel; + } else { + next unless $from eq lc $channel or $channel eq '.*'; + } } foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) { @@ -331,7 +335,7 @@ sub interpreter { my ($result, $channel); my $pbot = $self->{pbot}; - $self->{pbot}->{logger}->log("enter factoid interpreter [$keyword][$arguments]\n"); + $self->{pbot}->{logger}->log("enter factoid interpreter [$keyword][" . (defined $arguments ? $arguments : '') . "]\n"); return undef if not length $keyword or $depth > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion'); $from = lc $from; @@ -443,7 +447,7 @@ sub interpreter { } if(not $action =~ s/\$args/$arguments/gi and not exists $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args} and $type eq 'text') { - if($self->{pbot}->{nicklist}->is_present($from, $arguments)) { + if(not $action =~ m/^\/call/ and $self->{pbot}->{nicklist}->is_present($from, $arguments)) { if($action =~ /^\/.+? /) { $action =~ s/^(\/.+?) /$1 $arguments: /; } else {