Permalink
Browse files

Added Google plugin

  • Loading branch information...
1 parent cc4f14c commit d0c8e4869abdb75ff114a1e44ec77ca9928ea6dc @tadzik committed May 23, 2010
Showing with 36 additions and 0 deletions.
  1. +1 −0 README
  2. +35 −0 a8bot/Plugin/Google.pm
View
@@ -5,3 +5,4 @@ Required modules:
LWP (for WebTitle plugin)
Sys::SigAction (for WebTitle plugin)
Hash::MultiValue (for Powiedz plugin)
+ REST::Google::Search, HTML::Entities (for Google plugin)
@@ -0,0 +1,35 @@
+package a8bot::Plugin::Google;
+use Moose;
+use REST::Google::Search;
+use HTML::Entities;
+use Encode;
+with 'a8bot::Plugin';
+
+sub BUILD {
+ my $self = shift;
+ $self->keyword('g');
+ $self->keyword_cb(sub { pubmsg(@_) });
+}
+
+sub pubmsg {
+ my (%data) = @_;
+ my @args = @{$data{args} // []};
+ if ($#args < 0) {
+ return "$data{nick}: Usage: g <keywords>";
+ }
+ REST::Google::Search->http_referer('http://www.autom8.pl');
+ my $res = REST::Google::Search->new(
+ q => join(' ', @args)
+ );
+ my $pres = $res->{responseData}->{results}->[0];
+ if ($pres) {
+ decode_entities($pres->{titleNoFormatting});
+ return encode('utf8', "$data{nick}: $pres->{titleNoFormatting} -- $pres->{unescapedUrl}");
+ } else {
+ return "$data{nick}: nic nie znaleziono";
+ }
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;

0 comments on commit d0c8e48

Please sign in to comment.