/lib/DDG/Spice/Drinks.pm

https://github.com/pardocz/zeroclickinfo-spice · Perl · 47 lines · 34 code · 9 blank · 4 comment · 3 complexity · 51aea98474c7b6fc4ab87ce8dc8bb2c8 MD5 · raw file

  1. package DDG::Spice::Drinks;
  2. use DDG::Spice;
  3. primary_example_queries "how to mix a tom collins";
  4. secondary_example_queries "mixing 007", "how to make a 1.21 gigawatts";
  5. description "Bartending info";
  6. name "Drinks";
  7. source "Drink Project";
  8. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Drinks.pm";
  9. topics "food_and_drink";
  10. category "entertainment";
  11. attribution github => ['https://github.com/mutilator','mutilator'];
  12. triggers any => "mix", "make";
  13. triggers startend => "drink", "ingredients", "mixing", "making";
  14. spice to => 'http://drinkproject.com/api/?type=json&name=$1&callback={{callback}}';
  15. handle query_lc => sub {
  16. my $drink;
  17. # enforce "drink" to be in queries with
  18. # "make" or "making"
  19. # too ambiguous otherwise
  20. # e.g. "making a rails 4 backend"
  21. if (/^(?:how to make|making) an? (.+)/){
  22. $drink = $1;
  23. return unless $drink =~ /\bdrink\b/;
  24. } elsif (/^(?:how to mix|mixing) an? (.+)/){
  25. $drink = $1;
  26. } elsif (/^ingredients for an? (.+)|(.+) ingredients/){
  27. $drink = $1||$2;
  28. } elsif (/^(.+) drink$|^drink (.+)$/){
  29. $drink = $1;
  30. }
  31. if ($drink){
  32. $drink =~ s/drink//g;
  33. $drink =~ s/^\s+|\s+$//g;
  34. return $drink;
  35. }
  36. return;
  37. };
  38. 1;