From 3ed9ef94139df2c011890b52f838643f0f8061e4 Mon Sep 17 00:00:00 2001 From: djmcgrath Date: Tue, 2 Dec 2008 20:12:09 +0000 Subject: [PATCH] * Retired the old broken W3Search module in favour of a working Google search * Removed +W3Search in infobot.chan, added +Google (update your configs!) git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1853 c11ca15a-4712-0410-83d8-924469b57eb5 --- ChangeLog | 5 +++ THANKS | 5 +++ files/sample/infobot.chan | 2 +- src/CommandStubs.pl | 11 +++---- src/Modules/Google.pl | 51 +++++++++++++++++++++++++++++ src/Modules/W3Search.pl | 67 --------------------------------------- 6 files changed, 67 insertions(+), 74 deletions(-) create mode 100644 src/Modules/Google.pl delete mode 100644 src/Modules/W3Search.pl diff --git a/ChangeLog b/ChangeLog index 45903ae..749fd2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,11 @@ * check for and use of old blootbot.(users|chan) files +* Retired the old broken W3Search module in favour of a working Google search + +* Removed +W3Search in infobot.chan, added +Google (don't forget to update your +configs) + 1.5.3 ===== diff --git a/THANKS b/THANKS index 8216bcf..3699e19 100644 --- a/THANKS +++ b/THANKS @@ -12,6 +12,10 @@ other another, or people who we feel we owe thanks to in one way or another. If we missed you from this list, drop us a line and we will be sure to give credit where it is due. +#People +------- + +Brett Cave (Google search) #perl@freenode.net ------------------ @@ -32,4 +36,5 @@ jagerman --------------------- quin - many thanks for ctcp version bug help + # vim:ts=4:sw=4:expandtab:tw=80 diff --git a/files/sample/infobot.chan b/files/sample/infobot.chan index a9742ae..07a2811 100644 --- a/files/sample/infobot.chan +++ b/files/sample/infobot.chan @@ -37,6 +37,7 @@ _default +Dict +Exchange +Factoids + +Google +HTTPDtype +Kernel +Math @@ -48,7 +49,6 @@ _default +Topic +Units +UserInfo - +W3Search +Weather +Zippy addressCharacter ~ diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 82886a7..e66e6d8 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -182,17 +182,16 @@ sub Modules { return; } - # google searching. Simon++ - my $w3search_regex = 'google'; + # google searching -- thanks Brett Cave if ( $message =~ - /^(?:search\s+)?($w3search_regex)\s+(?:for\s+)?['"]?(.*?)["']?\s*\?*$/i + /^(\s+)?google\s+['"]?(.*?)["']?\s*\?*$/i ) { - return unless ( &IsChanConfOrWarn('W3Search') ); + return unless ( &IsChanConfOrWarn('Google') ); - &Forker( 'W3Search', sub { &W3Search::W3Search( $1, $2 ); } ); + &Forker( 'Google', sub { &Google::GoogleSearch( $2 ); } ); - $cmdstats{'W3Search'}++; + $cmdstats{'Google'}++; return; } diff --git a/src/Modules/Google.pl b/src/Modules/Google.pl new file mode 100644 index 0000000..f6762e2 --- /dev/null +++ b/src/Modules/Google.pl @@ -0,0 +1,51 @@ +# W3Search drastically altered back to GoogleSearch as Search::Google +# was deprecated and requires a key that google no longer provides. +# This new module uses REST::Google::Search +# Modified by db 12-01-2008. + +package Google; + +use strict; + +my $maxshow = 5; + +sub GoogleSearch { + my ( $what, $type ) = @_; + my $where = "Google"; + my $retval = "$where can't find \002$what\002"; + my $Search; + + return unless &::loadPerlModule("REST::Google::Search"); + + REST::Google::Search->http_referer('http://infobot.sourceforge.net/'); + $Search = REST::Google::Search->new( q => $what ); + + if ( !defined $Search ) { + &::msg( $::who, "$where is invalid search." ); + return; + } + + if ( $Search->responseStatus != 200 ) { + &::msg( $::who, "http error returned." ); + return; + } + + my $data = $Search->responseData; + my $cursor = $data->cursor; + my @results = $data->results; + + my $count; + $retval = "$where says \002$what\002 is at "; + foreach my $r (@results) { + my $url = $r->url; + $retval .= ' or ' if ( $count > 0 ); + $retval .= $url; + last if ++$count >= $maxshow; + } + + &::performStrictReply($retval); +} + +1; + +# vim:ts=4:sw=4:expandtab:tw=80 diff --git a/src/Modules/W3Search.pl b/src/Modules/W3Search.pl deleted file mode 100644 index 27bdbd7..0000000 --- a/src/Modules/W3Search.pl +++ /dev/null @@ -1,67 +0,0 @@ -# WWWSearch backend, with queries updating the is-db (optionally) -# Uses WWW::Search::Google and WWW::Search -# originally Google.pl, drastically altered. - -package W3Search; - -use strict; -use vars qw(@W3Search_engines $W3Search_regex); - -@W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek - Lycos Magellan PLweb SFgate Simple Verity Google z); -$W3Search_regex = join '|', @W3Search_engines; - -my $maxshow = 5; - -sub W3Search { - my ( $where, $what, $type ) = @_; - my $retval = "$where can't find \002$what\002"; - my $Search; - - my @matches = grep { lc($_) eq lc($where) ? $_ : undef } @W3Search_engines; - if (@matches) { - $where = shift @matches; - } - else { - &::msg( $::who, "i don't know how to check '$where'" ); - return; - } - - return unless &::loadPerlModule("WWW::Search"); - - eval { $Search = new WWW::Search( $where, agent_name => 'Mozilla/4.5' ); }; - - if ( !defined $Search ) { - &::msg( $::who, "$where is invalid search." ); - return; - } - - my $Query = WWW::Search::escape_query($what); - $Search->native_query( - $Query, - { - num => 10, - - # search_debug => 2, - # search_parse_debug => 2, - } - ); - $Search->http_proxy( $::param{'httpProxy'} ) if ( &::IsParam('httpProxy') ); - - #my $max = $Search->maximum_to_retrieve(10); # DOES NOT WORK. - - my ( @results, $count, $r ); - $retval = "$where says \002$what\002 is at "; - while ( $r = $Search->next_result() ) { - my $url = $r->url(); - $retval .= ' or ' if ( $count > 0 ); - $retval .= $url; - last if ++$count >= $maxshow; - } - - &::performStrictReply($retval); -} - -1; - -# vim:ts=4:sw=4:expandtab:tw=80 -- 2.39.2