zeroclickinfo-goodies/lib/DDG/Goodie/Fortune.pm

38 lines
1019 B
Perl
Raw Normal View History

2013-03-17 20:34:21 -07:00
package DDG::Goodie::Fortune;
# ABSTRACT: UNIX fortune quips.
2013-03-17 20:34:21 -07:00
use DDG::Goodie;
use Fortune;
2014-10-14 11:52:56 -07:00
triggers startend => 'unix fortune', 'fortune cookie', 'random fortune';
2014-10-14 11:52:56 -07:00
primary_example_queries 'fortune cookie', 'random fortune';
name 'Fortune';
description 'get a random phrase from the original fortunes file';
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Fortune.pm';
category 'random';
topics 'words_and_games';
attribution github => ['https://github.com/frncscgmz', 'frncscgmz'],
github => ['https://github.com/dmschulman', 'dmschulman'];
2013-03-17 20:34:21 -07:00
zci answer_type => "fortune";
2014-10-14 11:52:56 -07:00
zci is_cached => 0;
2013-03-17 20:34:21 -07:00
2014-06-27 12:29:21 -07:00
my $ffile = share('fortunes');
my $fortune_file = Fortune->new($ffile);
$fortune_file->read_header();
2013-03-17 20:34:21 -07:00
handle remainder => sub {
my $output = $fortune_file->get_random_fortune();
2014-10-14 11:52:56 -07:00
$output =~ s/\n/ /g;
return $output,
structured_answer => {
input => [],
operation => 'Random fortune',
2014-10-14 11:52:56 -07:00
result => $output
};
2013-03-17 20:34:21 -07:00
};
1;