From 92c8d6b2215ca2448dbbd5f5370cbba88c32beec Mon Sep 17 00:00:00 2001 From: dms Date: Thu, 28 Nov 2002 12:28:19 +0000 Subject: [PATCH] - move unuseable files to old/ - Freshmeat is gone because fm ][ is lacking in info - Freshmeat I is kept for historical value. - dbm.pl is kept for historical value. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@716 c11ca15a-4712-0410-83d8-924469b57eb5 --- old/Freshmeat_I.pl | 270 +++++ .../Freshmeat.pl => old/Freshmeat_II.pl | 0 old/News.pl | 1031 +++++++++++++++++ old/dbm.pl | 449 +++++++ 4 files changed, 1750 insertions(+) create mode 100644 old/Freshmeat_I.pl rename src/Modules/Freshmeat.pl => old/Freshmeat_II.pl (100%) create mode 100644 old/News.pl create mode 100644 old/dbm.pl diff --git a/old/Freshmeat_I.pl b/old/Freshmeat_I.pl new file mode 100644 index 0000000..2936b9c --- /dev/null +++ b/old/Freshmeat_I.pl @@ -0,0 +1,270 @@ +# +# Freshmeat.pl: Frontend to www.freshmeat.net +# Author: dms +# Version: v0.7d (20000923) +# Created: 19990930 +# + +package Freshmeat; + +use strict; + +### download compressed version instead? + +my %urls = ( + 'public' => 'http://www.freshmeat.net/backend/appindex.txt', + 'private' => 'http://feed.freshmeat.net/appindex/appindex.txt', +); + +#### +# Usage: &Freshmeat($string); +sub Freshmeat { + my $sstr = lc($_[0]); + my $refresh = &::getChanConfDefault("freshmeatRefreshInterval", + "", 24) * 60 * 60; + + my $last_refresh = &::dbGet("freshmeat", "name","_","stable"); + my $renewtable = 0; + + if (defined $last_refresh) { + $renewtable++ if (time() - $last_refresh > $refresh); + } else { + $renewtable++; + } + $renewtable++ if (&::countKeys("freshmeat") < 10); + + if ($renewtable and $$ == $::bot_pid) { + &::Forker("freshmeat", sub { + &downloadIndex(); + &Freshmeat($sstr); + } ); + # both parent/fork runs here, in case the following looks weird. + return if ($$ == $::bot_pid); + } + + if (!&showPackage($sstr)) { # no exact match. + my $start_time = &::timeget(); + my %hash; + + # search by key/NAME first. + foreach (&::searchTable("freshmeat", "name","name",$sstr)) { + $hash{$_} = 1 unless exists $hash{$_}; + } + + # search by description line. + foreach (&::searchTable("freshmeat", "name","oneliner", $sstr)) { + $hash{$_} = 1 unless exists $hash{$_}; + last if (scalar keys %hash > 15); + } + + my @list = keys %hash; + # search by value, if we have enough room to do it. + if (scalar @list == 1) { + &::status("only one match found; showing full info."); + &showPackage($list[0]); + return; + } + + # show how long it took. + my $delta_time = &::timedelta($start_time); + &::status(sprintf("freshmeat: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0); + + for (@list) { + tr/A-Z/a-z/; + s/([\,\;]+)/\037$1\037/g; + } + + &::performStrictReply( &::formListReply(1, "Freshmeat ", @list) ); + } +} + +sub showPackage { + my ($pkg) = @_; + my @fm = &::dbGet("freshmeat", "name",$pkg,"*"); + + if (scalar @fm) { #1: perfect match of name. + my $retval; + $retval = "$fm[0] \002(\002$fm[11]\002)\002, "; + $retval .= "section $fm[3], "; + $retval .= "is $fm[4]. "; + $retval .= "Stable: \002$fm[1]\002, "; + $retval .= "Development: \002$fm[2]\002. "; + $retval .= $fm[5] || $fm[6]; # fallback to 'download'. + $retval .= " deb: ".$fm[8] if ($fm[8] ne ""); # 'deb'. + &::performStrictReply($retval); + return 1; + } else { + return 0; + } +} + +sub randPackage { + my @fm = &::randKey("freshmeat","*"); + + if (scalar @fm) { #1: perfect match of name. + my $retval; + $retval = "$fm[0] \002(\002$fm[11]\002)\002, "; + $retval .= "section $fm[3], "; + $retval .= "is $fm[4]. "; + $retval .= "Stable: \002$fm[1]\002, "; + $retval .= "Development: \002$fm[2]\002. "; + $retval .= $fm[5] || $fm[6]; # fallback to 'download'. + $retval .= " deb: ".$fm[8] if ($fm[8] ne ""); # 'deb'. + + return $retval; + } else { + return; + } +} + +sub downloadIndex { + my $start_time = &::timeget(); # set the start time. + my $idx = "$::param{tempDir}/fm_index.txt"; + + &::msg($::who, "Updating freshmeat index... please wait"); + + if (&::isStale($idx, 1)) { + &::status("Freshmeat: fetching data."); + foreach (keys %urls) { + my $retval = &::getURLAsFile($urls{$_}, $idx); + next if ($retval =~ /^(403|500)$/); + + &::DEBUG("FM: last! retval => '$retval'."); + last; + } + } else { + &::status("Freshmeat: local file hack."); + } + + if (! -e $idx) { + &::msg($::who, "the freshmeat butcher is closed."); + return; + } + + if ( -s $idx < 100000) { + &::DEBUG("FM: index too small?"); + unlink $idx; + &::msg($::who, "internal error?"); + return; + } + + if ($idx =~ /bz2$/) { + open(IN, "bzcat $idx |"); + } elsif ($idx =~ /gz$/) { + open(IN, "gzcat $idx |"); + } else { + open(IN, $idx); + } + + # delete the table before we redo it. + &::deleteTable("freshmeat"); + + ### lets get on with business. + # set the last refresh time. fixes multiple spawn bug. + &::dbSet("freshmeat", "name","_","stable",time()); + + my $i = 0; + while (my $line = ) { + chop $line; + $i++ if ($line eq "%%"); + last if ($i == 2); + } + + &::dbRaw("LOCK", "LOCK TABLES freshmeat WRITE"); + my @data; + my @done; + while (my $line = ) { + chop $line; + if ($line ne "%%") { + push(@data,$line); + next; + } + + if ($i % 200 == 0 and $i != 0) { + &::DEBUG("FM: unlocking and locking."); + &::dbRaw("UNLOCK", "UNLOCK TABLES"); + ### another lame hack to "prevent" errors. + select(undef, undef, undef, 0.2); + &::dbRaw("LOCK", "LOCK TABLES freshmeat WRITE"); + } + + if (grep /^\Q$data[0]\E$/, @done) { + &::DEBUG("dupe? $data[0]"); + @data = (); + next; + } + + $i++; + pop @data; + $data[1] ||= "none"; + $data[2] ||= "none"; + &::dbSetRow("freshmeat", @data); + push(@done,$data[0]); + @data = (); + } + close IN; + &::DEBUG("FM: data ".scalar(@data) ); + &::dbRaw("UNLOCK", "UNLOCK TABLES"); + + my $delta_time = &::timedelta($start_time); + &::status(sprintf("Freshmeat: %.02f sec to complete.", $delta_time)) if ($delta_time > 0); + + my $count = &::countKeys("freshmeat"); + &::status("Freshmeat: $count entries loaded."); +} + +sub freshmeatAnnounce { + my $file = "$::param{tempDir}/fm_recent.txt"; + my @old; + + ### if file exists, lets read it. + if ( -f $file) { + open(IN, $file); + while () { + chop; + push(@old,$_); + } + close IN; + } + + my @array = &::getURL("http://core.freshmeat.net/backend/recentnews.txt"); + my @now; + + while (@array) { + my($what,$date,$url) = splice(@array,0,3); + push(@now, $what); + } + + ### if file does not exist, write new. + if (! -f $file) { + open(OUT, ">$file"); + foreach (@now) { + print OUT "$_\n"; + } + close OUT; + + return; + } + + my @new; + for(my $i=0; $i$file"); + foreach (@now) { + print OUT "$_\n"; + } + close OUT; + + return "Freshmeat update: ".join(" \002::\002 ", @new); +} + +1; diff --git a/src/Modules/Freshmeat.pl b/old/Freshmeat_II.pl similarity index 100% rename from src/Modules/Freshmeat.pl rename to old/Freshmeat_II.pl diff --git a/old/News.pl b/old/News.pl new file mode 100644 index 0000000..1c1629d --- /dev/null +++ b/old/News.pl @@ -0,0 +1,1031 @@ +# +# News.pl: Advanced news management +# Author: dms +# Version: v0.3 (20010412) +# Created: 20010326 +# Notes: Testing done by greycat, kudos! +# +### structure: +# news{ channel }{ string } { item } +# newsuser{ channel }{ user } = time() +### where item is: +# Time - when it was added (used for sorting) +# Author - Who by. +# Expire - Time to expire. +# Text - Actual text. +### + +package News; + +use strict; + +use vars qw($who $chan); + +sub Parse { + my($what) = @_; + $chan = undef; + $who = lc $::who; + + if (!keys %::news) { + if (!exists $::cache{newsFirst}) { + &::DEBUG("news: looks like we enabled news option just then; loading up news file just in case."); + $::cache{newsFirst} = 1; + } + + &readNews(); + } + + if ($::msgType ne "private") { + $chan = $::chan; + } + + if (defined $what and $what =~ s/^($::mask{chan})\s*//) { + # todo: check if the channel exists aswell. + $chan = lc $1; + + if (!&::IsNickInChan($who, $chan)) { + &::notice($who, "sorry but you're not on $chan."); + return; + } + } + + if (!defined $chan) { + my @chans = &::getNickInChans($who); + + if (scalar @chans > 1) { + &::notice($who, "error: I dunno which channel you are referring to since you're on more than one. Try 'news #chan ...' instead"); + return; + } + + if (scalar @chans == 0) { + &::notice($who, "error: I couldn't find you on any chan. This must be a bug!"); + return; + } + + $chan = $chans[0]; + &::VERB("Guessed $who being on chan $chan",2); + $::chan = $chan; # hack for IsChanConf(). + } + + if (!defined $what or $what =~ /^\s*$/) { + &list(); + return; + } + + if ($what =~ /^add(\s+(.*))?$/i) { + &add($2); + + } elsif ($what =~ /^del(\s+(.*))?$/i) { + &del($2); + + } elsif ($what =~ /^mod(\s+(.*))?$/i) { + &mod($2); + + } elsif ($what =~ /^set(\s+(.*))?$/i) { + &set($2); + + } elsif ($what =~ /^(\d+)$/i) { + &::VERB("News: read shortcut called.",2); + &read($1); + + } elsif ($what =~ /^read(\s+(.*))?$/i) { + &read($2); + + } elsif ($what =~ /^(latest|new)(\s+(.*))?$/i) { + &latest($3 || $chan, 1); +# $::cmdstats{'News latest'}++; + + } elsif ($what =~ /^stats?$/i) { + &stats(); + + } elsif ($what =~ /^list$/i) { + &list(); + + } elsif ($what =~ /^(expire|text|desc)(\s+(.*))?$/i) { + # shortcut/link. + # nice hack. + my $cmd = $1; + my($arg1,$arg2) = split(/\s+/, $3, 2); + &set("$arg1 $cmd $arg2"); + + } elsif ($what =~ /^help(\s+(.*))?$/i) { + &::help("news $2"); + + } elsif ($what =~ /^newsflush$/i) { + &::msg($who, "newsflush called... check out the logs!"); + &::newsFlush(); + + } elsif ($what =~ /^(un)?notify$/i) { + my $state = ($1) ? 0 : 1; + + # todo: don't notify even if "news" is called. + if (!&::IsChanConf("newsNotifyAll")) { + &::DEBUG("news: chan => $chan, ::chan => $::chan."); + &::notice($who, "not available for this channel or disabled altogether."); + return; + } + + my $t = $::newsuser{$chan}{$who}; + if ($state) { # state = 1 + if (defined $t and ($t == 0 or $t == -1)) { + &::notice($who, "enabled notify."); + delete $::newsuser{$chan}{$who}; + return; + } + &::notice($who, "already enabled."); + + } else { # state = 0 + my $x = $::newsuser{$chan}{$who}; + if (defined $x and ($x == 0 or $x == -1)) { + &::notice($who, "notify already disabled"); + return; + } + $::newsuser{$chan}{$who} = -1; + &::notice($who, "notify is now disabled."); + } + + } else { + &::notice($who, "unknown command: $what"); + } +} + +sub readNews { + my $file = "$::bot_base_dir/blootbot-news.txt"; + if (! -f $file or -z $file) { + return; + } + + if (fileno NEWS) { + &::DEBUG("readNews: fileno exists, should never happen."); + return; + } + + my($item,$chan); + my($ci,$cu) = (0,0); + + open(NEWS, $file); + while () { + chop; + + # todo: allow commands. + + if (/^[\s\t]+(\S+):[\s\t]+(.*)$/) { + if (!defined $item) { + &::DEBUG("news: !defined item, never happen!"); + next; + } + + $::news{$chan}{$item}{$1} = $2; + next; + } + + # U