diff options
author | David Phillips <david@sighup.nz> | 2018-04-10 15:20:24 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-04-10 15:20:24 +1200 |
commit | cd1fc57841deab0e9b8bcfad49d527c6b263534c (patch) | |
tree | 83bc8874a4b6970e0850f9aaca3a8c801bce293c /plugin/url_title.pm | |
parent | bb1808b1ef92af9a14a073f2e14973ac132b7e7e (diff) | |
download | idalius-cd1fc57841deab0e9b8bcfad49d527c6b263534c.tar.xz |
Correct capitalisation on module names
Diffstat (limited to 'plugin/url_title.pm')
-rw-r--r-- | plugin/url_title.pm | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/plugin/url_title.pm b/plugin/url_title.pm deleted file mode 100644 index 32995fd..0000000 --- a/plugin/url_title.pm +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env perl - -package plugin::url_title; - -use strict; -use warnings; -use HTTP::Tiny; -use HTML::HeadParser; -use utf8; - -my %config; - -sub configure { - my $self = $_[0]; - my $cmdref = $_[1]; - my $cref = $_[2]; - %config = %$cref; - return $self; -} - -sub message -{ - my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_; - my $url; - - return if ($config{url_on} == 0); - - if ($what =~ /(https?:\/\/[^ ]+)/i) { - $url = $1; - } - return unless $url; - - my $http = HTTP::Tiny->new((default_headers => {'Range' => "bytes=0-65536", 'Accept' => 'text/html'}, timeout => 3)); - - my $response = $http->get($url); - - if (!$response->{success}) { - $logger->("Something broke: $response->{reason}"); - return; - } - - if (!($response->{headers}->{"content-type"} =~ m,text/html ?,)) { - $logger->("Not html, giving up now"); - return; - } - - my $html = $response->{content}; - - my $parser = HTML::HeadParser->new; - $parser->parse($html); - - # get title and unpack from utf8 (assumption) - my $title = $parser->header("title"); - utf8::upgrade($title); - return unless $title; - - my $shorturl = $url; - $shorturl = (substr $url, 0, $config{url_len}) . "β¦" if length ($url) > $config{url_len}; - - # remove http(s):// to avoid triggering other poorly configured bots - $shorturl =~ s,^https?://,,g; - $shorturl =~ s,/$,,g; - - my $composed_title = "$title ($shorturl)"; - return $composed_title; -} -1; |