3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 10:59:29 +01:00

Factoids: replace get_all_by_trigger() with DualIndexSQLiteObject->get()

This commit is contained in:
Pragmatic Software 2020-02-26 17:48:34 -08:00
parent bd805f558b
commit c489b6eac7
2 changed files with 4 additions and 24 deletions

View File

@ -330,14 +330,11 @@ sub find_factoid {
} }
if (not $opts{exact_channel}) { if (not $opts{exact_channel}) {
my $factoids = $self->{factoids}->get_all_by_trigger($keyword); foreach my $factoid ($self->{factoids}->get(index2 => $keyword, index1 => undef, action => undef)) {
foreach my $factoid (@$factoids) {
$channel = $factoid->{index1}; $channel = $factoid->{index1};
$trigger = $factoid->{index2}; $trigger = $keyword;
$action = $factoid->{action};
if ($opts{find_alias} && $action =~ m{^/call\s+(.*)$}ms) { if ($opts{find_alias} && $factoid->{action} =~ m{^/call\s+(.*)$}ms) {
goto CHECK_ALIAS; goto CHECK_ALIAS;
} }
@ -797,7 +794,7 @@ sub interpreter {
# if multiple channels have this keyword, then ask user to disambiguate # if multiple channels have this keyword, then ask user to disambiguate
if (@chanlist> 1) { if (@chanlist> 1) {
return undef if $stuff->{referenced}; return undef if $stuff->{referenced};
return $ref_from . "Ambiguous keyword '$original_keyword' exists in multiple channels (use 'fact <channel> $original_keyword' to choose one): " . join(' ,', @chanlist); return $ref_from . "Ambiguous keyword '$original_keyword' exists in multiple channels (use 'fact <channel> $original_keyword' to choose one): " . join(', ', @chanlist);
} }
# if there's just one other channel that has this keyword, trigger that instance # if there's just one other channel that has this keyword, trigger that instance

View File

@ -25,23 +25,6 @@ sub new {
return $self; return $self;
} }
sub get_all_by_trigger {
my ($self, $index2) = @_;
my $data = eval {
my $sth = $self->{dbh}->prepare('SELECT index1, index2, action FROM Stuff WHERE index2 = ?');
$sth->execute($index2);
return $sth->fetchall_arrayref({});
};
if ($@) {
$self->{pbot}->{logger}->log("Error in get_all_by_trigger: $@\n");
return undef;
}
return $data;
}
sub get_regex_by_channel { sub get_regex_by_channel {
my ($self, $channel) = @_; my ($self, $channel) = @_;