]> git.donarmstrong.com Git - infobot.git/commitdiff
plug.org, there should be a general xml news app...
authortimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 2 Nov 2002 06:01:01 +0000 (06:01 +0000)
committertimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 2 Nov 2002 06:01:01 +0000 (06:01 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@591 c11ca15a-4712-0410-83d8-924469b57eb5

src/CommandStubs.pl
src/IRC/Schedulers.pl
src/Modules/Plug.pl [new file with mode: 0644]
src/modules.pl

index 9c68e2cf5d8005ba08bcdacf26c9e6184e24e010..32e1005733da8c0b3312cdd8d5ded63b4f465716 100644 (file)
@@ -208,6 +208,9 @@ sub parseCmdHook {
 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
        'Identifier' => 'slashdot', 'Forker' => 1,
        'Cmdstats' => 'Slashdot') );
+&addCmdHook("extra", 'plug', ('CODEREF' => 'Plug::Plug',
+       'Identifier' => 'plug', 'Forker' => 1,
+       'Cmdstats' => 'Plug') );
 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
        'Cmdstats' => 'Uptime') );
 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
index b169c66904aef9bfedb9d3d6471f398b5ed7a578..be8099133cd41a0dac84dc74f0ea369882e4689c 100644 (file)
@@ -34,6 +34,7 @@ sub setupSchedulers {
     &miscCheck2(2);    # mandatory
     &shmFlush(1);      # mandatory
     &slashdotLoop(2);
+    &plugLoop(2);
     &freshmeatLoop(2);
     &kernelLoop(2);
     &wingateWriteFile(2);
@@ -922,6 +923,29 @@ sub slashdotLoop {
     } );
 }
 
+sub plugLoop {
+
+    if (@_) {
+       &ScheduleThis(60, "plugLoop");
+       return if ($_[0] eq "2");
+    }
+
+    my @chans = &ChanConfList("plugAnnounce");
+    return unless (scalar @chans);
+
+    &Forker("plug", sub {
+       my $line = &Plug::plugAnnounce();
+       return unless (defined $line);
+
+       foreach (@chans) {
+           next unless (&::validChan($_));
+
+           &::status("sending plug update to $_.");
+           &notice($_, "Plug: $line");
+       }
+    } );
+}
+
 sub freshmeatLoop {
     if (@_) {
        &ScheduleThis(60, "freshmeatLoop");
diff --git a/src/Modules/Plug.pl b/src/Modules/Plug.pl
new file mode 100644 (file)
index 0000000..3467a83
--- /dev/null
@@ -0,0 +1,105 @@
+#
+#     Plug.pl: hacked for http://Plug.org/ by Tim Riker <Tim@Rikers.org>
+# Slashdot.pl: Slashdot headline retrival
+#      Author: Chris Tessone <tessone@imsa.edu>
+#    Modified: dms
+#   Licensing: Artistic License (as perl itself)
+#     Version: v0.4 (19991125)
+#
+
+###
+# fixed up to use XML'd /. backdoor 7/31 by richardh@rahga.com
+# My only request if this gets included in infobot is that the
+# other header gets trimmed to 2 lines, dump the fluff ;) -rah
+#
+# added a status message so people know to install LWP - oznoid
+# also simplified the return code because it wasn't working.
+###
+
+
+package Plug;
+
+use strict;
+
+sub plugParse {
+    my @list;
+
+    foreach (@_) {
+       next unless (/<title>(.*?)<\/title>/);
+       my $title = $1;
+       $title =~ s/&amp\;/&/g;
+       push(@list, $title);
+    }
+
+    return @list;
+}
+
+sub Plug {
+    my @results = &::getURL("http://www.plug.org/plug.xml");
+    my $retval  = "i could not get the headlines.";
+
+    if (scalar @results) {
+       my $prefix      = "Plug Headlines ";
+       my @list        = &plugParse(@results);
+       $retval         = &::formListReply(0, $prefix, @list);
+    }
+
+    &::performStrictReply($retval);
+}
+
+sub plugAnnounce {
+    my $file = "$::param{tempDir}/plug.xml";
+
+    my @Cxml = &::getURL("http://www.plug.org/plug.xml");
+    if (!scalar @Cxml) {
+       &::DEBUG("sdA: failure (Cxml == NULL).");
+       return;
+    }
+
+    if (! -e $file) {          # first time run.
+       open(OUT, ">$file");
+       foreach (@Cxml) {
+           print OUT "$_\n";
+       }
+       close OUT;
+
+       return;
+    }
+
+    my @Oxml;
+    open(IN, $file);
+    while (<IN>) {
+       chop;
+       push(@Oxml,$_);
+    }
+    close IN;
+
+    my @Chl = &plugParse(@Cxml);
+    my @Ohl = &plugParse(@Oxml);
+
+    my @new;
+    foreach (@Chl) {
+       last if ($_ eq $Ohl[0]);
+       push(@new, $_);
+    }
+
+    if (scalar @new == 0) {
+       &::status("Plug: no new headlines.");
+       return;
+    }
+
+    if (scalar @new == scalar @Chl) {
+       &::DEBUG("sdA: scalar(new) == scalar(Chl). bad?");
+    }
+
+    open(OUT,">$file");
+    foreach (@Cxml) {
+       print OUT "$_\n";
+    }
+    close OUT;
+
+    return "Plug: ".
+                       join(" \002::\002 ", @new);
+}
+
+1;
index 0cae3423342c6aae1ecdb2783eba3613b944e314..9d54aa1204f1dfbcc171a50177b4ac10ea08a8f7 100644 (file)
@@ -31,9 +31,9 @@ if ($@) {
        "factoids"      => "Factoids.pl",
        "freshmeat"     => "Freshmeat.pl",
        "kernel"        => "Kernel.pl",
-       "ircdcc"        => "UserDCC.pl",
        "perlMath"      => "Math.pl",
        "news"          => "News.pl",
+       "plug"          => "Plug.pl",
        "quote"         => "Quote.pl",
        "rootwarn"      => "RootWarn.pl",
        "search"        => "Search.pl",
@@ -41,15 +41,16 @@ if ($@) {
        "topic"         => "Topic.pl",
        "units"         => "Units.pl",
        "uptime"        => "Uptime.pl",
+       "ircdcc"        => "UserDCC.pl",
        "userinfo"      => "UserInfo.pl",
        "wwwsearch"     => "W3Search.pl",
        "whatis"        => "WhatIs.pl",
        "wingate"       => "Wingate.pl",
-       "zfi"           => "zfi.pl",
-       "zsi"           => "zsi.pl",
+       "babelfish"     => "babel.pl",
        "insult"        => "insult.pl",
        "nickometer"    => "nickometer.pl",
-       "babelfish"     => "babel.pl",
+       "zfi"           => "zfi.pl",
+       "zsi"           => "zsi.pl",
 );
 ### THIS IS NOT LOADED ON RELOAD :(
 my @myModulesLoadNow;