$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 );
}
}
$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;
}
}
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" );
}
}