mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-23 02:24:25 +01:00
Quotegrabs: Replace inferior GetOptionsFromString with better GetOptionsFromArray; improve usage messages
This commit is contained in:
parent
0f4eb76a4e
commit
4562eab46f
@ -17,7 +17,7 @@ use feature 'unicode_strings';
|
|||||||
use HTML::Entities;
|
use HTML::Entities;
|
||||||
use Time::Duration;
|
use Time::Duration;
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
use Getopt::Long qw(GetOptionsFromString);
|
use Getopt::Long qw(GetOptionsFromArray);
|
||||||
|
|
||||||
use PBot::Plugins::Quotegrabs::Quotegrabs_SQLite; # use SQLite backend for quotegrabs database
|
use PBot::Plugins::Quotegrabs::Quotegrabs_SQLite; # use SQLite backend for quotegrabs database
|
||||||
#use PBot::Plugins::Quotegrabs::Quotegrabs_Hashtable; # use Perl hashtable backend for quotegrabs database
|
#use PBot::Plugins::Quotegrabs::Quotegrabs_Hashtable; # use Perl hashtable backend for quotegrabs database
|
||||||
@ -161,7 +161,7 @@ sub grab_quotegrab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (not defined $arguments or not length $arguments) {
|
if (not defined $arguments or not length $arguments) {
|
||||||
return "Usage: grab <nick> [history [channel]] [+ <nick> [history [channel]] ...] -- where [history] is an optional argument that is a regex (without whitespace) of the text within the message; e.g., to grab a message containing 'pizza', use `grab nick pizza`; you can chain grabs with + to grab multiple messages";
|
return "Usage: grab <nick> [history [channel]] [+ <nick> [history [channel]] ...] -- where [history] is an optional regex argument; e.g., to grab a message containing 'pizza', use `grab nick pizza`; you can chain grabs with + to grab multiple messages";
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = lc $arguments;
|
$arguments = lc $arguments;
|
||||||
@ -322,7 +322,7 @@ sub show_random_quotegrab {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $usage = 'Usage: rq [nick [channel [text]]] [-c,--channel <channel>] [-t,--text <text>]';
|
my $usage = 'Usage: rq [nick [channel [text]]] [-c <channel>] [-t <text>]';
|
||||||
|
|
||||||
if (defined $arguments) {
|
if (defined $arguments) {
|
||||||
my $getopt_error;
|
my $getopt_error;
|
||||||
@ -331,16 +331,16 @@ sub show_random_quotegrab {
|
|||||||
chomp $getopt_error;
|
chomp $getopt_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
$arguments =~ s/(?<!\\)'/\\'/g;
|
my @opt_args = $self->{pbot}->{interpreter}->split_line($arguments, preserve_escapes => 1, strip_quotes => 1);
|
||||||
my ($ret, $args) = GetOptionsFromString($arguments,
|
my ($ret, $rest) = GetOptionsFromArray(\@opt_args,
|
||||||
'channel|c=s' => \$channel_search,
|
'channel|c=s' => \$channel_search,
|
||||||
'text|t=s' => \$text_search);
|
'text|t=s' => \$text_search);
|
||||||
|
|
||||||
return "$getopt_error -- $usage" if defined $getopt_error;
|
return "$getopt_error -- $usage" if defined $getopt_error;
|
||||||
|
|
||||||
$nick_search = shift @$args;
|
$nick_search = shift @opt_args;
|
||||||
$channel_search = shift @$args if not defined $channel_search;
|
$channel_search = shift @opt_args if not defined $channel_search;
|
||||||
$text_search = shift @$args if not defined $text_search;
|
$text_search = shift @opt_args if not defined $text_search;
|
||||||
|
|
||||||
if ($nick_search =~ m/^#/) {
|
if ($nick_search =~ m/^#/) {
|
||||||
my $tmp = $channel_search;
|
my $tmp = $channel_search;
|
||||||
@ -353,7 +353,15 @@ sub show_random_quotegrab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$channel_search = undef if defined $channel_search and $channel_search !~ /^#/;
|
if (defined $channel_search and $channel_search !~ /^#/) {
|
||||||
|
if ($channel_search eq $nick) {
|
||||||
|
$channel_search = undef;
|
||||||
|
} elsif ($channel_search =~ m/^\./) {
|
||||||
|
# do nothing
|
||||||
|
} else {
|
||||||
|
return "$channel_search is not a valid channel.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $quotegrab = $self->{database}->get_random_quotegrab($nick_search, $channel_search, $text_search);
|
my $quotegrab = $self->{database}->get_random_quotegrab($nick_search, $channel_search, $text_search);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user