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