]> git.donarmstrong.com Git - infobot.git/commitdiff
A round of fixes:
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 11 Apr 2001 14:34:12 +0000 (14:34 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Wed, 11 Apr 2001 14:34:12 +0000 (14:34 +0000)
- added dbReplace but it's broken
- debian infopackages shows dist
- news user cache now works properly
- "+" now works for all commands, not only for factoids

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@436 c11ca15a-4712-0410-83d8-924469b57eb5

src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/Modules/Debian.pl
src/Modules/News.pl
src/Process.pl
src/UserExtra.pl
src/db_mysql.pl
src/modules.pl

index 006f106ad59d6d8af340c22e896fb171b23d4329..461d9de730b69a5ba45c33c878bc8d6fc60d4b4e 100644 (file)
@@ -482,32 +482,8 @@ sub on_join {
 
     ### NEWS:
     if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) {
-       my @new;
-       foreach (keys %{ $::news{$chan} }) {
-           my $t = $::newsuser{$chan}{$who};
-           next if (!defined $t);
-           next if ($t > $::news{$chan}{$_}{Time});
-
-           push(@new, $_);
-       }
-
-       if (scalar @new) {
-           &msg($who, "+==== New news for $chan (".scalar(@new)."):");
-           # todo: show how many sec/min/etc ago?
-           my $timestr = &Time2String( time() - $::newsuser{$chan}{$who} );
-           &msg($who, "|= Last time read $timestr ago");
-
-           foreach (@new) {
-               my $i   = &News::getNewsItem($_);
-               my $age = time() - $::news{$chan}{$_}{Time};
-               &msg($who, sprintf("\002[\002%2d\002]\002 %s (%s)",
-                       $i, $_, &Time2String($age) ) );
-           }
-           &msg($who, "to read, do 'news read <#>' or 'news read <keyword>'");
-
-           # lame hack to prevent dupes if we just ignore it.
-           $::newsuser{$chan}{$who} = time();
-       }
+       # todo: what if it hasn't been loaded?
+       &News::latest($chan);
     }
 
     ### chanlimit check.
@@ -589,7 +565,7 @@ sub on_msg {
 
     if ($nick eq $ident) { # hopefully ourselves.
        if ($msg eq "TEST") {
-           &status("Local: Yes, we're alive.");
+           &status("IRCTEST: Yes, we're alive.");
            delete $cache{connect};
            return;
        }
index 0f28ddc14cc7416b071de01ceefe7cf23c9adbd9..2df8512bfbecdd9a4c8b565c077b3d10adb54587 100644 (file)
@@ -120,7 +120,8 @@ sub randomFactoid {
     while (1) {
        ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
 ###    $val =~ tr/^[A-Z]/[a-z]/;       # blah is Good => blah is good.
-       last if ($val !~ /^</);
+       last if (defined $val and $val !~ /^</);
+
        $error++;
        if ($error == 5) {
            &ERROR("rF: tried 5 times but failed.");
@@ -299,6 +300,9 @@ sub newsFlush {
        foreach $item (keys %{ $::news{$chan} }) {
            my $t = $::news{$chan}{$item}{Expire};
 
+           my $tadd    = $::news{$chan}{$item}{Time};
+           $oldest     = $tadd if ($oldest > $tadd);
+
            next if ($t == 0 or $t == -1);
            if ($t < 1000) {
                &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
@@ -306,8 +310,6 @@ sub newsFlush {
                next;
            }
 
-           $oldest = $t if ($t < $oldest);
-
            next unless (time() > $t);
            # todo: show how old it was.
            delete $::news{$chan}{$item};
@@ -465,6 +467,22 @@ sub seenFlush {
 
     if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
        foreach $nick (keys %seencache) {
+           if (0) {
+           my $retval = &dbReplace("seen", $nick, (
+                       "nick" => $seencache{$nick}{'nick'},
+                       "time" => $seencache{$nick}{'time'},
+                       "host" => $seencache{$nick}{'host'},
+                       "channel" => $seencache{$nick}{'chan'},
+                       "message" => $seencache{$nick}{'msg'},
+           ) );
+           &DEBUG("retval => $retval.");
+           delete $seencache{$nick};
+           $flushed++;
+
+           next;
+           }
+           ### OLD CODE...
+
            my $exists = &dbGet("seen","nick", $nick, "nick");
 
            if (defined $exists and $exists) {
@@ -627,7 +645,8 @@ sub ircCheck {
            &ircloop();
            delete $cache{connect};
        } else {
-           &DEBUG("possible lost in space; checking.");
+           &status("IRCTEST: possible lost in space; checking. ".
+               scalar(localtime) );
            &msg($ident, "TEST");
            $cache{connect} = time();
        }
@@ -703,7 +722,7 @@ sub miscCheck {
            next if (time() - $time < 60*60);
 
        } else {
-           &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
+#          &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
 #          next;
        }
 
@@ -1073,7 +1092,7 @@ sub mkBackup {
 
     if ( -e "$file~" ) {
        $backup++ if ( -s $file > -s "$file~");
-       $backup++ if ( (stat $file)[9] - (stat "$file~")[9] > $time);
+       $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
     } else {
        $backup++;
     }
@@ -1082,6 +1101,7 @@ sub mkBackup {
     ### TODO: do internal copying.
     &status("Backup: $file to $file~");
     CORE::system("/bin/cp $file $file~");
+    CORE::system("/bin/touch $file~"); # needed!
 }
 
 1;
index e3709bf506914529437853f148debdc75b0aadaf..eea5d945cc545e3c96c0a494eb6477d72c72d04b 100644 (file)
@@ -697,7 +697,8 @@ sub infoPackages {
            $pkg{'info'}  = "\002(\002". $pkg{'desc'} ."\002)\002";
            $pkg{'info'} .= ", section ".$pkg{'section'};
            $pkg{'info'} .= ", is ".$pkg{'priority'};
-           $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
+#          $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
+           $pkg{'info'} .= ". Version: \002$pkg{'version'}\002 ($dist)";
            $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
            $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
 
index b2f8b119780c259430955192753454d0cbd7c98f..b9cd1beb9f947a9caf3f511637343549177d5c0d 100644 (file)
@@ -75,6 +75,9 @@ sub Parse {
        &read($1);
     } elsif ($what =~ /^read(\s+(.*))?$/i) {
        &read($2);
+    } elsif ($what =~ /^(latest|new)(\s+(.*))?$/i) {
+       &::DEBUG("latest called... hrm");
+       &latest($3 || $chan, 1);
     } elsif ($what =~ /^list$/i) {
        &::DEBUG("list longcut called.");
        &list();
@@ -218,16 +221,15 @@ sub add {
     $::news{$chan}{$str}{Author}       = $::who;
 
     my $agestr = &::Time2String($::news{$chan}{$str}{Expire} - time() );
-    my $item   = &getNewsItem($str);
-    if ($item eq $str) {
-       &::DEBUG("item eq str ($item): should never happen.");
-    }
+    my $item   = &newsS2N($str);
     &::msg($::who, "Added '\037$str\037' at [".localtime(time).
                "] by \002$::who\002 for item #\002$item\002.");
     &::msg($::who, "Now do 'news text $item <your_description>'");
     &::msg($::who, "This item will expire at \002".
        localtime($::news{$chan}{$str}{Expire})."\002 [$agestr from now] "
     );
+
+    &writeNews();
 }
 
 sub del {
@@ -251,9 +253,8 @@ sub del {
            return;
        }
 
-       $item = &getNewsItem($what);
-       &::DEBUG("del: num: item => $item ($what)");
-       $what   = $item;        # hack hack hack.
+       $item   = &getNewsItem($what);
+       $what   = $item;                # hack hack hack.
 
     } else {
        $_      = &getNewsItem($what);  # hack hack hack.
@@ -584,6 +585,54 @@ sub set {
     &::msg($::who, "Setting [$chan]/{$news}/<$what> to '$value'.");
 }
 
+sub latest {
+    my($tchan, $flag) = @_;
+
+    $chan ||= $tchan;  # hack hack hack.
+
+    # todo: if chan = undefined, guess.
+    if (!exists $::news{$chan}) {
+       &::msg($::who, "invalid chan $chan");
+       return;
+    }
+
+    my @new;
+    foreach (keys %{ $::news{$chan} }) {
+       my $t = $::newsuser{$chan}{$::who};
+       next if (!defined $t);
+       next if ($t > $::news{$chan}{$_}{Time});
+
+       push(@new, $_);
+    }
+
+    if (!scalar @new and $flag) {
+       &::msg($::who, "no new news for $chan.");
+       return;
+    }
+
+    if (scalar @new) {
+       &::msg($::who, "+==== New news for \002$chan\002 (".
+               scalar(@new)." new items):");
+
+       my $timestr = &::Time2String( time() - $::newsuser{$chan}{$::who} );
+       &::msg($::who, "|= Last time read $timestr ago");
+
+       foreach (@new) {
+           my $i   = &newsS2N($_);
+           &::DEBUG("i = $i, _ => $_");
+           my $age = time() - $::news{$chan}{$_}{Time};
+           &::msg($::who, sprintf("\002[\002%2d\002]\002 %s",
+               $i, $_) );
+#              $i, $_, &::Time2String($age) ) );
+       }
+
+       &::msg($::who, "|= to read, do 'news read <#>' or 'news read <keyword>'");
+
+       # lame hack to prevent dupes if we just ignore it.
+       $::newsuser{$chan}{$::who} = time();
+    }
+}
+
 ###
 ### helpers...
 ###
@@ -602,6 +651,32 @@ sub getNewsAll {
     return @items;
 }
 
+sub newsS2N {
+    my($what)  = @_;
+    my @items;
+    my $no;
+
+    my %time;
+    foreach (keys %{ $::news{$chan} }) {
+       my $t = $::news{$chan}{$_}{Time};
+
+       if (!defined $t or $t !~ /^\d+$/) {
+           &::DEBUG("warn: t is undefined for news{$chan}{$_}{Time}; removing item.");
+           delete $::news{$chan}{$_};
+           next;
+       }
+
+       $time{$t} = $_;
+    }
+
+    foreach (sort { $a <=> $b } keys %time) {
+       $item++;
+       return $item if ($time{$_} eq $what);
+    }
+
+    &::DEBUG("newsS2N($what): failed...");
+}
+
 sub getNewsItem {
     my($what)  = @_;
     my $item   = 0;
@@ -633,7 +708,12 @@ sub getNewsItem {
        my $no;
        foreach (sort { $a <=> $b } keys %time) {
            $item++;
-           $no = $item if ($time{$_} eq $what);
+#          $no = $item if ($time{$_} eq $what);
+           if ($time{$_} eq $what) {
+               $no = $item;
+               next;
+           }
+
            push(@items, $time{$_}) if ($time{$_} =~ /\Q$what\E/i);
        }
 
@@ -642,6 +722,7 @@ sub getNewsItem {
        # todo: split this command in the future into:
        #       full_string->number and number->string
        #       partial_string->full_string
+       &::DEBUG("no => $no, items => @items.");
        if (defined $no and !@items) {
            &::DEBUG("string->number resolution.");
            return $no;
@@ -653,6 +734,7 @@ sub getNewsItem {
            return;
        }
 
+       &::DEBUG("gNI: string->number(??): $what->$items[0]");
        if (@items) {
            &::DEBUG("gNI: Guessed '$items[0]'.");
            return $items[0];
index c24f51ca6fa3a51f2da590832968d0708a35f22f..55da57b038e49fa11aaf82d4a02bdfffb445e835 100644 (file)
@@ -186,6 +186,15 @@ sub process {
        }
     }
 
+    # override msgType.
+    if ($msgType =~ /public/ and $message =~ s/^\+//) {
+       &status("found '+' flag; setting msgType to public.");
+       $force_public_reply++;
+       $msgType = 'public';
+       $who     = $chan;       # major hack to fix &msg().
+       &DEBUG("addressed => $addressed.");
+    }
+
     # User Processing, for all users.
     if ($addressed) {
        my $retval;
@@ -262,13 +271,6 @@ sub process {
     ### bot commands...
     ###
 
-    # override msgType.
-    if ($msgType =~ /public/ and $message =~ s/^\+//) {
-       &status("found '+' flag; setting msgType to public.");
-       $force_public_reply++;
-       $msgType = 'public';
-    }
-
     if ($message =~ s/^literal\s+//i) {
        &status("literal ask of '$message'.");
        $literal = 1;
index 6e6b81e954ac4fa114e29bb7f78daaded6eb246d..be48b367b41568bc9382e934588710bf272569fb 100644 (file)
@@ -30,7 +30,8 @@ use vars qw(%channels %chanstats %cmdstats);
        Help => 'nslookup', Identifier => 'allowDNS',
        Forker => "NULL", ) );
 &addCmdHook("main", 'tell|explain', ('CODEREF' => 'tell', 
-       Help => 'tell', Identifier => 'allowTelling', ) );
+       Help => 'tell', Identifier => 'allowTelling',
+       Cmdstats => 'Tell') );
 &addCmdHook("main", 'news', ('CODEREF' => 'News::Parse', 
        Module => 'news', Identifier => 'news') );
 
index 4a9d2687dbda31fcbca4812e0acf4f8c0966edc0..a88051cf96223a8006f22ef4496c848c6950e72f 100644 (file)
@@ -185,6 +185,25 @@ sub dbInsert {
     return 1;
 }
 
+#####
+# Usage: &dbReplace($table, $primkey, %hash);
+sub dbReplace {
+    my ($table, $primkey, %hash) = @_;
+    my (@keys, @vals);
+
+    foreach (keys %hash) {
+       &DEBUG("hash{$_} => $hash{$_}");
+       push(@keys, $_);
+       push(@vals, &dbQuote($hash{$_}));
+    }
+
+    &dbRaw("Replace($table)", "REPLACE INTO $table (".join(',',@keys).
+               ") VALUES (".join(',',@vals).")"
+    );
+
+    return 1;
+}
+
 #####
 # Usage: &dbSetRow($table, @values);
 sub dbSetRow {
index 791bd9f5f946998f5ef35efebfeb330d76a64c6d..30c5a40c8d9d2d2113ab89e7d0f159ec9bf4e5c4 100644 (file)
@@ -239,25 +239,31 @@ sub reloadModule {
        return;
     }
 
-    my $age = (stat $file)[9];
-    return if ($age == $moduleAge{$file});
-
-    if ($age < $moduleAge{$file}) {
-       &WARN("rM: we're not gonna downgrade the file. use 'touch'.");
-       return;
-    }
-
     if (grep /$mod/, @myModulesReloadNot) {
        &DEBUG("rM: SHOULD NOT RELOAD $mod!!!");
        return;
     }
 
-    my $dc  = &Time2String($age   - $moduleAge{$file});
-    my $ago = &Time2String(time() - $moduleAge{$file});
+    my $age = (stat $file)[9];
+
+    if (!exists $moduleAge{$file}) {
+       &DEBUG("Looks like $file was not loaded; fixing.");
+    } else {
+       return if ($age == $moduleAge{$file});
+
+       if ($age < $moduleAge{$file}) {
+           &WARN("rM: we're not gonna downgrade the file. use 'touch'.");
+           return;
+       }
+
+       my $dc  = &Time2String($age   - $moduleAge{$file});
+       my $ago = &Time2String(time() - $moduleAge{$file});
+
+       &VERB("Module:  delta change: $dc",2);
+       &VERB("Module:           ago: $ago",2);
+    }
 
     &status("Module: Loading $mod...");
-    &VERB("Module:  delta change: $dc",2);
-    &VERB("Module:           ago: $ago",2);
 
     delete $INC{$file};
     eval "require \"$file\"";  # require or use?