3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +01:00

Update udict

This commit is contained in:
Pragmatic Software 2017-10-10 20:30:26 -07:00
parent 26b6f90c7c
commit 24035d8db9

View File

@ -23,6 +23,8 @@ my $usage = "Usage: udict [-m <show definition matching this regex>] [-n <entry
my ($entry, $sort, $match, $show_all);
my $arguments = join(' ', @ARGV);
$arguments =~ s/'/\\'/g;
my ($ret, $args) = GetOptionsFromString($arguments,
'a' => \$show_all,
'm=s' => \$match,
@ -30,9 +32,24 @@ my ($ret, $args) = GetOptionsFromString($arguments,
's=s' => \$sort);
print "$getopt_error -- $usage" and exit if defined $getopt_error;
print "Missing phrase -- $usage" and exit if @$args == 0;
print "Missing phrase -- $usage" and exit if @$args == 0 and not $match and not $entry;
$args = join(' ', @$args);
if (@$args == 0) {
open my $fh, "<", "udict.last";
if ($fh) {
$args = <$fh>;
chomp $args;
close $fh;
} else {
$args = "wtf";
}
} else {
$args = join(' ', @$args);
open my $fh, ">", "udict.last";
print $fh "$args\n";
close $fh;
}
my $ud = WebService::UrbanDictionary->new;
my $results = $ud->request($args);
@ -79,6 +96,9 @@ sub show_definition {
print "$num/$num_entries: ";
}
$entry->{'definition'} =~ s/\[(.*?)\]/$1/g;
$entry->{'example'} =~ s/\[(.*?)\]/$1/g if $entry->{'example'};
print "(+$entry->{'thumbs_up'}/-$entry->{'thumbs_down'}) $entry->{'definition'}\n";
print "$entry->{'example'}\n" if $entry->{'example'};
}