3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 09:58:42 +02: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}) {
my $factoids = $self->{factoids}->get_all_by_trigger($keyword);
foreach my $factoid (@$factoids) {
foreach my $factoid ($self->{factoids}->get(index2 => $keyword, index1 => undef, action => undef)) {
$channel = $factoid->{index1};
$trigger = $factoid->{index2};
$action = $factoid->{action};
$trigger = $keyword;
if ($opts{find_alias} && $action =~ m{^/call\s+(.*)$}ms) {
if ($opts{find_alias} && $factoid->{action} =~ m{^/call\s+(.*)$}ms) {
goto CHECK_ALIAS;
}
@ -797,7 +794,7 @@ sub interpreter {
# if multiple channels have this keyword, then ask user to disambiguate
if (@chanlist> 1) {
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

View File

@ -25,23 +25,6 @@ sub new {
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 {
my ($self, $channel) = @_;