3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-29 23:39:24 +01:00

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)
This commit is contained in:
Pragmatic Software 2015-04-10 14:59:17 -07:00
parent d89e05b759
commit 59c29977e6
2 changed files with 14 additions and 10 deletions

View File

@ -90,13 +90,13 @@ sub call_factoid {
return "Usage: fact <channel> <keyword> [arguments]"; return "Usage: fact <channel> <keyword> [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) { if(not defined $trigger) {
return "No such factoid '$keyword' exists for channel '$chan'"; 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 { sub factset {
@ -133,7 +133,7 @@ sub factset {
$channel = '.*' if $channel !~ /^#/; $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) { if(defined $owner_channel) {
my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger}; my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger};
@ -180,7 +180,7 @@ sub factunset {
$channel = '.*' if $channel !~ /^#/; $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) { if(defined $owner_channel) {
my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger}; my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger};
@ -397,7 +397,7 @@ sub factalias {
$chan = '.*' if $chan !~ /^#/; $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) { if(defined $alias_trigger) {
$self->{pbot}->{logger}->log("attempt to overwrite existing command\n"); $self->{pbot}->{logger}->log("attempt to overwrite existing command\n");
@ -433,7 +433,7 @@ sub add_regex {
return "Usage: regex <regex> <command>"; return "Usage: regex <regex> <command>";
} }
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) { if(defined $trigger) {
$self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $trigger\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $trigger\n");
@ -837,7 +837,7 @@ sub factchange {
return "Usage: factchange <channel> <keyword> s/<pattern>/<replacement>/"; return "Usage: factchange <channel> <keyword> s/<pattern>/<replacement>/";
} }
($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) { if(not defined $trigger) {
return "$keyword not found in channel $from."; return "$keyword not found in channel $from.";

View File

@ -259,7 +259,11 @@ sub find_factoid {
# check factoids # check factoids
foreach my $channel (sort keys %{ $self->{factoids}->hash }) { foreach my $channel (sort keys %{ $self->{factoids}->hash }) {
if($exact_channel) { 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} }) { foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) {
@ -331,7 +335,7 @@ sub interpreter {
my ($result, $channel); my ($result, $channel);
my $pbot = $self->{pbot}; 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'); return undef if not length $keyword or $depth > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion');
$from = lc $from; $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(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 =~ /^\/.+? /) { if($action =~ /^\/.+? /) {
$action =~ s/^(\/.+?) /$1 $arguments: /; $action =~ s/^(\/.+?) /$1 $arguments: /;
} else { } else {