mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
Fix factlog
to use exact channel if specified
This commit is contained in:
parent
d473ab7fe7
commit
4b10c69f47
@ -170,7 +170,7 @@ sub log_factoid {
|
||||
}
|
||||
|
||||
sub find_factoid_with_optional_channel {
|
||||
my ($self, $from, $arguments, $command, $usage, $explicit) = @_;
|
||||
my ($self, $from, $arguments, $command, $usage, $explicit, $exact_channel) = @_;
|
||||
my ($from_chan, $from_trigger, $remaining_args) = split /\s+/, $arguments, 3;
|
||||
|
||||
if (not defined $from_chan or (not defined $from_chan and not defined $from_trigger)) {
|
||||
@ -200,6 +200,16 @@ sub find_factoid_with_optional_channel {
|
||||
$from_chan = '.*' if $from_chan !~ /^#/;
|
||||
$from_chan = lc $from_chan;
|
||||
|
||||
my ($channel, $trigger);
|
||||
|
||||
if (defined $exact_channel and $exact_channel == 1) {
|
||||
($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $from_trigger, undef, 1, 1);
|
||||
|
||||
if (not defined $channel) {
|
||||
$from_chan = 'the global channel' if $from_chan eq '.*';
|
||||
return "/say $from_trigger not found in $from_chan.";
|
||||
}
|
||||
} else {
|
||||
my @factoids = $self->{pbot}->{factoids}->find_factoid($from_chan, $from_trigger, undef, 0, 1);
|
||||
|
||||
if (not @factoids or not $factoids[0]) {
|
||||
@ -211,8 +221,6 @@ sub find_factoid_with_optional_channel {
|
||||
}
|
||||
}
|
||||
|
||||
my ($channel, $trigger);
|
||||
|
||||
if (@factoids > 1) {
|
||||
if ($needs_disambig or not grep { $_->[0] eq $from_chan } @factoids) {
|
||||
unless ($explicit) {
|
||||
@ -236,6 +244,7 @@ sub find_factoid_with_optional_channel {
|
||||
} else {
|
||||
($channel, $trigger) = ($factoids[0]->[0], $factoids[0]->[1]);
|
||||
}
|
||||
}
|
||||
|
||||
$channel = '.*' if $channel eq 'global';
|
||||
$from_chan = '.*' if $channel eq 'global';
|
||||
@ -947,7 +956,7 @@ sub factlog {
|
||||
return "Too many arguments -- $usage" if @$args > 2;
|
||||
return "Missing argument -- $usage" if not @$args;
|
||||
|
||||
my ($channel, $trigger) = $self->find_factoid_with_optional_channel($from, "@$args", 'factlog', $usage);
|
||||
my ($channel, $trigger) = $self->find_factoid_with_optional_channel($from, "@$args", 'factlog', $usage, 0, 1);
|
||||
|
||||
if (not defined $trigger) {
|
||||
# factoid not found or some error, try to continue and load factlog file if it exists
|
||||
@ -967,7 +976,7 @@ sub factlog {
|
||||
my $trigger_safe = safe_filename $trigger;
|
||||
|
||||
open my $fh, "< $path/$trigger_safe.$channel_safe" or do {
|
||||
$self->{pbot}->{logger}->log("Could not open $path/$trigger.$channel: $!\n");
|
||||
$self->{pbot}->{logger}->log("Could not open $path/$trigger_safe.$channel_safe: $!\n");
|
||||
$channel = 'the global channel' if $channel eq 'global';
|
||||
return "No factlog available for $trigger in $channel.";
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user