diff --git a/applets/wiktionary.pl b/applets/wiktionary.pl index 7783c5fa..19747b46 100755 --- a/applets/wiktionary.pl +++ b/applets/wiktionary.pl @@ -18,6 +18,8 @@ use Encode; use Getopt::Long qw/GetOptionsFromArray/; use JSON; +sub flatten { map { ref eq 'ARRAY' ? flatten(@$_) : $_ } @_ } + binmode(STDOUT, ":utf8"); @ARGV = map { decode('UTF-8', $_, 1) } @ARGV; @@ -93,16 +95,27 @@ if (not defined $entries) { $cache->set($cache_id, $entries); } -my @valid_sections = qw/definitions etymology pronunciations/; +if ($ENV{DEBUG}) { + use Data::Dumper; + print Dumper($entries), "\n"; +} + +my @valid_sections = qw/definitions etymology pronunciations participle/; if (not grep { $_ eq $section } @valid_sections) { print "Unknown section `$section`. Available sections are: " . join(', ', sort @valid_sections) . "\n"; exit 1; } +my $entries_text = $section; + my $total_entries_count = @$entries; -my $entries_text = $section; +if ($total_entries_count == 0) { + $entries_text =~ s/y$/ies/; + print "No $entries_text for `$term`.\n"; + exit 1; +} if ($num > $total_entries_count) { if ($total_entries_count == 1) { @@ -159,11 +172,11 @@ for (my $i = $start; $i < $num; $i++) { foreach my $definition (@{$entry->{definitions}}) { $text .= "$definition->{partOfSpeech}) "; - $text .= join("\n\n", @{$definition->{text}}) . "\n\n"; + $text .= join("\n\n", flatten @{$definition->{text}}) . "\n\n"; if (@{$definition->{examples}}) { $text .= "examples:\n\n"; - $text .= join("\n\n", @{$definition->{examples}}) . "\n\n"; + $text .= join("\n\n", map { $_->{text} } @{$definition->{examples}}) . "\n\n"; } } @@ -174,8 +187,8 @@ for (my $i = $start; $i < $num; $i++) { if (not @results) { $entries_text =~ s/y$/ies/; - print "There are no $entries_text for $term.\n"; - exit 0; + print "There are no $entries_text for `$term`.\n"; + exit 1; } my $total_results_count = @results; @@ -186,8 +199,6 @@ if ($total_results_count == 1) { $entries_text =~ s/y$/ies/; } -print "$total_entries_count entries, " if $total_entries_count > 1; - print "$total_results_count $entries_text for $term:\n\n"; if ($unique) { diff --git a/applets/wiktionary.py b/applets/wiktionary.py index 2bb63c9d..8b565d23 100644 --- a/applets/wiktionary.py +++ b/applets/wiktionary.py @@ -4,6 +4,11 @@ # # This was written for wiktionary.pl since Wiktionary::Parser in CPAN # seems to be broken and abandoned. +# +# Important: This uses a custom fork of wiktionaryparser which contains +# numerous fixes. To install it use: +# +# pip install git+https://github.com/pragma-/WiktionaryParser # SPDX-FileCopyrightText: 2021 Pragmatic Software # SPDX-License-Identifier: MIT diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 10a92c2c..4e7c268a 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4546, + BUILD_REVISION => 4547, BUILD_DATE => "2022-06-27", };