Change TINYURL to be more generic (now called SHORTEN), and modify irc.pl to support...
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Mon, 25 Aug 2008 14:04:48 +0000 (14:04 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Mon, 25 Aug 2008 14:04:48 +0000 (14:04 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@52 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml
irc.pl

index 018a4cd..13584e3 100644 (file)
@@ -1474,19 +1474,31 @@ MEMO: |-
        $kernel->post( $src, $replypath, "Memo left for $rec.", $dest );
   }
 
-TINYURL: |-
+SHORTEN: |-
   sub {
-    use WWW::Shorten::TinyURL;
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+    my( $service, $url ) = split( / /, $what, 2 );
+    $service =~ s/[^a-z]//gi;
+    if( length $url ) {
+      eval "use WWW::Shorten::$service";
+      if( $@ ) {
+       $kernel->post( $src, $replypath, "Loading 'WWW::Shorten::$service' failed: $@", $dest );
+       return;
+      }
+    } else {
+      $url = $service;
+      use WWW::Shorten::TinyURL;
+    }
+    my( $kernel, $heap, $who, $url, $src, $dest, $replypath ) = @_;
     if( !exists( $heap->{ 'urls' } ) ) {
       $heap->{ 'urls' } = {};
     }
-    if( exists( $heap->{ 'urls' }->{ uc( $what ) } ) ) {
-      my @arr = @{ $heap->{ 'urls' }->{ uc( $what ) } };
+    if( exists( $heap->{ 'urls' }->{ uc( $url ) } ) ) {
+      my @arr = @{ $heap->{ 'urls' }->{ uc( $url ) } };
       $kernel->post( $src, $replypath, $arr[2]." [first: ".$arr[0]."/".$arr[1]."]", $dest );
     } else {
-      my $url = makeashorterlink( $what ) or return;
-      $heap->{ 'urls' }->{ uc( $what ) } = [ $who, $dest->{ 'dest' }, $url ];
+      my $url = makeashorterlink( $url ) or return;
+      $heap->{ 'urls' }->{ uc( $url ) } = [ $who, $dest->{ 'dest' }, $url ];
       $kernel->post( $src, $replypath, "$url [$who]", $dest );
     }
   }
diff --git a/irc.pl b/irc.pl
index 78dcef5..a20cc26 100644 (file)
--- a/irc.pl
+++ b/irc.pl
@@ -33,11 +33,19 @@ sub new {
        $self->{ "port" } = 6667;
        $self->{ "password" } = "";
        $self->{ "trap" } = 0;
+       $self->{ "trapEnabled" } = 0;
        $self->{ "throttle" } = 0;
        while( $_ = shift ) {
                print( "IRC : Parsing Option '$_'\n" );
                my( $name, $value ) = split( /=/, $_, 2 );
-               if( exists( $self->{ $name } ) ) {
+               if( $name == "trap" ) {
+                       if( $value == 1 ) {
+                               $value = "TinyURL";
+                       }
+                       print( "IRC : Enabling URL trapping using $value\n" );
+                       $self->{ "trap" } = $value;
+                       $self->{ "trapEnabled" } = 1;
+               } elsif( exists( $self->{ $name } ) ) {
                        print( "IRC : Setting $name to $value\n" );
                        $self->{ $name } = $value;
                }
@@ -195,10 +203,10 @@ sub on_public {
        }
        if( $cmd =~ /^[~].*/ ) {
                $kernel->post( "core", "cmd", $who, $msg, $self->{ "ssid" }, $dest->[0], "send_public_to" );
-       } elsif( $msg =~ m!(https?://[^[:space:]]+)!i && $self->{ "trap" } == 1 && length($1) >= 30 ) {
+       } elsif( $msg =~ m!(https?://[^[:space:]]+)!i && $self->{ "trapEnabled" } == 1 && length($1) >= 30 ) {
                print( "IRC : URL Trapped: '$1' from $who\n" );
                my $url = $1;
-               $kernel->post( "core", "cmd", $who, "TINYURL $url", $self->{ "ssid" }, $dest->[0], "send_public_to" );
+               $kernel->post( "core", "cmd", $who, "SHORTEN ".$self->{ "trap" }." $url", $self->{ "ssid" }, $dest->[0], "send_public_to" );
        }
 }