From 5e1577f54b095891e29f996828b58a8bd109c37a Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Wed, 9 Feb 2011 14:57:13 -0500 Subject: [PATCH 1/2] updating the factoids --- etc/plugins.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/plugins.conf b/etc/plugins.conf index cf0c84c..8a0d9e4 100644 --- a/etc/plugins.conf +++ b/etc/plugins.conf @@ -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; } } } From a3509d5aebb0d3b1ebb956a82a5069c6b3c1ed6b Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Thu, 17 Feb 2011 10:45:58 -0500 Subject: [PATCH 2/2] adding google plugin --- plugins/google.pm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 plugins/google.pm diff --git a/plugins/google.pm b/plugins/google.pm new file mode 100644 index 0000000..7f40560 --- /dev/null +++ b/plugins/google.pm @@ -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 ; Returns the link and description of the first result from querying google.