NYES! yet another huuuge slithering Perl horror!

This program adds /gonode command for sirc! It works in two ways:

  • As bare /gonode, it goes to node that was last mentioned in IRC (ie, the last words that appeared in [brackets])
  • And, of course, /gonode wonderland will magically transport thee to the wonderland!

This supports HOWL! extension's advanced WWW stuff (HOWL! is a script of mine, get the most recent version from my home page). Note that the "normal" URL stuff has not been tested, but hey, it's almost cut and paste from www.pl that comes with sirc =)

Downloadable version appearing soon in my home page, at <http://www.iki.fi/wwwwolf/code/sirc/>

Please, send comments to me via E-mail. This is a fairly quick hack and just ItWorksForMe™...

Stuff for the next version

  • Should bail out if we use Perl 4. (I see no reason not to support Perl 4, but this is "suff to do by choice"...)
  • RCS identification might be informative.
  • Bug that sirc doesn't whine about: Now it uses POSIX::setlocale() when it's not imported in use POSIX part...
  • Maybe it should also do reverse-video replace (a la "here's a link!" for some channels? =)
#!/usr/bin/perl -- This is for magic only, please load this from within sirc!
#######################################################################
# Everything2 support for sirc
# Written by Weyfour WWWWolf (Urpo Lankinen)
#
# E-mail:    <wwwwolf@iki.fi>
# Home page: <http://www.iki.fi/wwwwolf/>
# Home node: <http://www.everything2.com/?node=WWWWolf&type=user>
#
# Distributed under the Artistic Lisence. No warranty, dammit.
#######################################################################

use POSIX qw(isalnum);
use vars qw($lastnode $bullet);

&tell("*** sirc E2 extension by WWWWolf - see /help gonode for help.");

########################################################################

# URL escaping function.
# OK, this is pretty bogus, but I guess it's better than including
# CGI.pm for a mere IRC script... =)
sub escaped {
  my $str = shift || die "Some coder used escaped() with no args. Fool.\n";
  my $newstr;

  # What's my locale?
  my $old_locale = POSIX::setlocale(&POSIX::LC_CTYPE);

  # Handle characters the Equally Discriminating Way!
  POSIX::setlocale(&POSIX::LC_CTYPE,"C");

  $str =~ tr/ /+/; # Convert spaces to +'es
  # Iterate over characters; If it's alphanumeric (or plus), use it
  # as it is, else insert it as a %XX hex escape.
  for(my $n = 0; $n < length($str); $n++) {
    my $char = substr($str,$n,1);
    if($char eq '+' or POSIX::isalnum($char)) {
      $newstr .= $char;
    } else {
      $newstr .= "%" . uc sprintf("%02x",ord($char));
    }
  }

  # Return to old locale.
  POSIX::setlocale(&POSIX::LC_CTYPE, $old_locale);

  return $newstr;
}

# The actual command to go to the node.
sub cmd_gonode {
  my $url = "http://www.everything2.com/?node=";

  if($args ne '') { # Has arguments
    $url .= escaped($args);
  } else { # No arguments, go to the last node mentioned.
    $url .= escaped($lastnode);
  }

  &tell("*** Going to $url");
  if($add_ons =~ /\+HOWL/) { # HOWL!'s way of handling this
    eval {                  # Enclosed in eval to avoid (howl-)silence nausea
      &openurl($url);
    };
  } else {                  # The boring old way - NOT TESTED =)
    system("netscape", "-remote", "openURL($url)");
  }
}

# The hook to listen the conversation...
sub hook_e2sniffer {
  my $line = $_[0];
  my $stuff;
  if($line =~ /\[([^\]]+)]/g) {   # Matches [...]
    $stuff = $1;
    if($stuff =~ /|/) {         # Handle [deceptive links|Cool Stuff]
      $stuff =~ /([^|]+)|/;
      $lastnode = $1;
    } else {
      $lastnode = $stuff;
    }
  }
}

########################################################################

# Add the command and help message.
&addcmd("gonode");
&addhelp("gonode","Usage: \cbGONODE\cb [node]
Jumps to specified node in Everything2. If no node is specified, will
jump to last node that was mentioned in the printed messages, private
messages and IRC channels (Nodes should be mentioned in [brackets], just
like in E2 chatterbox and in writeups themselves).

This script will either launch Netscape (as www.pl does), or use the
web browser specified via HOWL! extension if it's loaded.

This extension to sirc was written by Weyfour WWWWolf <wwwwolf\@iki.fi>.
For stuff, say '/gonode Everything2 support for sirc'.

");

# Hook the stuff.
&addhook("print", "e2sniffer");


# Add the gratuitous advertising =)
$add_ons .= "+Everything2" unless $add_ons =~ /\+Everything2/;
$lastnode = "my dog it has three corners"; # =)


More Slithering Perl Horrors!

Log in or registerto write something here or to contact authors.