PageRenderTime 268ms CodeModel.GetById 31ms RepoModel.GetById 5ms app.codeStats 0ms

/lib/RoboDuck/Plugin/Links.pm

https://github.com/8dx/duckduckgo-roboduck
Perl | 111 lines | 93 code | 11 blank | 7 comment | 1 complexity | d564cd4efa5d0b5ffa389b55710f130b MD5 | raw file
  1. package RoboDuck::Plugin::Links;
  2. use 5.10.0;
  3. use Moses::Plugin;
  4. use String::Trim;
  5. my %links = (
  6. # duckduckgo.com/*.html / etc.
  7. "goodie" => "https://duckduckgo.com/goodies.html",
  8. "bang" => "https://duckduckgo.com/bang.html",
  9. "newbang" => "https://duckduckgo.com/newbang.html",
  10. "about" => "https://duckduckgo.com/about.html",
  11. "setting" => "https://duckduckgo.com/settings.html",
  12. "param" => "https://duckduckgo.com/params.html",
  13. "privacy" => "https://duckduckgo.com/privacy.html",
  14. "feedback" => "https://duckduckgo.com/feedback.html",
  15. "spread" => "https://duckduckgo.com/spread.html",
  16. "traffic" => "https://duckduckgo.com/traffic.html",
  17. "tech" => "https://duckduckgo.com/tech.html",
  18. "searchbox" => "https://duckduckgo.com/search_box.html",
  19. "api" => "https://api.duckduckgo.com/",
  20. "homepage" => "https://duckduckgo.com/",
  21. "home" => \"homepage",
  22. "h" => \"homepage",
  23. "shorturl" => "http://ddg.gg/",
  24. # minisites
  25. "dontbubble"=> "http://dontbubble.us/",
  26. "donttrack" => "http://donttrack.us/",
  27. "duckduckhack"=> "http://duckduckhack.com/",
  28. "hack" => \"duckduckhack",
  29. "ddh" => \"duckduckhack",
  30. # other DDG sites
  31. "help" => "https://help.duckduckgo.com/",
  32. "community" => "https://dukgo.com/",
  33. "forum" => "https://duck.co/",
  34. "duckpan" => "http://duckpan.org/",
  35. # social
  36. "twitter" => "https://twitter.com/duckduckgo",
  37. "facebook" => "https://facebook.com/duckduckgo",
  38. "sticker" => "https://www.stickermule.com/duckduckgo",
  39. "github" => "https://github.com/duckduckgo",
  40. "store" => "http://cafepress.com/duckduckgo",
  41. "reddit" => "http://www.reddit.com/r/duckduckgo",
  42. "identica" => "https://identi.ca/duckduckgo",
  43. "diaspora" => "https://joindiaspora.com/u/duckduckgo",
  44. # official ddg articles (help.ddg, blogposts, etc)
  45. "browser" => "http://help.duckduckgo.com/customer/portal/articles/216425-browsers",
  46. "addsite" => "http://help.duckduckgo.com/customer/portal/articles/216407",
  47. "addad" => "http://help.duckduckgo.com/customer/portal/articles/216405",
  48. "syntax" => "http://help.duckduckgo.com/customer/portal/articles/300304-syntax",
  49. "image" => "http://help.duckduckgo.com/customer/portal/articles/215615-images",
  50. "email" => "http://help.duckduckgo.com/customer/portal/articles/215614-email",
  51. "history" => "http://help.duckduckgo.com/customer/portal/articles/216406-history",
  52. "source" => "http://help.duckduckgo.com/customer/portal/articles/216399-sources",
  53. "spam" => "http://help.duckduckgo.com/customer/portal/articles/215611-spam",
  54. "logo" => "http://help.duckduckgo.com/customer/portal/articles/485613-holiday-logos",
  55. "pii" => "http://www.gabrielweinberg.com/blog/2010/11/how-to-not-log-personally-identifiable-information.html",
  56. # specific browsers
  57. "firefox" => "http://help.duckduckgo.com/customer/portal/articles/216441-firefox",
  58. "chrome" => "http://help.duckduckgo.com/customer/en/portal/articles/216440",
  59. "opera" => "http://help.duckduckgo.com/customer/portal/articles/216453-opera",
  60. "safari" => "http://help.duckduckgo.com/customer/portal/articles/216447-safari",
  61. "android" => "http://help.duckduckgo.com/customer/portal/articles/216461-android",
  62. "ie" => "http://help.duckduckgo.com/customer/portal/articles/216464-internet-explorer",
  63. "omniweb" => "http://help.duckduckgo.com/customer/portal/articles/216459-omniweb",
  64. "epiphany" => "http://help.duckduckgo.com/customer/portal/articles/216460-epiphany",
  65. "conkeror" => "http://help.duckduckgo.com/customer/portal/articles/216462-conkeror",
  66. # random
  67. "soul" => "http://www.youtube.com/watch?v=XvwK-3cQ6gE",
  68. "die" => "http://www.youtube.com/watch?v=K5sANHYp_IQ",
  69. );
  70. sub give_link {
  71. my ( $self, $channels, $target, $key ) = @_;
  72. my $reply;
  73. $key =~ s/[-_']//g;
  74. $key =~ s/s$//;
  75. if ( exists $links{$key} ) {
  76. my $value = $links{$key};
  77. $reply = ref $value eq 'SCALAR' ? $links{$$value} : $value;
  78. } else {
  79. $reply = "I don't have a link to \"$key\"";
  80. }
  81. $self->privmsg( $_ => "$target: ".$reply ) for @$$channels;
  82. }
  83. sub S_public {
  84. my ( $self, $irc, $nickstring, $channels, $message ) = @_;
  85. my ( $nick ) = split /!/, $$nickstring;
  86. my $mynick = $self->nick;
  87. my $reply;
  88. $message = lc($$message);
  89. given ($message) {
  90. when (/^\.(\w+)(\s+[^\s]+)?$/) {
  91. my $target = trim($2);
  92. $target = ($target) ? $target : $nick;
  93. $self->give_link( $channels, $target, $1 );
  94. return PCI_EAT_ALL;
  95. }
  96. }
  97. }
  98. 1;
  99. __END__