mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
Minor clean-up of bash faq
This commit is contained in:
parent
cbc10751e0
commit
7134010f98
18
modules/bashfaq.pl
vendored
18
modules/bashfaq.pl
vendored
@ -7,7 +7,7 @@
|
|||||||
my $query = "@ARGV";
|
my $query = "@ARGV";
|
||||||
print "Usage: faq <id or search text>\n" and exit 0 if not length $query;
|
print "Usage: faq <id or search text>\n" and exit 0 if not length $query;
|
||||||
|
|
||||||
my (%faq, $id, $rcpt, $output);
|
my (%faq, $match);
|
||||||
|
|
||||||
open(FILE, "< bashfaq.txt") or print "Can't open Bash FAQ: $!" and exit 1;
|
open(FILE, "< bashfaq.txt") or print "Can't open Bash FAQ: $!" and exit 1;
|
||||||
|
|
||||||
@ -26,23 +26,21 @@ if ($query =~ / >/) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (exists $faq{$query}) {
|
if (exists $faq{$query}) {
|
||||||
$id = $query;
|
$match = $query;
|
||||||
$output = $faq{$id};
|
|
||||||
} else {
|
} else {
|
||||||
foreach my $key (keys %faq) {
|
foreach my $key (keys %faq) {
|
||||||
if ($faq{$key} =~ /$query/i) {
|
if ($faq{$key} =~ /$query/i) {
|
||||||
$id = $key;
|
$match = $key;
|
||||||
$output = $faq{$key};
|
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $output) {
|
if ($match) {
|
||||||
$id = sprintf "%03d", $id;
|
my $id = sprintf "%03d", $match;
|
||||||
$output = "https://mywiki.wooledge.org/BashFAQ/$id -- $output\n";
|
my $output = "https://mywiki.wooledge.org/BashFAQ/$id -- $faq{$match}";
|
||||||
$output = "$rcpt: $output" if length $rcpt;
|
print "$rcpt: " if $rcpt;
|
||||||
print $output;
|
print "$output\n";
|
||||||
} else {
|
} else {
|
||||||
print "No matches found at https://mywiki.wooledge.org/BashFAQ\n";
|
print "No matches found at https://mywiki.wooledge.org/BashFAQ\n";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user