mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 19:22:40 +01:00
urban module: improve showing of number of entries
This commit is contained in:
parent
5bc65c9f67
commit
f120959935
@ -55,19 +55,15 @@ my $num_entries = @entries;
|
||||
if ($num_entries == 0) {
|
||||
print "$args: no definition found.\n";
|
||||
exit;
|
||||
} else {
|
||||
if ($num_entries > 1) {
|
||||
if (defined $entry) {
|
||||
print "$entry/$num_entries:\n";
|
||||
} else {
|
||||
print "1/$num_entries:\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $entry) {
|
||||
if ($entry < 1 or $entry > $num_entries) {
|
||||
print "No such entry. There are $num_entries for $args.\n";
|
||||
if ($num_entries == 1) {
|
||||
print "There is only one entry for $args.\n";
|
||||
} else {
|
||||
print "$args: no such entry. There are $num_entries entries.\n";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
$entry--;
|
||||
@ -75,6 +71,13 @@ if (defined $entry) {
|
||||
|
||||
sub show_definition {
|
||||
my $entry = shift;
|
||||
my $num = shift;
|
||||
|
||||
$num = 1 if not defined $num;
|
||||
|
||||
if ($num_entries > 1) {
|
||||
print "$num/$num_entries: ";
|
||||
}
|
||||
|
||||
print "($entry->{'thumbs_up'}/$entry->{'thumbs_down'}) $entry->{'definition'}\n";
|
||||
print "$entry->{'example'}\n" if $entry->{'example'};
|
||||
@ -83,12 +86,14 @@ sub show_definition {
|
||||
if (defined $show_all or defined $match) {
|
||||
my $shown;
|
||||
eval {
|
||||
my $n = 0;
|
||||
for my $each (@entries) {
|
||||
$n++;
|
||||
if (defined $match) {
|
||||
my $def = $each->{'definition'} . "\n" . $each->{'example'};
|
||||
next if $def !~ m/$match/im;
|
||||
}
|
||||
show_definition($each);
|
||||
show_definition($each, $n);
|
||||
print "\n";
|
||||
$shown++;
|
||||
}
|
||||
@ -107,5 +112,5 @@ if (defined $show_all or defined $match) {
|
||||
print "$args: no definition matching '$match' found.\n";
|
||||
}
|
||||
} else {
|
||||
show_definition($entries[$entry]);
|
||||
show_definition($entries[$entry], $entry + 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user