3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 09:58:42 +02:00

Factoids: add default options for named parameters

This commit is contained in:
Pragmatic Software 2019-06-10 09:21:35 -07:00
parent 75a31458b0
commit f0181c7a69
2 changed files with 19 additions and 2 deletions

View File

@ -170,6 +170,14 @@ sub log_factoid {
sub find_factoid_with_optional_channel {
my ($self, $from, $arguments, $command, %opts) = @_;
my %default_opts = (
usage => undef,
explicit => 0,
exact_channel => 0
);
%opts = (%default_opts, %opts);
my $arglist = $self->{pbot}->{interpreter}->make_args($arguments);
my ($from_chan, $from_trigger, $remaining_args) = $self->{pbot}->{interpreter}->split_args($arglist, 3);

View File

@ -271,6 +271,15 @@ sub export_factoids {
sub find_factoid {
my ($self, $from, $keyword, %opts) = @_;
my %default_opts = (
arguments => '',
exact_channel => 0,
exact_trigger => 0,
find_alias => 0
);
%opts = (%default_opts, %opts);
my $debug = 0;
if ($debug) {
@ -279,13 +288,13 @@ sub find_factoid {
$self->{pbot}->{logger}->log("find_factiod: from: $from, kw: $keyword, opts: $dump\n");
}
my $arguments = exists $opts{arguments} ? $opts{arguments} : "";
$from = '.*' if not defined $from or $from !~ /^#/;
$from = lc $from;
$self->{pbot}->{logger}->log("from: $from\n") if $debug;
my $arguments = $opts{arguments};
my @result = eval {
my @results;
for (my $depth = 0; $depth < 5; $depth++) {