diff --git a/.gitignore b/.gitignore index 6c65321..e3c16b0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ inc Makefile earl.db earl.conf +MYMETA.json +MYMETA.yml +blib/ +pm_to_blib diff --git a/Makefile.PL b/Makefile.PL index 1d4bf90..b644c66 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,5 +16,8 @@ requires 'DBI'; requires 'Date::Format'; requires 'DBD::SQLite'; requires 'Config::General'; +requires "WWW::Shorten"; + +install_script 'earl.pl'; WriteAll; diff --git a/earl.conf.example b/earl.conf.example index 931a1c8..0370d44 100644 --- a/earl.conf.example +++ b/earl.conf.example @@ -1,3 +1,4 @@ +tinyurl 1 detach 1 neverolde ^https?://wiki\.hackspace\.org\.uk <server> diff --git a/earl.pl b/earl.pl index 72482f7..8e64fc3 100755 --- a/earl.pl +++ b/earl.pl @@ -15,6 +15,7 @@ package Bot; use Date::Format; use DBD::SQLite; use Config::General; +use WWW::Shorten "TinyURL"; my $configFile = 'earl.conf'; my $conf = new Config::General( @@ -86,28 +87,37 @@ sub said { return if $self->ignore_nick($args->{who}); - for ( list_uris( $args->{body} ) ) { - next unless $_ =~ /^http/i; + for my $uri ( list_uris( $args->{body} ) ) { + next unless $uri =~ /^http/i; - if ( my $reply = get_response( $_ ) ) { + if ( my $reply = get_response( $uri ) ) { # Sanitise the reply to only include printable chars $reply =~ s/[^[:print:]]//g; # See if this has been posted before, unless it's a whitelisted URL my $neverolde = $config{ 'neverolde' } || '^$'; - my %result = log_uri( $_, $args->{channel}, $args->{who} ) unless $_ =~ m/$neverolde/i; + my %result = log_uri( $uri, $args->{channel}, $args->{who} ) unless $uri =~ m/$neverolde/i; my $olde = ''; if (%result) { $olde = ' (First posted by '.$result{'nick'}.', '.time2str('%C', $result{'timestamp'}).')'; } + if (length($uri) > 60 and $config{tinyurl}) { + my $short = makeashorterlink($uri); + if ($short) { + $reply .= " [ $short ]"; + } + } + # Make sure the reply fits in one IRC message my $maxLen = 250 - length($olde); if (length($reply) > $maxLen) { $reply = substr($reply, 0, $maxLen) . '...'; } + $self->reply( $args, "[ $reply ]$olde" ); + } } }