Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes it nicer! #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ inc
Makefile
earl.db
earl.conf
MYMETA.json
MYMETA.yml
blib/
pm_to_blib
3 changes: 3 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ requires 'DBI';
requires 'Date::Format';
requires 'DBD::SQLite';
requires 'Config::General';
requires "WWW::Shorten";

install_script 'earl.pl';

WriteAll;
1 change: 1 addition & 0 deletions earl.conf.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tinyurl 1
detach 1
neverolde ^https?://wiki\.hackspace\.org\.uk
<server>
Expand Down
18 changes: 14 additions & 4 deletions earl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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" );

}
}
}
Expand Down