X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=src%2FModules%2FNews.pl;h=c82b5772730d04daad16574ef74dd6338ac74849;hb=a41f790cd30339179f7ae655a3009f22d61fc9e3;hp=128bb2c821c85d9034bdd5b52582dbcc53cbd687;hpb=346e5bd13875b55c25c90c58cf186f747100689d;p=infobot.git diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 128bb2c..c82b577 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -15,10 +15,12 @@ # Text - Actual text. ### -use vars qw($who $chan); - package News; +use strict; + +use vars qw($who $chan); + sub Parse { my($what) = @_; $chan = undef; @@ -38,7 +40,7 @@ sub Parse { } if (defined $what and $what =~ s/^($::mask{chan})\s*//) { - # todo: check if the channel exists aswell. + # TODO: check if the channel exists aswell. $chan = lc $1; if (!&::IsNickInChan($who, $chan)) { @@ -116,7 +118,7 @@ sub Parse { } elsif ($what =~ /^(un)?notify$/i) { my $state = ($1) ? 0 : 1; - # todo: don't notify even if "news" is called. + # 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."); @@ -165,7 +167,7 @@ sub readNews { while () { chop; - # todo: allow commands. + # TODO: allow commands. if (/^[\s\t]+(\S+):[\s\t]+(.*)$/) { if (!defined $item) { @@ -216,7 +218,7 @@ sub writeNews { return; } - # todo: add commands to output file. + # TODO: add commands to output file. my $c = 0; my($cc,$ci,$cu) = (0,0,0); @@ -225,6 +227,7 @@ sub writeNews { $c = scalar keys %{ $::news{$chan} }; next unless ($c); $cc++; + my $item; foreach $item (sort keys %{ $::news{$chan} }) { $c = scalar keys %{ $::news{$chan}{$item} }; @@ -232,6 +235,7 @@ sub writeNews { $ci++; print NEWS "$chan $item\n"; + my $what; foreach $what (sort keys %{ $::news{$chan}{$item} }) { print NEWS " $what: $::news{$chan}{$item}{$what}\n"; } @@ -239,7 +243,7 @@ sub writeNews { } } - # todo: show how many users we wrote down. + # TODO: show how many users we wrote down. if (&::getChanConfList("newsKeepRead")) { # old users are removed in newsFlush(), perhaps it should be # done here. @@ -277,17 +281,17 @@ sub add { } $::news{$chan}{$str}{Time} = time(); - my $expire = &::getChanConfDefault("newsDefaultExpire",7); + my $expire = &::getChanConfDefault("newsDefaultExpire",7, $chan); $::news{$chan}{$str}{Expire} = time() + $expire*60*60*24; $::news{$chan}{$str}{Author} = $::who; # case! my $agestr = &::Time2String($::news{$chan}{$str}{Expire} - time() ); my $item = &newsS2N($str); - &::notice($who, "Added '\037$str\037' at [".localtime(time). + &::notice($who, "Added '\037$str\037' at [".gmtime(time). "] by \002$::who\002 for item #\002$item\002."); &::notice($who, "Now do 'news text $item '"); &::notice($who, "This item will expire at \002". - localtime($::news{$chan}{$str}{Expire})."\002 [$agestr from now] " + gmtime($::news{$chan}{$str}{Expire})."\002 [$agestr from now] " ); &writeNews(); @@ -349,7 +353,7 @@ sub del { $auth++ if (&::IsFlag("o")); if (!$auth) { - # todo: show when it'll expire. + # TODO: show when it'll expire. &::notice($who, "Sorry, you cannot remove items; just let them expire on their own."); return; } @@ -363,7 +367,7 @@ sub del { sub list { if (!scalar keys %{ $::news{$chan} }) { - &::notice($who, "No News for \002$chan\002."); + &::notice($who, "No news for \002$chan\002."); return; } @@ -393,7 +397,9 @@ sub list { $newest = $t if ($t > $newest); if ($e > 1 and $e < $expire) { $expire = $e; - $eno = &newsS2N($item); + &::DEBUG("before newsS2N($_)"); + $eno = &newsS2N($_); + &::DEBUG("after newsS2N($_) == $eno"); } } my $timestr = &::Time2String(time() - $newest); @@ -414,7 +420,7 @@ sub list { next; } - # todo: show request stats aswell. + # TODO: show request stats aswell. &::msg($who, sprintf("\002[\002%2d\002]\002%s %s", $i, $chr, $subtopic)); $i++; @@ -440,13 +446,13 @@ sub read { } if (!scalar keys %{ $::news{$chan} }) { - &::notice($who, "No News for \002$chan\002."); + &::notice($who, "No news for \002$chan\002."); return; } my $item = &getNewsItem($str); if (!defined $item or !scalar keys %{ $::news{$chan}{$item} }) { - # todo: numerical check. + # TODO: numerical check. if ($str =~ /^(\d+)[-, ](\d+)$/ or $str =~ /^-(\d+)$/ or $str =~ /^(\d+)-$/ or 0 @@ -464,7 +470,7 @@ sub read { return; } - my $t = localtime( $::news{$chan}{$item}{Time} ); + my $t = gmtime( $::news{$chan}{$item}{Time} ); my $a = $::news{$chan}{$item}{Author}; my $text = $::news{$chan}{$item}{Text}; my $num = &newsS2N($item); @@ -486,7 +492,7 @@ sub read { my $e; if ($_) { $e = sprintf("\037%s\037 [%s from now]", - scalar(localtime($_)), + scalar(gmtime($_)), &::Time2String($_ - time()) ); } @@ -530,13 +536,13 @@ sub mod { } ### TODO: use m### to make code safe! - # todo: make code safer. + # TODO: make code safer. my $done = 0; - # todo: use eval to deal with flags easily. + # TODO: use eval to deal with flags easily. if ($flags eq "") { $done++ if (!$done and $mod_news =~ s/\Q$op\E/$np/); $done++ if (!$done and $mod_nnews =~ s/\Q$op\E/$np/); - } elsif ($flags eq "g") { + } elsif ($flags eq "g") { $done++ if ($mod_news =~ s/\Q$op\E/$np/g); $done++ if ($mod_nnews =~ s/\Q$op\E/$np/g); } @@ -636,7 +642,7 @@ sub set { } if ($what eq "Expire") { - # todo: use do_set(). + # TODO: use do_set(). my $time = 0; my $plus = ($value =~ s/^\+//g); @@ -674,7 +680,7 @@ sub set { return; } else { &::notice($who, "Set expire for \002$item\002, to ". - localtime($time) ." [".&::Time2String($time - time())."]" ); + gmtime($time) ." [".&::Time2String($time - time())."]" ); if (time() > $time) { &::DEBUG("news: hrm... time() > $time, should expire."); @@ -700,12 +706,12 @@ sub set { } if (!$auth) { - # todo: show when it'll expire. + # TODO: show when it'll expire. &::notice($who, "Sorry, you cannot set items. (author $author owns it)"); return; } - # todo: clean this up. + # TODO: clean this up. my $old = $::news{$chan}{$news}{$what}; if (defined $old) { &::DEBUG("news: old => $old."); @@ -715,13 +721,13 @@ sub set { } sub latest { - my($tchan, $flag) = @_; + my ($tchan, $flag) = @_; - # hack hack hack. - $chan ||= $tchan; - $who = $::who; + # hack hack hack. fix later. + $chan = $tchan; + $who = $::who; - # todo: if chan = undefined, guess. + # TODO: if chan = undefined, guess. # if (!exists $::news{$chan}) { if (!exists $::channels{$chan}) { &::notice($who, "invalid chan $chan") if ($flag); @@ -746,14 +752,14 @@ sub latest { $::chan = $chan; my $x = &::IsChanConf("newsNotifyAll"); - if (&::IsChanConf("newsNotifyAll") and !defined $t) { - $t = 1; - } + return if (!$x); + + # I don't understand this code ;) + $t = 1 if (!defined $t); if (!defined $t) { # &::msg($who, "News is disabled for $chan"); - &::DEBUG("news: something went really wrong."); - &::DEBUG("news: chan => $chan."); + &::DEBUG("news: $chan: something went really wrong."); return; } @@ -786,10 +792,14 @@ sub latest { # scalar @new, !$flag my $unread = scalar @new; my $total = scalar keys %{ $::news{$chan} }; - if (!$flag || &::IsChanConf("newsTellUnread")) { + if (!$flag && !&::IsChanConf("newsTellUnread")) { + return; + } + + if (!$flag) { return unless ($unread); - # just a temporary measure not to flood ourself off the + # just a temporary measure not to flood ourself off the # network with news until we get global notice() and msg() # throttling. if (time() - ($::cache{newsTime} || 0) < 5) { @@ -821,20 +831,20 @@ sub latest { $i = &newsS2N($_); $sorted[$i] = $_; } - + for ($i=0; $i<=scalar(@sorted); $i++) { my $news = $sorted[$i]; next unless (defined $news); - my $age = time() - $::news{$chan}{$news}{Time}; +# my $age = time() - $::news{$chan}{$news}{Time}; + my $msg = sprintf("\002[\002%2d\002]\002 %s", $i, $news); +### $i, $_, &::Time2String($age) $::conn->schedule(int((2+$i)/2), sub { - &::notice($who, sprintf("\002[\002%2d\002]\002 %s", - $i, $news) ); -# $i, $_, &::Time2String($age) ) ); + &::notice($who, $msg); } ); } - # todo: implement throttling via schedule into ¬ice() / &msg(). + # TODO: implement throttling via schedule into ¬ice() / &msg(). $::conn->schedule(int((2+$i)/2), sub { &::notice($who, "|= to read, do \002news $chan read <#>\002 or \002news $chan read \002"); } ); @@ -979,7 +989,7 @@ sub do_set { return; } - &::DEBUG("news: do_set: TODO..."); + &::TODO("news: do_set:"); } sub stats {