Skip to content

Commit

Permalink
WebTitle adopted
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed May 23, 2010
1 parent 8b1b536 commit 4ece89e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions a8bot/Plugin/WebTitle.pm
Original file line number Original file line Diff line number Diff line change
@@ -1,17 +1,26 @@
package WebTitle; package a8bot::Plugin::WebTitle;
use Moose;
use LWP::Simple qw /get $ua/; use LWP::Simple qw /get $ua/;
use Sys::SigAction qw /timeout_call/;
with 'a8bot::Plugin';


sub init { sub BUILD {
return { publicmsg => \&pubmsg }; my $self = shift;
$self->passive_cb(sub { pubmsg(@_) });
} }


sub pubmsg { sub pubmsg {
my ($bot, $data) = @_; my (%data) = @_;
if ($data->{msg} =~ /(http:\/\/[^ ]+)/) { if ($data{msg} =~ /(http:\/\/[^ ]+)/) {
$ua->max_size(1024); $ua->max_size(1024);
my $site = get($1); our $site;
my ($title) = $site =~ /<title>([^<]+)<\/title>/; if (timeout_call(8, sub {$site = get($1)})){
return "[ $title ]" if $title; return undef;
} else {
my ($title) = $site =~ /<title>([^<]+)<\/title>/i;
$title =~ s/\n/ /g;
return "[ $title ]" if $title;
}
} }
return undef; return undef;
} }
Expand Down

0 comments on commit 4ece89e

Please sign in to comment.