Permalink
Browse files

Combined !short and !custurl into the !short command.

Usage: !short http://someurl.com
       !short customstring http://someurl.com
  • Loading branch information...
1 parent d007034 commit cbc95de250b1d04d41b32462335ffe393b55919b @wneessen committed Jul 5, 2011
Showing with 24 additions and 27 deletions.
  1. +23 −26 Nelson/Plugin/ShortURL.pm
  2. +1 −1 Nelson/Plugin/URLTitle.pm
@@ -27,37 +27,34 @@ sub initialize {
sub message {
my ($self, $message) = @_;
- if($message->text =~ m#^!short (https?://\S+)#i) {
+ if($message->text =~ m#^!short\s+(\S+)?\s?(https?://\S+)#i) {
my $url = new URI('http://nop.li/yourls-api.php');
- $url->query_form(
- action => 'shorturl',
- url => $1,
- username => $self->{username},
- password => $self->{password},
- format => 'simple',
- );
+ my $longurl = $2;
+ my $custom = $1;
- my $result = $self->mechanize->get($url);
+ if(defined($custom)) {
+
+ $url->query_form(
+ action => 'shorturl',
+ url => $longurl,
+ keyword => $custom,
+ username => $self->{username},
+ password => $self->{password},
+ format => 'simple',
+ );
- if(defined($result) and length($result)) {
- $message->reply($self->mechanize->content);
} else {
- $message->reply("Nop! You stink!");
- }
- }
-
- if($message->text =~ m#^!custurl (\S+) (https?://\S+)#i) {
- my $url = new URI('http://nop.li/yourls-api.php');
+
+ $url->query_form(
+ action => 'shorturl',
+ url => $longurl,
+ username => $self->{username},
+ password => $self->{password},
+ format => 'simple',
+ );
- $url->query_form(
- action => 'shorturl',
- url => $2,
- keyword => $1,
- username => $self->{username},
- password => $self->{password},
- format => 'simple',
- );
+ }
my $result = $self->mechanize->get($url);
@@ -67,7 +64,7 @@ sub message {
$message->reply("Nop! You stink!");
}
}
-
+
return 1;
}
@@ -21,7 +21,7 @@ sub message {
$self->{_mechanize} ||= new WWW::Mechanize ( autocheck => 0, timeout => 2 );
- if($message->text =~ m#(https?://\S+)#i and $message->text !~ m#^!short# and $message->text !~ m#^!custurl#) {
+ if($message->text =~ m#(https?://\S+)#i and $message->text !~ m#^!short#) {
my $url = $1;
return 1 if $url =~ m#http://www.imdb.com/title/#i;
my $head = $self->mechanize->head($url);

0 comments on commit cbc95de

Please sign in to comment.