use strict; use Irssi; use LWP::UserAgent; use HTML::Entities; use vars qw($VERSION %IRSSI @blacklist); $VERSION = '20081117'; %IRSSI = ( authors => 'Domen Puncer', contact => 'domen@coderock.org', name => 'html_title', description => 'retrieve of a document pointed by url', license => 'Public Domain', ); @blacklist = ( "^\Qhttp://rafb.net\E", "^\Qhttp://pastebin\E"); sub title_query { my ($query) = @_; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/5.0 (compatible; irssi/0.1)'); $ua->max_size(1024); $ua->timeout(3); my $result = $ua->get($query); my $content = $result->content; my $title; if ($content =~ /\<title\>\s*(.*?)\s*\<\/title\>/i) { my $s = substr $1, 0, 128; decode_entities($s); $s = 'Request syntax FAIL' if ($s =~ /^400 / ); $s = 'Password FAIL' if ($s =~ /^401 / ); $s = 'Not allowed FAIL' if ($s =~ /^403 / ); $s = 'Locate url FAIL' if ($s =~ /^404 / ); $s = 'Internal server FAIL' if ($s =~ /^500 / ); $s = 'Server available... not... FAIL' if ($s =~ /^503 / ); $title = "^ $s"; } return $title; } sub message_public { my ($server, $msg, $nick, $address, $target) = @_; foreach (@blacklist) { if ($msg =~ /$_/) { return undef; } } # only if nothing (hopefully a comment with description?) precedes url if ($msg =~ /^(http\S+)/) { my $title = title_query($1); if ($title) { $server->command("MSG $target $title"); } } } sub message_private { my ($server, $msg, $nick, $address) = @_; message_public($server, $msg, $nick, $address, $nick); } sub message_own_public { my ($server, $msg, $target) = @_; message_public($server, $msg, $server->{nick}, 0, $target); } sub message_own_private { my ($server, $msg, $target, $otarget) = @_; message_public($server, $msg, $server->{nick}, 0, $target); } Irssi::signal_add('message public', 'message_public'); Irssi::signal_add('message private', 'message_private'); Irssi::signal_add('message own_public', 'message_own_public'); Irssi::signal_add('message own_private', 'message_own_private');