]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/News.pl
- irctextcounters: add percentage to top3
[infobot.git] / src / Modules / News.pl
index 4696982a3eae772f9aa5e7bdabfb4e7fdcd4873f..8075a5143e2f22391830403b4dac7ea83d1cae7c 100644 (file)
@@ -192,7 +192,7 @@ sub readNews {
     close NEWS;
 
     my $cn = scalar(keys %::news);
-    &::status("News: Read ".
+    &::status("News: read ".
        $ci. &::fixPlural(" item", $ci). " for ".
        $cn. &::fixPlural(" chan", $cn). ", ".
        $cu. &::fixPlural(" user", $cu), " cache"
@@ -381,18 +381,29 @@ sub list {
     my $count = scalar keys %{ $::news{$chan} };
     &::msg($::who, "|==== News for \002$chan\002: ($count items)");
     my $newest = 0;
+    my $expire = 0;
+    my $eno    = 0;
     foreach (keys %{ $::news{$chan} }) {
        my $t   = $::news{$chan}{$_}{Time};
+       my $e   = $::news{$chan}{$_}{Expire};
        $newest = $t if ($t > $newest);
+       if ($e > 1 and $e < $expire) {
+           $expire     = $e;
+           $eno        = &newsS2N($item);
+       }
     }
     my $timestr = &::Time2String(time() - $newest);
     &::msg($::who, "|= Last updated $timestr ago.");
-    &::msg($::who, " \037Num\037 \037Item ".(" "x40)." \037");
+    &::msg($::who, " \037Num\037  \037Item ".(" "x40)." \037");
+
+    &DEBUG("list: expire = $expire");
+    &DEBUG("list: eno    = $eno");
 
     my $i = 1;
     foreach ( &getNewsAll() ) {
        my $subtopic    = $_;
        my $setby       = $::news{$chan}{$subtopic}{Author};
+       my $chr         = (exists $::News{$chan}{$subtopic}{Text}) ? "" : "*";
 
        if (!defined $subtopic) {
            &::DEBUG("news: warn: subtopic == undef.");
@@ -400,11 +411,18 @@ sub list {
        }
 
        # todo: show request stats aswell.
-       &::msg($::who, sprintf("\002[\002%2d\002]\002 %s",
-                               $i, $subtopic));
+       &::msg($::who, sprintf("\002[\002%2d\002]\002%s %s",
+                               $i, $chr, $subtopic));
        $i++;
     }
 
+    my $z = $::newsuser{$::who};
+    if (defined $z) {
+       &::DEBUG("cache $::who: $z");
+    } else {
+       &::DEBUG("cache: $::who doesn't have newscache set.");
+    }
+
     &::msg($::who, "|= End of News.");
     &::msg($::who, "use 'news read <#>' or 'news read <keyword>'");
 }
@@ -550,8 +568,11 @@ sub mod {
 
 sub set {
     my($args) = @_;
-    $args =~ /^(\S+)\s+(\S+)\s+(.*)$/;
-    my($item, $what, $value) = ($1,$2,$3);
+    my($item, $what, $value);
+
+    $item = $1 if ($args =~ s/^(\S+)\s*//);
+    $what = $1 if ($args =~ s/^(\S+)\s*//);
+    $value = $args;
 
     &::DEBUG("news: set called.");
 
@@ -560,7 +581,6 @@ sub set {
        return;
     }
 
-    &::DEBUG("news: set: item => '$item'.");
     my $news = &getNewsItem($item);
 
     if (!defined $news) {
@@ -569,8 +589,8 @@ sub set {
     }
 
     # list all values for chan.
-    if (!defined $what) {
-       &::DEBUG("news: set: 1");
+    if (!defined $what or $what =~ /^\s*$/) {
+       &::msg($::who, "set: you didn't fill me on the arguments! (what and values)");
        return;
     }
 
@@ -589,8 +609,8 @@ sub set {
     }
 
     # show (read) what.
-    if (!defined $value) {
-       &::DEBUG("news: set: 2");
+    if (!defined $value or $value =~ /^\s*$/) {
+       &::msg($::who, "set: you didn't fill me on the arguments! (value)");
        return;
     }
 
@@ -627,6 +647,7 @@ sub set {
 
        if (!$time or ($value and $value !~ /^never$/i)) {
            &::DEBUG("news: set: Expire... need to parse.");
+           &::msg($::who, "hrm... couldn't parse that.");
            return;
        }
 
@@ -682,21 +703,27 @@ sub latest {
 
     # hack hack hack.
     $chan      ||= $tchan;
-    $who       ||= $::who;
+    $who       = $::who;
 
     # todo: if chan = undefined, guess.
 #    if (!exists $::news{$chan}) {
     if (!exists $::channels{$chan}) {
-       &::notice($::who, "invalid chan $chan") if ($flag);
+       &::notice($who, "invalid chan $chan") if ($flag);
        return;
     }
 
     my $t = $::newsuser{$chan}{$who};
+    if (defined $t) {
+       &::DEBUG("newsuser: $chan/$who == $t");
+    } else {
+       &::DEBUG("newsuser: $chan/$who == undefined");
+    }
+
     if (defined $t and ($t == 0 or $t == -1)) {
        if ($flag) {
-           &::notice($::who, "if you want to read news, try /msg $::ident news or /msg $::ident news notify");
+           &::notice($who, "if you want to read news, try /msg $::ident news or /msg $::ident news notify");
        } else {
-           &::DEBUG("news: not displaying any new news for $::who");
+           &::DEBUG("news: not displaying any new news for $who");
            return;
        }
     }
@@ -710,7 +737,7 @@ sub latest {
     if (!defined $t) {
        &::DEBUG("news: something went really wrong.");
        &::DEBUG("news: chan => $chan, ::chan => $::chan");
-#      &::notice($::who, "something went really wrong.");
+#      &::notice($who, "something went really wrong.");
        return;
     }
 
@@ -734,7 +761,9 @@ sub latest {
 
     # !scalar @new, $flag
     if (!scalar @new and $flag) {
-       &::notice($::who, "no new news for $chan.");
+       &::notice($who, "no new news for $chan for $who.");
+       # valid to set this?
+       $::newsuser{$chan}{$who} = time();
        return;
     }
 
@@ -746,19 +775,19 @@ sub latest {
 
        my $reply = "There are unread news in $chan ($unread unread, $total total). /msg $::ident news $::chan latest";
        $reply   .= "  If you don't want further news notification, /msg $::ident news unnotify" if ($unread == $total);
-       &::notice($::who, $reply);
+       &::notice($who, $reply);
 
        return;
     }
 
     # scalar @new, $flag
     if (scalar @new) {
-       &::notice($::who, "+==== New news for \002$chan\002 ($unread new; $total total):");
+       &::notice($who, "+==== New news for \002$chan\002 ($unread new; $total total):");
 
        my $t = $::newsuser{$chan}{$who};
        if (defined $t and $t > 1) {
            my $timestr = &::Time2String( time() - $t );
-           &::notice($::who, "|= Last time read $timestr ago");
+           &::notice($who, "|= Last time read $timestr ago");
        }
 
        my @sorted;
@@ -772,17 +801,17 @@ sub latest {
            next unless (defined $news);
 
            my $age = time() - $::news{$chan}{$news}{Time};
-           &::notice($::who, sprintf("\002[\002%2d\002]\002 %s",
+           &::notice($who, sprintf("\002[\002%2d\002]\002 %s",
                $i, $news) );
 #              $i, $_, &::Time2String($age) ) );
        }
 
-       &::notice($::who, "|= to read, do 'news read <#>' or 'news read <keyword>'");
+       &::notice($who, "|= to read, do 'news read <#>' or 'news read <keyword>'");
 
        # lame hack to prevent dupes if we just ignore it.
        my $x = $::newsuser{$chan}{$who};
        if (defined $x and ($x == 0 or $x == -1)) {
-           &::DEBUG("news: not updating time for $::who. (2)");
+           &::DEBUG("news: not updating time for $who. (2)");
        } else {
            $::newsuser{$chan}{$who} = time();
        }
@@ -867,18 +896,18 @@ sub getNewsItem {
        foreach (sort { $a <=> $b } keys %time) {
            $item++;
 #          $no = $item if ($time{$_} eq $what);
-           if ($time{$_} eq $what) {
-               $no = $item;
-               next;
-           }
+##         if ($time{$_} eq $what) {
+##             $no = $item;
+##             next;
+##         }
 
            push(@items, $time{$_}) if ($time{$_} =~ /\Q$what\E/i);
        }
 
-       if (defined $no and !@items) {
-           &::DEBUG("news: string->number resolution: $what->$no.");
-           return $no;
-       }
+##     if (defined $no and !@items) {
+##         &::DEBUG("news: string->number resolution: $what->$no.");
+##         return $no;
+##     }
 
        if (scalar @items > 1) {
            &::DEBUG("news: Multiple matches, not guessing.");
@@ -945,7 +974,7 @@ sub stats {
     my $t = time();
     foreach $chan (keys %::newsuser) {
        $i += $t - $::newsuser{$chan}{$_};
-       &DEBUG(" i = $i");
+       &::DEBUG(" i = $i");
        $j++;
     }
     &::DEBUG("news: stats: average latest time read: total time: $i");