2013-06-21 13:34:59 -07:00
|
|
|
package DDG::Goodie::HelpLine;
|
2014-08-20 11:45:33 -07:00
|
|
|
# ABSTRACT: Provide localized suicide intervention phone numbers.
|
2013-06-21 12:43:57 -07:00
|
|
|
|
2015-02-22 12:09:29 -08: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';
|
2013-06-24 11:33:36 -07:00
|
|
|
|
2015-05-29 15:18:03 -07:00
|
|
|
my $triggers = LoadFile(share('triggers.yml'));
|
2014-10-06 06:13:35 -07:00
|
|
|
|
|
|
|
triggers any => @$triggers;
|
2013-06-24 11:33:36 -07:00
|
|
|
|
2013-06-21 12:43:57 -07:00
|
|
|
zci answer_type => 'helpline';
|
2014-09-27 06:42:57 -07:00
|
|
|
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';
|
2014-01-23 14:13:20 -08:00
|
|
|
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'));
|
2014-10-06 06:13:35 -07:00
|
|
|
my %suicide_phrases = map { $_ => 1 } @$triggers;
|
2013-06-21 12:43:57 -07:00
|
|
|
|
2013-06-24 11:33:36 -07:00
|
|
|
handle query_lc => sub {
|
|
|
|
my $query = shift;
|
2014-01-23 14:13:20 -08:00
|
|
|
|
|
|
|
return unless exists $suicide_phrases{$query};
|
|
|
|
|
|
|
|
# Display the result.
|
2014-10-06 06:13:35 -07:00
|
|
|
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;
|