2 # News.pl: Advanced news management
4 # Version: v0.3 (20010412)
6 # Notes: Testing done by greycat, kudos!
9 # news{ channel }{ string } { item }
10 # newsuser{ channel }{ user } = time()
12 # Time - when it was added (used for sorting)
14 # Expire - Time to expire.
22 use vars qw($who $chan);
29 if ( !keys %::news ) {
30 if ( !exists $::cache{newsFirst} ) {
32 "news: looks like we enabled news option just then; loading up news file just in case."
34 $::cache{newsFirst} = 1;
40 if ( $::msgType ne 'private' ) {
44 if ( defined $what and $what =~ s/^($::mask{chan})\s*// ) {
46 # TODO: check if the channel exists aswell.
49 if ( !&::IsNickInChan( $who, $chan ) ) {
50 &::notice( $who, "sorry but you're not on $chan." );
55 if ( !defined $chan ) {
56 my @chans = &::getNickInChans($who);
58 if ( scalar @chans > 1 ) {
60 "error: I dunno which channel you are referring to since you're on more than one. Try 'news #chan ...' instead"
65 if ( scalar @chans == 0 ) {
67 "error: I couldn't find you on any chan. This must be a bug!" );
72 &::VERB( "Guessed $who being on chan $chan", 2 );
73 $::chan = $chan; # hack for IsChanConf().
76 if ( !defined $what or $what =~ /^\s*$/ ) {
81 if ( $what =~ /^add(\s+(.*))?$/i ) {
85 elsif ( $what =~ /^del(\s+(.*))?$/i ) {
89 elsif ( $what =~ /^mod(\s+(.*))?$/i ) {
93 elsif ( $what =~ /^set(\s+(.*))?$/i ) {
97 elsif ( $what =~ /^(\d+)$/i ) {
98 &::VERB( "News: read shortcut called.", 2 );
102 elsif ( $what =~ /^read(\s+(.*))?$/i ) {
106 elsif ( $what =~ /^(latest|new)(\s+(.*))?$/i ) {
107 &latest( $3 || $chan, 1 );
109 # $::cmdstats{'News latest'}++;
112 elsif ( $what =~ /^stats?$/i ) {
116 elsif ( $what =~ /^list$/i ) {
120 elsif ( $what =~ /^(expire|text|desc)(\s+(.*))?$/i ) {
125 my ( $arg1, $arg2 ) = split( /\s+/, $3, 2 );
126 &set("$arg1 $cmd $arg2");
129 elsif ( $what =~ /^help(\s+(.*))?$/i ) {
133 elsif ( $what =~ /^newsflush$/i ) {
134 &::msg( $who, "newsflush called... check out the logs!" );
138 elsif ( $what =~ /^(un)?notify$/i ) {
139 my $state = ($1) ? 0 : 1;
141 # TODO: don't notify even if 'News' is called.
142 if ( &::IsChanConf('newsNotifyAll') <= 0 ) {
143 &::DEBUG("news: chan => $chan, ::chan => $::chan.");
145 "not available for this channel or disabled altogether." );
149 my $t = $::newsuser{$chan}{$who};
150 if ($state) { # state = 1
151 if ( defined $t and ( $t == 0 or $t == -1 ) ) {
152 &::notice( $who, "enabled notify." );
153 delete $::newsuser{$chan}{$who};
156 &::notice( $who, "already enabled." );
160 my $x = $::newsuser{$chan}{$who};
161 if ( defined $x and ( $x == 0 or $x == -1 ) ) {
162 &::notice( $who, 'notify already disabled' );
165 $::newsuser{$chan}{$who} = -1;
166 &::notice( $who, "notify is now disabled." );
171 &::notice( $who, "unknown command: $what" );
176 my $file = "$::bot_base_dir/infobot-news.txt";
177 if ( !-f $file or -z $file ) {
182 &::DEBUG("readNews: fileno exists, should never happen.");
187 my ( $ci, $cu ) = ( 0, 0 );
193 # TODO: allow commands.
195 if (/^[\s\t]+(\S+):[\s\t]+(.*)$/) {
196 if ( !defined $item ) {
197 &::DEBUG("news: !defined item, never happen!");
201 $::news{$chan}{$item}{$1} = $2;
205 # U <chan> <nick> <time>
206 if (/^U\s+(\S+)\s+(\S+)\s+(\d+)$/) {
207 $::newsuser{$1}{$2} = $3;
212 if (/^(\S+)[\s\t]+(.*)$/) {
220 my $cn = scalar( keys %::news );
221 return unless ( $ci or $cn or $cu );
225 . &::fixPlural( ' item', $ci ) . ' for '
227 . &::fixPlural( ' chan', $cn ) . ', '
229 . &::fixPlural( ' user', $cu ),
235 if ( !scalar keys %::news and !scalar keys %::newsuser ) {
236 &::VERB( "wN: nothing to write.", 2 );
240 # should define this at the top of file.
241 my $file = "$::bot_base_dir/infobot-news.txt";
244 &::ERROR("News: write: fileno NEWS exists, should never happen.");
248 # TODO: add commands to output file.
250 my ( $cc, $ci, $cu ) = ( 0, 0, 0 );
252 open( NEWS, ">$file" );
253 foreach $chan ( sort keys %::news ) {
254 $c = scalar keys %{ $::news{$chan} };
259 foreach $item ( sort keys %{ $::news{$chan} } ) {
260 $c = scalar keys %{ $::news{$chan}{$item} };
264 print NEWS "$chan $item\n";
266 foreach $what ( sort keys %{ $::news{$chan}{$item} } ) {
267 print NEWS " $what: $::news{$chan}{$item}{$what}\n";
273 # TODO: show how many users we wrote down.
274 if ( &::getChanConfList('newsKeepRead') ) {
276 # old users are removed in newsFlush(), perhaps it should be
279 foreach $chan ( sort keys %::newsuser ) {
281 foreach ( sort keys %{ $::newsuser{$chan} } ) {
282 print NEWS "U $chan $_ $::newsuser{$chan}{$_}\n";
290 &::status("News: Wrote $ci items for $cc chans, $cu user cache.");
296 if ( !defined $chan or !defined $str or $str =~ /^\s*$/ ) {
301 if ( length $str > 64 ) {
302 &::notice( $who, "That's not really an item (>64chars)" );
306 if ( exists $::news{$chan}{$str}{Time} ) {
307 &::notice( $who, "'$str' for $chan already exists!" );
311 $::news{$chan}{$str}{Time} = time();
312 my $expire = &::getChanConfDefault( 'newsDefaultExpire', 7, $chan );
313 $::news{$chan}{$str}{Expire} = time() + $expire * 60 * 60 * 24;
314 $::news{$chan}{$str}{Author} = $::who; # case!
316 my $agestr = &::Time2String( $::news{$chan}{$str}{Expire} - time() );
317 my $item = &newsS2N($str);
319 "Added '\037$str\037' at ["
321 . "] by \002$::who\002 for item #\002$item\002." );
322 &::notice( $who, "Now do 'news text $item <your_description>'" );
324 "This item will expire at \002"
325 . gmtime( $::news{$chan}{$str}{Expire} )
326 . "\002 [$agestr from now] " );
335 if ( !defined $what ) {
340 if ( $what =~ /^\d+$/ ) {
341 my $count = scalar keys %{ $::news{$chan} };
343 &::notice( $who, "No news for $chan." );
347 if ( $what > $count or $what < 0 ) {
348 &::notice( $who, "$what is out of range (max $count)" );
352 $item = &getNewsItem($what);
353 $what = $item; # hack hack hack.
357 $_ = &getNewsItem($what); # hack hack hack.
358 $what = $_ if ( defined $_ );
360 if ( !exists $::news{$chan}{$what} ) {
362 foreach ( keys %{ $::news{$chan} } ) {
363 next unless (/\Q$what\E/);
367 if ( !scalar @found ) {
368 &::notice( $who, "could not find $what." );
372 if ( scalar @found > 1 ) {
373 &::notice( $who, "too many matches for $what." );
378 &::DEBUG("news: del: str: guessed what => $what");
382 if ( exists $::news{$chan}{$what} ) {
384 $auth++ if ( $::who eq $::news{$chan}{$what}{Author} );
385 $auth++ if ( &::IsFlag('o') );
389 # TODO: show when it'll expire.
391 "Sorry, you cannot remove items; just let them expire on their own."
396 &::notice( $who, "ok, deleted '$what' from \002$chan\002..." );
397 delete $::news{$chan}{$what};
400 &::notice( $who, "error: not found $what in news for $chan." );
405 if ( !scalar keys %{ $::news{$chan} } ) {
406 &::notice( $who, "No news for \002$chan\002." );
410 if ( &::IsChanConf('newsKeepRead') > 0 ) {
411 my $x = $::newsuser{$chan}{$who};
413 if ( defined $x and ( $x == 0 or $x == -1 ) ) {
414 &::DEBUG("news: not updating time for $who.");
417 if ( !scalar keys %{ $::news{$chan} } ) {
418 &::DEBUG("news: should not add $chan/$who to cache!");
421 $::newsuser{$chan}{$who} = time();
425 # ¬ice() breaks OPN :( - using msg() instead!
426 my $count = scalar keys %{ $::news{$chan} };
427 &::msg( $who, "|==== News for \002$chan\002: ($count items)" );
431 foreach ( keys %{ $::news{$chan} } ) {
432 my $t = $::news{$chan}{$_}{Time};
433 my $e = $::news{$chan}{$_}{Expire};
434 $newest = $t if ( $t > $newest );
435 if ( $e > 1 and $e < $expire ) {
437 &::DEBUG("before newsS2N($_)");
439 &::DEBUG("after newsS2N($_) == $eno");
442 my $timestr = &::Time2String( time() - $newest );
443 &::msg( $who, "|= Last updated $timestr ago." );
444 &::msg( $who, " \037Num\037 \037Item " . ( ' ' x 40 ) . " \037" );
446 # &::DEBUG("news: list: expire = $expire");
447 # &::DEBUG("news: list: eno = $eno");
450 foreach ( &getNewsAll() ) {
452 my $setby = $::news{$chan}{$subtopic}{Author};
453 my $chr = ( exists $::News{$chan}{$subtopic}{Text} ) ? '' : '*';
455 if ( !defined $subtopic ) {
456 &::DEBUG("news: warn: subtopic == undef.");
460 # TODO: show request stats aswell.
462 sprintf( "\002[\002%2d\002]\002%s %s", $i, $chr, $subtopic ) );
466 my $z = $::newsuser{$who};
468 &::DEBUG("cache $who: $z");
471 &::DEBUG("cache: $who doesn't have newscache set.");
474 &::msg( $who, "|= End of News." );
475 &::msg( $who, "use 'news read <#>' or 'news read <keyword>'" );
481 if ( !defined $chan or !defined $str or $str =~ /^\s*$/ ) {
482 &::help('news read');
486 if ( !scalar keys %{ $::news{$chan} } ) {
487 &::notice( $who, "No news for \002$chan\002." );
491 my $item = &getNewsItem($str);
492 if ( !defined $item or !scalar keys %{ $::news{$chan}{$item} } ) {
494 # TODO: numerical check.
495 if ( $str =~ /^(\d+)[-, ](\d+)$/
496 or $str =~ /^-(\d+)$/
497 or $str =~ /^(\d+)-$/
501 "We don't support multiple requests of news items yet. Sorry."
506 &::notice( $who, "No news item called '$str'" );
510 if ( !exists $::news{$chan}{$item}{Text} ) {
511 &::notice( $who, 'Someone forgot to add info to this news item' );
515 my $t = gmtime( $::news{$chan}{$item}{Time} );
516 my $a = $::news{$chan}{$item}{Author};
517 my $text = $::news{$chan}{$item}{Text};
518 my $num = &newsS2N($item);
519 my $rwho = $::news{$chan}{$item}{Request_By} || $::who;
520 my $rcount = $::news{$chan}{$item}{Request_Count} || 0;
522 if ( length $text < $::param{maxKeySize} ) {
523 &::VERB( "NEWS: Possible news->factoid redirection.", 2 );
524 my $f = &::getFactoid($text);
527 &::VERB( "NEWS: ok, $text is factoid redirection.", 2 );
528 $f =~ s/^<REPLY>\s*//i; # anything else?
533 $_ = $::news{$chan}{$item}{'Expire'};
537 "\037%s\037 [%s from now]",
538 scalar( gmtime($_) ),
539 &::Time2String( $_ - time() )
543 &::notice( $who, "+- News \002$chan\002 #$num: $item" );
544 &::notice( $who, "| Added by $a at \037$t\037" );
545 &::notice( $who, "| Expire: $e" ) if ( defined $e );
546 &::notice( $who, $text );
548 "| Requested \002$rcount\002 times, last by \002$rwho\002" )
549 if ( $rcount and $rwho );
551 $::news{$chan}{$item}{'Request_By'} = $::who;
552 $::news{$chan}{$item}{'Request_Time'} = time();
553 $::news{$chan}{$item}{'Request_Count'}++;
557 my ( $item, $str ) = split /\s+/, $_[0], 2;
559 if ( !defined $item or $item eq '' or $str =~ /^\s*$/ ) {
564 my $news = &getNewsItem($item);
566 if ( !defined $news ) {
567 &::DEBUG("news: error: mod: news == undefined.");
570 my $nnews = $::news{$chan}{$news}{Text};
571 my $mod_news = $news;
572 my $mod_nnews = $nnews;
575 if ( $str =~ m|^\s*s([/,#\|])(.+?)\1(.*?)\1([a-z]*);?\s*$| ) {
576 my ( $delim, $op, $np, $flags ) = ( $1, $2, $3, $4 );
578 if ( $flags !~ /^(g)?$/ ) {
579 &::notice( $who, "error: Invalid flags to regex." );
583 ### TODO: use m### to make code safe!
584 # TODO: make code safer.
587 # TODO: use eval to deal with flags easily.
588 if ( $flags eq '' ) {
589 $done++ if ( !$done and $mod_news =~ s/\Q$op\E/$np/ );
590 $done++ if ( !$done and $mod_nnews =~ s/\Q$op\E/$np/ );
592 elsif ( $flags eq 'g' ) {
593 $done++ if ( $mod_news =~ s/\Q$op\E/$np/g );
594 $done++ if ( $mod_nnews =~ s/\Q$op\E/$np/g );
598 &::notice( $who, "warning: regex not found in news." );
602 if ( $mod_news ne $news ) { # news item.
603 if ( exists $::news{$chan}{$mod_news} ) {
604 &::notice( $who, "item '$mod_news' already exists." );
609 "Moving item '$news' to '$mod_news' with SAR s/$op/$np/." );
610 foreach ( keys %{ $::news{$chan}{$news} } ) {
611 $::news{$chan}{$mod_news}{$_} = $::news{$chan}{$news}{$_};
612 delete $::news{$chan}{$news}{$_};
616 delete $::news{$chan}{$news};
619 if ( $mod_nnews ne $nnews ) { # news Text/Description.
620 &::notice( $who, "Changing text for '$news' SAR s/$op/$np/." );
621 if ( $mod_news ne $news ) {
622 $::news{$chan}{$mod_news}{Text} = $mod_nnews;
625 $::news{$chan}{$news}{Text} = $mod_nnews;
632 &::notice( $who, "error: that regex failed ;(" );
636 &::notice( $who, "error: Invalid regex. Try s/1/2/, s#3#4#..." );
641 my ( $item, $what, $value );
643 if ( !defined $args ) {
644 &::DEBUG("news: set: args == NULL.");
648 $item = $1 if ( $args =~ s/^(\S+)\s*// );
649 $what = $1 if ( $args =~ s/^(\S+)\s*// );
657 my $news = &getNewsItem($item);
659 if ( !defined $news ) {
661 "Could not find item '$item' substring or # in news list." );
665 # list all values for chan.
666 if ( !defined $what or $what =~ /^\s*$/ ) {
668 "set: you didn't fill me on the arguments! (what and values)" );
673 my @elements = ( 'Expire', 'Text' );
674 foreach (@elements) {
675 next unless ( $what =~ /^$_$/i );
682 &::notice( $who, "Invalid set. Try: @elements" );
687 if ( !defined $value or $value =~ /^\s*$/ ) {
688 &::msg( $who, "set: you didn't fill me on the arguments! (value)" );
692 if ( !exists $::news{$chan}{$news} ) {
693 &::notice( $who, "news '$news' does not exist" );
697 if ( $what eq 'Expire' ) {
699 # TODO: use do_set().
702 my $plus = ( $value =~ s/^\+//g );
703 while ( $value =~ s/^(\d+)(\S*)\s*// ) {
704 my ( $int, $unit ) = ( $1, $2 );
705 $time += $int if ( $unit =~ /^s(ecs?)?$/i );
706 $time += $int * 60 if ( $unit =~ /^m(in(utes?)?)?$/i );
707 $time += $int * 60 * 60 if ( $unit =~ /^h(ours?)?$/i );
708 $time += $int * 60 * 60 * 24
709 if ( !$unit or $unit =~ /^d(ays?)?$/i );
710 $time += $int * 60 * 60 * 24 * 7 if ( $unit =~ /^w(eeks?)?$/i );
711 $time += $int * 60 * 60 * 24 * 30 if ( $unit =~ /^mon(th)?$/i );
714 if ( $value =~ s/^never$//i ) {
726 # from creation of item.
727 $time += $::news{$chan}{$news}{Time};
730 if ( !$time or ( $value and $value !~ /^never$/i ) ) {
731 &::DEBUG("news: set: Expire... need to parse.");
732 &::msg( $who, "hrm... couldn't parse that." );
737 &::notice( $who, "Set never expire for \002$item\002." );
739 elsif ( $time < -1 ) {
740 &::DEBUG("news: time should never be negative ($time).");
745 "Set expire for \002$item\002, to "
746 . gmtime($time) . " ["
747 . &::Time2String( $time - time() )
750 if ( time() > $time ) {
751 &::DEBUG("news: hrm... time() > $time, should expire.");
755 $::news{$chan}{$news}{Expire} = $time;
762 # &::DEBUG("news: who => '$who'");
763 my $author = $::news{$chan}{$news}{Author};
764 $auth++ if ( $::who eq $author );
765 $auth++ if ( &::IsFlag('o') );
766 if ( !defined $author ) {
768 "news: news{$chan}{$news}{Author} is not defined! auth'd anyway");
769 $::news{$chan}{$news}{Author} = $::who;
776 # TODO: show when it'll expire.
778 "Sorry, you cannot set items. (author $author owns it)" );
782 # TODO: clean this up.
783 my $old = $::news{$chan}{$news}{$what};
784 if ( defined $old ) {
785 &::DEBUG("news: old => $old.");
787 $::news{$chan}{$news}{$what} = $value;
788 &::notice( $who, "Setting [$chan]/{$news}/<$what> to '$value'." );
792 my ( $tchan, $flag ) = @_;
794 # hack hack hack. fix later.
798 # TODO: if chan = undefined, guess.
799 # if (!exists $::news{$chan}) {
800 if ( !exists $::channels{$chan} ) {
801 &::notice( $who, "invalid chan $chan" ) if ($flag);
805 my $t = $::newsuser{$chan}{$who};
808 # &::DEBUG("newsuser: $chan/$who == $t");
810 # &::DEBUG("newsuser: $chan/$who == undefined");
813 if ( defined $t and ( $t == 0 or $t == -1 ) ) {
816 "if you want to read news, try \002/msg $::ident news $chan\002 or \002/msg $::ident news $chan notify\002"
820 &::DEBUG("news: not displaying any new news for $who");
826 return if ( &::IsChanConf('newsNotifyAll') <= 0 );
828 # I don't understand this code ;)
829 $t = 1 if ( !defined $t );
833 # &::msg($who, "News is disabled for $chan");
834 &::DEBUG("news: $chan: something went really wrong.");
839 foreach ( keys %{ $::news{$chan} } ) {
840 next if ( !defined $t );
841 next if ( $t > $::news{$chan}{$_}{Time} );
843 # don't list new items if they don't have Text.
844 if ( !exists $::news{$chan}{$_}{Text} ) {
845 if ( time() - $::news{$chan}{$_}{Time} > 60 * 60 * 24 * 3 ) {
847 "deleting news{$chan}{$_} because it was too old and had no text info."
849 delete $::news{$chan}{$_};
858 # !scalar @new, $flag
859 if ( !scalar @new and $flag ) {
860 &::notice( $who, "no new news for $chan for $who." );
863 $::newsuser{$chan}{$who} = time();
867 # scalar @new, !$flag
868 my $unread = scalar @new;
869 my $total = scalar keys %{ $::news{$chan} };
870 if ( !$flag && &::IsChanConf('newsTellUnread') <= 0 ) {
875 return unless ($unread);
877 # just a temporary measure not to flood ourself off the
878 # network with news until we get global notice() and msg()
880 if ( time() - ( $::cache{newsTime} || 0 ) < 5 ) {
881 &::status("news: not displaying latest notice to $who/$chan.");
885 $::cache{newsTime} = time();
887 "There are unread news in $chan ($unread unread, $total total). /msg $::ident news $::chan latest";
889 " If you don't want further news notification, /msg $::ident news unnotify"
890 if ( $unread == $total );
891 &::notice( $who, $reply );
899 "+==== New news for \002$chan\002 ($unread new; $total total):" );
901 my $t = $::newsuser{$chan}{$who};
902 if ( defined $t and $t > 1 ) {
903 my $timestr = &::Time2String( time() - $t );
904 &::notice( $who, "|= Last time read $timestr ago" );
914 for ( $i = 0 ; $i <= scalar(@sorted) ; $i++ ) {
915 my $news = $sorted[$i];
916 next unless ( defined $news );
918 # my $age = time() - $::news{$chan}{$news}{Time};
919 my $msg = sprintf( "\002[\002%2d\002]\002 %s", $i, $news );
920 ### $i, $_, &::Time2String($age)
922 int( ( 2 + $i ) / 2 ),
924 &::notice( $who, $msg );
929 # TODO: implement throttling via schedule into ¬ice() / &msg().
931 int( ( 2 + $i ) / 2 ),
934 "|= to read, do \002news $chan read <#>\002 or \002news $chan read <keyword>\002"
939 # lame hack to prevent dupes if we just ignore it.
940 my $x = $::newsuser{$chan}{$who};
941 if ( defined $x and ( $x == 0 or $x == -1 ) ) {
942 &::DEBUG("news: not updating time for $who. (2)");
945 $::newsuser{$chan}{$who} = time();
956 foreach ( keys %{ $::news{$chan} } ) {
957 $time{ $::news{$chan}{$_}{Time} } = $_;
961 foreach ( sort { $a <=> $b } keys %time ) {
962 push( @items, $time{$_} );
975 foreach ( keys %{ $::news{$chan} } ) {
976 my $t = $::news{$chan}{$_}{Time};
978 if ( !defined $t or $t !~ /^\d+$/ ) {
980 "news: warn: t is undefined for news{$chan}{$_}{Time}; removing item."
982 delete $::news{$chan}{$_};
989 foreach ( sort { $a <=> $b } keys %time ) {
991 return $item if ( $time{$_} eq $what );
994 &::DEBUG("newsS2N($what): failed...");
1001 $what =~ s/^\#//; # '#1' for example.
1004 foreach ( keys %{ $::news{$chan} } ) {
1005 my $t = $::news{$chan}{$_}{Time};
1007 if ( !defined $t or $t !~ /^\d+$/ ) {
1009 "news: warn: t is undefined for news{$chan}{$_}{Time}; removing item."
1011 delete $::news{$chan}{$_};
1018 # number to string resolution.
1019 if ( $what =~ /^\d+$/ ) {
1020 foreach ( sort { $a <=> $b } keys %time ) {
1022 return $time{$_} if ( $item == $what );
1028 # partial string to full string resolution
1029 # in some cases, string->number resolution.
1033 foreach ( sort { $a <=> $b } keys %time ) {
1036 # $no = $item if ($time{$_} eq $what);
1037 ## if ($time{$_} eq $what) {
1042 push( @items, $time{$_} ) if ( $time{$_} =~ /\Q$what\E/i );
1045 ## if (defined $no and !@items) {
1046 ## &::DEBUG("news: string->number resolution: $what->$no.");
1050 if ( scalar @items > 1 ) {
1051 &::DEBUG("news: Multiple matches, not guessing.");
1052 &::notice( $who, "Multiple matches, not guessing." );
1058 # &::DEBUG("news: gNI: part_string->full_string: $what->$items[0]");
1062 &::DEBUG("news: gNI: No match for '$what'");
1067 &::ERROR("news: gNI: should not happen (what = $what)");
1072 my ( $what, $value ) = @_;
1074 if ( !defined $chan ) {
1075 &::DEBUG("news: do_set: chan not defined.");
1079 if ( !defined $what or $what =~ /^\s*$/ ) {
1080 &::DEBUG("news: what $what is not defined.");
1084 if ( !defined $value or $value =~ /^\s*$/ ) {
1085 &::DEBUG("news: value $value is not defined.");
1089 &::TODO("news: do_set:");
1093 &::DEBUG("News: stats called.");
1094 &::msg( $who, "check my logs/console." );
1095 my ( $i, $j ) = ( 0, 0 );
1097 # total request count.
1098 foreach $chan ( keys %::news ) {
1099 foreach ( keys %{ $::news{$chan} } ) {
1100 $i += $::news{$chan}{$_}{Request_Count};
1103 &::DEBUG("news: stats: total request count => $i");
1106 # total user cached.
1107 foreach $chan ( keys %::newsuser ) {
1108 $i += $::newsuser{$chan}{$_};
1110 &::DEBUG("news: stats: total user cache => $i");
1113 # average latest time read.
1115 foreach $chan ( keys %::newsuser ) {
1116 $i += $t - $::newsuser{$chan}{$_};
1117 &::DEBUG(" i = $i");
1120 &::DEBUG("news: stats: average latest time read: total time: $i");
1121 &::DEBUG("news: ... count: $j");
1122 &::DEBUG( "news: average: "
1123 . sprintf( "%.02f", $i / ( $j || 1 ) )
1128 sub AUTOLOAD { &::AUTOLOAD(@_); }
1132 # vim:ts=4:sw=4:expandtab:tw=80