Questions about this topic? Sign up to ask in the talk tab.

User:Mike/wikilink.pl

From NetSec
Jump to: navigation, search
use strict;
use Irssi;

Irssi::signal_add 'message public', 'sig_message_public';

sub sig_message_public {
  my ($server, $msg, $nick, $nick_addr, $target, $host, $text) = @_;
  my ($link, $linkname, $article, $artname);
  unless ($target =~ m/(?:ed-logging)/i) { #dofuckall here
    $article = $msg;
    $artname = $msg;
    if ($target =~ m/(?:bha-wiki|csiii)/i) { #works for links in black hat academy - ed for anythign else
      $link = 'http://www.blackhatlibrary.net/';
      $linkname = 'Black Hat Library';
    }
    else {
      $link = 'https://encyclopediadramatica.se/';
      $linkname = 'Encyclopædia Dramatica';
    }
    if ($msg =~ m/^!link (\d|\w|[[:punct:]])/i) {
      if ($msg =~ m/^!link -wp/) {
        $article =~ s/ -wp//;
        $artname =~ s/ -wp//;
        $link = 'http://en.wikipedia.org/wiki/';
        $linkname = 'Wikipedia';
      }
      elsif ($msg =~ m/^!link -bha/) {
        $article =~ s/ -bha//;
        $artname =~ s/ -bha//;
        $link = 'http://www.blackhatlibrary.net/';
        $linkname = 'Black Hat Library';
      }
      elsif ($msg =~ m/^!link -ed/) {
        $article =~ s/ -ed//;
        $artname =~ s/ -ed//;
        $link = 'https://encyclopediadramatica.se/';
        $linkname = 'Encyclopædia Dramatica';
      }
      elsif ($msg =~ m/^!link -lmgtfy/) {
        $article =~ s/ -lmgtfy//;
        $artname =~ s/ -lmgtfy//;
        $link = 'http://lmgtfy.com/?q=';
        $linkname = "\x034L\x0312M\x038G\x0312T\x033F\x038Y\x03";
        $article =~ s/!link\s+//;
        $article =~ s/\s+/\+/g;
      }
      $article =~ s/!link\s+//;
      $artname =~ s/!link\s+//;
      $article =~ s/\s+/_/g;
      $server ->command("msg $target \x02\x1f\x0312$link$article\x1f \x0314[[\x038$artname\x0314]] \x03at $linkname");
    }
    elsif ($msg =~ m/^!lmgtfy (\d|\w|[[:punct:]])/i) { 
      $article =~ s/!lmgtfy\s*//;
      $artname =~ s/!lmgtfy\s*//;
      $link = 'http://lmgtfy.com/?q=';
      $linkname = "\x034L\x0312M\x038G\x0312T\x033F\x038Y\x03";
      $article =~ s/\s+/\+/g;
      $server ->command("msg $target \x02\x1f\x0312$link$article\x1f \x0314[[\x038$artname\x0314]] \x03at $linkname");
    }
  }
}

sub wikilink_self {
  my ($link, $linkname, $article, $artname);
  my ($data, $server,$witem) = @_;
  if ($witem->{name} =~ m/(?:bha-wiki|csiii)/i) { #works for links in black hat academy - ed for anythign else
    $link = 'http://www.blackhatlibrary.net/';
    $linkname = 'Black Hat Library';
  }
  else {
    $link = 'https://encyclopediadramatica.se/';
    $linkname = 'Encyclopædia Dramatica';
  }
  my $article = $data;
  my $artname = $data;
  if ($article =~ m/-wp/) {
    $article =~ s/-wp //;
    $artname =~ s/-wp //;
    $link = 'http://en.wikipedia.org/wiki/';
    $linkname = 'Wikipedia';
  }
  elsif ($article =~ m/-bha/) {
    $article =~ s/-bha //;
    $artname =~ s/-bha //;
    $link = 'http://www.blackhatlibrary.net/';
    $linkname = 'Black Hat Library';
  }
  elsif ($article =~ m/^-ed/) {
    $article =~ s/-ed //;
    $artname =~ s/-ed //;
    $link = 'https://encyclopediadramatica.se/';
    $linkname = 'Encyclopædia Dramatica';
  }
  elsif ($article =~ m/^-lmgtfy/) {
    $article =~ s/-lmgtfy //;
    $artname =~ s/-lmgtfy //;
    $link = 'http://lmgtfy.com/?q=';
    $linkname = "\x034L\x0312M\x038G\x0312T\x033F\x038Y\x03";
    $article =~ s/\s/+/g;
  }
  $article =~ s/!link\s+//;
  $artname =~ s/!link\s+//;
  $article =~ s/\s/_/g;
  $server->command("msg $witem->{name} \x02\x1f\x0312$link$article\x1f \x0314[[\x038$artname\x0314]] \x03at $linkname");
}


Irssi::command_bind('link', 'wikilink_self')