/lib/DDG/Spice/Twitter.pm

https://github.com/pardocz/zeroclickinfo-spice · Perl · 35 lines · 28 code · 6 blank · 1 comment · 1 complexity · 6dd2b5e17f53b2e1a4300634f236f83e MD5 · raw file

  1. package DDG::Spice::Twitter;
  2. use DDG::Spice;
  3. primary_example_queries '@duckduckgo';
  4. secondary_example_queries "twitter yegg";
  5. description "Shows a user's latest tweet.";
  6. name "Twitter";
  7. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Twitter.pm";
  8. topics "everyday", "social";
  9. category "time_sensitive";
  10. attribution github => ["https://github.com/duckduckgo/", "DuckDuckGo"],
  11. twitter => ["https://twitter.com/duckduckgo", "duckduckgo"],
  12. github => ["https://github.com/ecounysis/", "Eric Christensen"],
  13. twitter => ["https://twitter.com/ecounysis", "Eric Christensen"];
  14. spice to => 'https://duckduckgo.com/tw.js?user=$1&callback={{callback}}&current=1';
  15. triggers query => qr/^(?:twitter\s)?@([a-z0-9_]+)$|^twitter\s([a-z0-9_]+)$/i;
  16. # Possibly add skip words to a file for slurping?
  17. my $skip = join "|", ("apis?",
  18. "developers?",
  19. "users?",
  20. "search(es)?");
  21. handle matches => sub {
  22. if ($1) {
  23. return $1;
  24. } elsif ($2) {
  25. return $2 unless ($2 =~ m/^($skip)$/i)
  26. }
  27. return;
  28. };
  29. 1;