| Bot-BasicBot-Pluggable documentation | Contained in the Bot-BasicBot-Pluggable distribution. |
Bot::BasicBot::Pluggable::Module::Google - searches Google for terms and spellings
version 0.93
Returns Google hits for the terms given.
Returns a Google spelling suggestion for the term given.
To set module variables, use Bot::BasicBot::Pluggable::Module::Vars.
A valid Google API key is required for lookups.
Defaults to 'en'; a space-separated list of language restrictions.
Defaults to 3; the number of Google search results to return (maximum 10).
Defaults to 1; whether you need to address the bot for Google searches.
Net::Google
Mario Domgoergen <mdom@cpan.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Bot-BasicBot-Pluggable documentation | Contained in the Bot-BasicBot-Pluggable distribution. |
package Bot::BasicBot::Pluggable::Module::Google; BEGIN { $Bot::BasicBot::Pluggable::Module::Google::VERSION = '0.93'; } use base qw(Bot::BasicBot::Pluggable::Module); use warnings; use strict; use Net::Google; sub init { my $self = shift; $self->config( { user_google_key => "** SET ME FOR GOOGLE LOOKUPS **", user_languages => "en", user_num_results => 3, user_require_addressing => 1, } ); } sub help { return "Searches Google for terms and spellings. Usage: google <terms>, spell <words>."; } sub told { my ( $self, $mess ) = @_; my $body = $mess->{body}; return if ( $self->get("user_require_addressing") and not $mess->{address} ); my ( $command, $param ) = split( /\s+/, $body, 2 ); $command = lc($command); if ( $command eq "google" ) { return "No Google key has been set! Set it with '!set Google google_key <key>'." unless $self->get("user_google_key"); return "Your configuration has exceeded the maximum number of allowed Google results (10)." if $self->get("user_num_results") > 10; my $google = Net::Google->new( key => $self->get("user_google_key") ); my $search = $google->search( lr => qw($self->get("user_languages")), max_results => $self->get("user_num_results") ); $search->query( split( /\s+/, $param ) ); my $res; # magical concatenation of all results. $res .= $_->title . ": " . $_->URL . "\n" for @{ $search->results() }; $res =~ s/<[^>]+>//g; # remove the bolded search terms. return $res ? $res : "No results for \'$param\'."; } elsif ( $command eq "spell" ) { return "No Google key has been set! Set it with '!set Google google_key <key>'." unless $self->get("user_google_key"); my $google = Net::Google->new( key => $self->get("user_google_key") ); my $res = $google->spelling( phrase => $param )->suggest(); return $res ? $res : "No results for \'$param\'."; } } 1; __END__