]> git.donarmstrong.com Git - infobot.git/commitdiff
* Retired the old broken W3Search module in favour of a working Google search
authordjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Tue, 2 Dec 2008 20:12:09 +0000 (20:12 +0000)
committerdjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Tue, 2 Dec 2008 20:12:09 +0000 (20:12 +0000)
* 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
THANKS
files/sample/infobot.chan
src/CommandStubs.pl
src/Modules/Google.pl [new file with mode: 0644]
src/Modules/W3Search.pl [deleted file]

index 45903ae0b36b2b151b3dca75b15e4e61b0be7424..749fd2d2fa86680abffbd544dd3602dd42660416 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 * 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 8216bcf6d0d848eb9e88b99eff12f74a174c934b..3699e191f5cfa07d52826dcdcc341cf962c761ab 100644 (file)
--- 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
index a9742aeca81f24e17cf56687bcbca02818cba705..07a2811ca327f307364cc0fcb9f5137661d4798c 100644 (file)
@@ -37,6 +37,7 @@ _default
     +Dict
     +Exchange
     +Factoids
+    +Google
     +HTTPDtype
     +Kernel
     +Math
@@ -48,7 +49,6 @@ _default
     +Topic
     +Units
     +UserInfo
-    +W3Search
     +Weather
     +Zippy
     addressCharacter ~
index 82886a780f60494fb861f6528fd3c73bb0a61443..e66e6d8dcd99b823f518444d08f3a3144b5e2dee 100644 (file)
@@ -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 (file)
index 0000000..f6762e2
--- /dev/null
@@ -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 <db@cave.za.net> 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 (file)
index 27bdbd7..0000000
+++ /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