]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/News.pl
- added weather from Nathan Moschkin <logeist@guinerd.myip.org>. Thanks!
[infobot.git] / src / Modules / News.pl
index 2942f851348b5e57a15e7b5d8127efcb1a3ee7d6..33d8933d86b923f3b833bd29b5cb98ab8abc91aa 100644 (file)
@@ -1,7 +1,7 @@
 #
 # News.pl: Advanced news management
 #   Author: dms
-#  Version: v0.3 (20014012)
+#  Version: v0.3 (20010412)
 #  Created: 20010326
 #    Notes: Testing done by greycat, kudos!
 #
@@ -15,7 +15,7 @@
 #      Text    - Actual text.
 ###
 
-use vars qw($who);
+use vars qw($who $chan);
 
 package News;
 
@@ -102,11 +102,12 @@ sub Parse {
     } elsif ($what =~ /^(expire|text|desc)(\s+(.*))?$/i) {
        # shortcut/link.
        # nice hack.
+       my $cmd = $1;
        my($arg1,$arg2) = split(/\s+/, $3, 2);
-       &set("$arg1 $1 $arg2");
+       &set("$arg1 $cmd $arg2");
 
     } elsif ($what =~ /^help(\s+(.*))?$/i) {
-       &::help("news$1");
+       &::help("news $2");
 
     } elsif ($what =~ /^newsflush$/i) {
        &::msg($who, "newsflush called... check out the logs!");
@@ -192,11 +193,13 @@ sub readNews {
     close NEWS;
 
     my $cn = scalar(keys %::news);
+    return unless ($ci or $cn or $cu);
+
     &::status("News: read ".
        $ci. &::fixPlural(" item", $ci). " for ".
        $cn. &::fixPlural(" chan", $cn). ", ".
        $cu. &::fixPlural(" user", $cu), " cache"
-    ) if ($ci or $cn or $cu);
+    );
 }
 
 sub writeNews {
@@ -205,10 +208,11 @@ sub writeNews {
        return;
     }
 
+    # should define this at the top of file.
     my $file = "$::bot_base_dir/blootbot-news.txt";
 
     if (fileno NEWS) {
-       &::ERROR("fileno NEWS exists, should never happen.");
+       &::ERROR("News: write: fileno NEWS exists, should never happen.");
        return;
     }
 
@@ -396,8 +400,8 @@ sub list {
     &::msg($who, "|= Last updated $timestr ago.");
     &::msg($who, " \037Num\037  \037Item ".(" "x40)." \037");
 
-    &DEBUG("list: expire = $expire");
-    &::DEBUG("list: eno    = $eno");
+#    &::DEBUG("news: list: expire = $expire");
+#    &::DEBUG("news: list: eno    = $eno");
 
     my $i = 1;
     foreach ( &getNewsAll() ) {
@@ -442,6 +446,15 @@ sub read {
 
     my $item   = &getNewsItem($str);
     if (!defined $item or !scalar keys %{ $::news{$chan}{$item} }) {
+       # todo: numerical check.
+       if ($str =~ /^(\d+)[-, ](\d+)$/ or
+           $str =~ /^-(\d+)$/ or
+           $str =~ /^(\d+)-$/ or 0
+       ) {
+           &::notice($who, "We don't support multiple requests of news items yet.  Sorry.");
+           return;
+       }
+
        &::notice($who, "No news item called '$str'");
        return;
     }
@@ -570,12 +583,15 @@ sub set {
     my($args) = @_;
     my($item, $what, $value);
 
+    if (!defined $args) {
+       &::DEBUG("news: set: args == NULL.");
+       return;
+    }
+
     $item = $1 if ($args =~ s/^(\S+)\s*//);
     $what = $1 if ($args =~ s/^(\S+)\s*//);
     $value = $args;
 
-    &::DEBUG("news: set called.");
-
     if ($item eq "") {
        &::help("news set");
        return;
@@ -672,7 +688,7 @@ sub set {
     }
 
     my $auth = 0;
-    &::DEBUG("news: who => '$who'");
+#    &::DEBUG("news: who => '$who'");
     my $author = $::news{$chan}{$news}{Author};
     $auth++ if ($::who eq $author);
     $auth++ if (&::IsFlag("o"));
@@ -702,8 +718,8 @@ sub latest {
     my($tchan, $flag) = @_;
 
     # hack hack hack.
-    $chan      ||= $tchan;
-    $who       = $::who;
+    $chan ||= $tchan;
+    $who    = $::who;
 
     # todo: if chan = undefined, guess.
 #    if (!exists $::news{$chan}) {
@@ -721,7 +737,7 @@ sub latest {
 
     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 \002/msg $::ident news $chan\002 or \002/msg $::ident news $chan notify\002");
        } else {
            &::DEBUG("news: not displaying any new news for $who");
            return;
@@ -806,7 +822,7 @@ sub latest {
 #              $i, $_, &::Time2String($age) ) );
        }
 
-       &::notice($who, "|= to read, do 'news read <#>' or 'news read <keyword>'");
+       &::notice($who, "|= to read, do \002news $chan read <#>\002 or \002news $chan read <keyword>\002");
 
        # lame hack to prevent dupes if we just ignore it.
        my $x = $::newsuser{$chan}{$who};
@@ -916,7 +932,7 @@ sub getNewsItem {
        }
 
        if (@items) {
-           &::DEBUG("news: gNI: part_string->full_string: $what->$items[0]");
+#          &::DEBUG("news: gNI: part_string->full_string: $what->$items[0]");
            return $items[0];
        } else {
            &::DEBUG("news: gNI: No match for '$what'");
@@ -924,7 +940,7 @@ sub getNewsItem {
        }
     }
 
-    &::ERROR("getNewsItem: Should not happen (what = $what)");
+    &::ERROR("news: gNI: should not happen (what = $what)");
     return;
 }