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

51 lines
1.5 KiB
Perl
Raw Normal View History

2013-06-21 13:34:59 -07:00
package DDG::Goodie::HelpLine;
# ABSTRACT: Provide localized suicide intervention phone numbers.
2013-06-21 12:43:57 -07:00
use strict;
2013-06-21 12:43:57 -07:00
use DDG::Goodie;
2015-05-29 15:18:03 -07:00
use YAML::XS 'LoadFile';
2015-05-29 15:18:03 -07:00
my $triggers = LoadFile(share('triggers.yml'));
triggers any => @$triggers;
2013-06-21 12:43:57 -07:00
zci answer_type => 'helpline';
zci is_cached => 0;
2013-06-21 12:43:57 -07:00
primary_example_queries 'suicide hotline';
2014-07-01 02:58:12 -07:00
description 'Checks if a query with the word "suicide" was made and returns a 24 hr suicide hotline.';
2015-01-07 10:37:42 -08:00
attribution github => ['https://github.com/conorfl', 'conorfl'];
2013-06-21 12:43:57 -07:00
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Helpline.pm';
topics 'everyday';
2013-06-21 13:34:59 -07:00
category 'special';
source 'https://en.wikipedia.org/wiki/List_of_suicide_crisis_lines';
2013-06-21 13:34:59 -07:00
2015-05-29 15:18:03 -07:00
my $helplines = LoadFile(share('helplines.yml'));
my %suicide_phrases = map { $_ => 1 } @$triggers;
2013-06-21 12:43:57 -07:00
handle query_lc => sub {
my $query = shift;
return unless exists $suicide_phrases{$query};
# Display the result.
my $helpline = $helplines->{$loc->country_code};
return unless $helpline;
my @contacts = @{$helpline->{contacts}};
my $numbers_string = join(', ', map { ($_->{for_kids}) ? $_->{phone} . ' (kids)' : $_->{phone}; } @contacts);
my $operation = '24 Hour Suicide Hotline';
$operation .= 's' if (scalar @contacts > 1);
$operation .= ' in ' . $helpline->{display_country};
return $operation . ": " . $numbers_string,
structured_answer => {
input => [],
operation => $operation,
result => $numbers_string,
};
2013-06-21 12:43:57 -07:00
};
2013-06-21 13:34:59 -07:00
1;