1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 18:35:49 -04:00

Merge branch 'master' of github.com:simcop2387/perlbuut

This commit is contained in:
Ryan Voots 2011-02-18 21:24:53 -05:00
commit 09344be0b0
2 changed files with 38 additions and 2 deletions

View file

@ -11,7 +11,7 @@ server "*" {
plugin "karma_modify" { addressed: false; }
}
channel "#perl" {
plugin "eval" {addressed: true; }
plugin "deparse" {addressed: true; }
plugin "eval" {addressed: false; }
plugin "deparse" {addressed: false; }
}
}

36
plugins/google.pm Normal file
View file

@ -0,0 +1,36 @@
use LWP::UserAgent;
use HTML::TreeBuilder;
use URI::Escape qw/uri_escape/;
sub {
my( $said )= @_;
my $query = uri_escape( $said->{body} );
my $ua = LWP::UserAgent->new( agent => "Mozilla 5.0" );
my $resp = $ua->get( "http://google.com/search?q=$query" );
if( not $resp->is_success ) {
print "Sorry, got a " . $resp->code . " from google. ";
return;
}
my $tree = HTML::TreeBuilder->new_from_content( $resp->content );
my $first = $tree->look_down( class => "l" );
my $first_desc = $tree->look_down( class => "s" );
print $first->attr('href'), " - ";
print $first->as_text;
print " ";
for( $first_desc->content_list ) {
last if ref $_ and $_->tag eq 'cite';
print ref $_ ? $_->as_text : $_;
}
}
__DATA__
google <Query>; Returns the link and description of the first result from querying google.