aboutsummaryrefslogtreecommitdiff
path: root/plugin/url_title.pm
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/url_title.pm')
-rw-r--r--plugin/url_title.pm67
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;