]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/zsi.pl
zfi/zsi searching for #zaurus
[infobot.git] / src / Modules / zsi.pl
diff --git a/src/Modules/zsi.pl b/src/Modules/zsi.pl
new file mode 100644 (file)
index 0000000..51600a5
--- /dev/null
@@ -0,0 +1,103 @@
+package zsi;
+
+# Search Zaurus Software Index (ZSI)
+# Version 1.0
+# Released 26 Aug 2002
+
+# Developed by Darien Kruss <darien@kruss.com>
+# http://zaurus.kruss.com/
+# usually hangs out on #zaurus as 'darienm'
+
+# This script relies on the following page returning results
+# http://killefiz.de/zaurus/zsibot.php
+# Returns the 5 latest/newest entries
+
+# http://killefiz.de/zaurus/zsibot.php?query=XXXX
+# Returns all matches where XXX is in the name, description, etc
+
+# Returned matches are pipe-separated, one record per line
+# name|URL|description
+
+# These are the phrases we get called for:
+
+# 'zsi'  or  'zsi <search>'
+
+# We reply publicly or privately, depending how we were called
+
+my $no_zsi;
+
+BEGIN {
+       $no_zsi = 0;
+       eval "use LWP::UserAgent";
+       $no_zsi++ if ($@);
+}
+
+sub queryText {
+       my ($query) = @_;
+
+       if ($no_zsi) {
+               &main::status("zsi module requires LWP::UserAgent.");
+               return '';
+       }
+
+       my $res_return = 5;
+
+       my $ua = new LWP::UserAgent;
+  $ua->proxy('http', $::param{'httpProxy'}) if (&::IsParam("httpProxy"));
+
+       $ua->timeout(10);
+
+       my $searchpath;
+       if ($query) {
+               $searchpath = "http://killefiz.de/zaurus/zsibot.php?query=$query";
+       } else {
+               $searchpath = "http://killefiz.de/zaurus/zsibot.php";
+       }
+
+       my $request = new HTTP::Request('GET', "$searchpath");
+       my $response = $ua->request($request); 
+
+       if (!$response->is_success) {
+               return "Something failed in connecting to the ZSI web server. Try again later.";
+       }
+
+       my $content = $response->content;
+
+       if ($content =~ /No entries found/im) {
+               return "$result No results were found searching ZSI for '$query'.";
+       }
+
+       my $res_count = 0; #local counter
+       my $res_display = 0; #results displayed
+
+       my @lines = split(/\n/,$content);
+
+       my $result = '';
+       foreach $line(@lines) {
+               if (length($line) > 10) {
+                       my ($name, $href, $desc) = split(/\|/,$line);
+
+                       if ($res_count < $res_return) {
+                               $result .= "$name ($desc) $href\n";
+                               $res_display ++;
+                       }
+                       $res_count ++;
+               }
+       }
+
+       if (($query) && ($res_count > $res_display)) {
+               $result .= "$res_display of $res_count shown. All at http://killefiz.de/zaurus/search.php?q=$query\n";
+       }
+
+       return $result;
+}
+
+sub query {
+       my ($args) = @_;
+       &::performStrictReply(&queryText($args));
+  return;
+}
+
+1;
+# vim: shiftwidth=2 tabstop=2
+__END__