2012-05-02 10:40:56 -07:00
|
|
|
package DDG::Goodie::DuckDuckGo;
|
|
|
|
# ABSTRACT: Return hard-coded descriptions for DuckDuckGo terms
|
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2014-03-21 09:12:25 -07:00
|
|
|
use DDG::Goodie;
|
|
|
|
|
2015-05-29 15:18:03 -07:00
|
|
|
use YAML::XS 'LoadFile';
|
2014-05-08 16:56:36 -07:00
|
|
|
|
2014-11-13 11:42:56 -08:00
|
|
|
primary_example_queries 'duckduckgo help';
|
|
|
|
secondary_example_queries 'ddg tor', 'short URL for duck duck go';
|
2014-03-17 14:01:17 -07:00
|
|
|
description 'DuckDuckGo help and quick links';
|
|
|
|
name 'DuckDuckGo';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/DuckDuckGo.pm';
|
|
|
|
category 'cheat_sheets';
|
|
|
|
topics 'everyday';
|
2015-01-07 10:37:42 -08:00
|
|
|
attribution twitter => ['crazedpsyc','crazedpsyc'],
|
|
|
|
cpan => ['CRZEDPSYC','crazedpsyc'];
|
2014-03-17 14:01:17 -07:00
|
|
|
|
2014-09-20 11:06:04 -07:00
|
|
|
my @ddg_aliases = map { ($_, $_ . "'s", $_ . "s") } ('duck duck go', 'duckduck go', 'duck duckgo', 'duckduckgo', 'ddg');
|
2014-09-20 06:48:18 -07:00
|
|
|
|
2015-01-08 19:19:26 -08:00
|
|
|
triggers any => @ddg_aliases, "zeroclickinfo", "private search";
|
2014-03-21 11:51:35 -07:00
|
|
|
|
2014-04-04 01:22:27 -07:00
|
|
|
zci is_cached => 1;
|
|
|
|
|
2015-05-29 15:18:03 -07:00
|
|
|
my $responses = LoadFile(share('responses.yml'));
|
2014-04-04 01:22:27 -07:00
|
|
|
|
2014-05-08 16:56:36 -07:00
|
|
|
# The YAML is intended to be human-friendly.
|
|
|
|
# Now we make something computer-friendly.
|
|
|
|
foreach my $keyword (keys %$responses) {
|
|
|
|
my $response = $responses->{$keyword};
|
2014-05-01 18:22:22 -07:00
|
|
|
if (my $base_format = $response->{base_format}) {
|
|
|
|
# We need to produce the output for each version.
|
|
|
|
if (my $info_url = $response->{info_url}) {
|
|
|
|
$response->{text} = $base_format;
|
|
|
|
$response->{text} =~ s/[\[\]]//g; # No internal linking.
|
|
|
|
$response->{text} .= ': ' . $response->{info_url}; # Stick the link on the end.
|
|
|
|
|
|
|
|
$response->{html} = $base_format;
|
|
|
|
$response->{html} =~ s#\[#<a href='$info_url'>#; # Insert link.
|
|
|
|
$response->{html} =~ s#\]#</a>#;
|
|
|
|
$response->{html} .= '.';
|
|
|
|
} else {
|
|
|
|
# No link to insert, so it must be ready for both.
|
|
|
|
$response->{text} = $response->{html} = $response->{base_format};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ref($response->{aliases}) eq 'ARRAY') {
|
|
|
|
foreach my $alias (@{$response->{aliases}}) {
|
|
|
|
# Assume we didn't add an alias for an existing keyword.
|
2014-05-08 16:56:36 -07:00
|
|
|
$responses->{$alias} = $response;
|
2014-05-01 18:22:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $key (keys %$response) {
|
2014-05-08 16:56:36 -07:00
|
|
|
# No matter what they added, we only use the following keys for the actual response.
|
2014-05-01 18:22:22 -07:00
|
|
|
delete $response->{$key} unless (grep { $key eq $_ } (qw(text html)));
|
|
|
|
}
|
|
|
|
}
|
2012-05-02 10:40:56 -07:00
|
|
|
|
2014-09-21 13:11:15 -07:00
|
|
|
my $skip_words_re = qr/\b(?:what|where|is|of|for|the|in|on)\b/;
|
2014-09-20 06:48:18 -07:00
|
|
|
|
2014-03-21 11:51:35 -07:00
|
|
|
handle remainder => sub {
|
2014-05-01 14:30:26 -07:00
|
|
|
my $key = lc;
|
2014-04-04 02:39:55 -07:00
|
|
|
|
2014-09-22 14:16:51 -07:00
|
|
|
$key =~ s/\?//g; # Allow for questions, but don't pollute skip words.
|
2014-09-20 06:48:18 -07:00
|
|
|
$key =~ s/$skip_words_re//g;
|
|
|
|
$key =~ s/\W+//g;
|
|
|
|
|
2014-05-08 16:56:36 -07:00
|
|
|
my $response = $responses->{$key};
|
2014-04-04 02:39:55 -07:00
|
|
|
|
2014-05-01 18:22:22 -07:00
|
|
|
return unless ($response);
|
2014-10-06 04:37:53 -07:00
|
|
|
return $response->{text},
|
|
|
|
structured_answer => {
|
|
|
|
input => [],
|
|
|
|
operation => 'DuckDuckGo info',
|
|
|
|
result => $response->{html}};
|
2012-05-02 10:40:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
1;
|