X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FNews.pl;h=a161cd9d7e25a9566edc677d5c348e9f63d776c3;hb=refs%2Fheads%2Fdpkg;hp=6c2696a1d1ce9c613cf67a9aa021f2790bd36220;hpb=59b0e3d07dd301378ca8014330b1839d7c36edf4;p=infobot.git diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 6c2696a..a161cd9 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -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! # @@ -17,228 +17,272 @@ package News; -sub Parse { - my($what) = @_; - $chan = undef; - - if (!keys %::news) { - if (!exists $::cache{newsFirst}) { - &::DEBUG("looks like we enabled news option just then; loading up news file just in case."); - $::cache{newsFirst} = 1; - } +use strict; - &readNews(); - } +use vars qw($who $chan); - if ($::msgType ne "private") { - $chan = $::chan; +sub Parse { + my ($what) = @_; + $chan = undef; + $who = lc $::who; + + if ( !keys %::news ) { + if ( !exists $::cache{newsFirst} ) { + &::DEBUG( +"news: looks like we enabled news option just then; loading up news file just in case." + ); + $::cache{newsFirst} = 1; + } + + &readNews(); } - if (defined $what and $what =~ s/^($::mask{chan})\s*//) { - # todo: check if the channel exists aswell. - $chan = lc $1; - - if (!&::IsNickInChan($::who, $chan)) { - &::notice($::who, "sorry but you're not on $chan."); - return; - } + if ( $::msgType ne 'private' ) { + $chan = $::chan; } - if (!defined $chan) { - my @chans = &::getNickInChans($::who); + if ( defined $what and $what =~ s/^($::mask{chan})\s*// ) { - if (scalar @chans > 1) { - &::notice($::who, "error: I dunno which channel you are referring to since you're on more than one. Try 'news #chan ...' instead"); - return; - } + # TODO: check if the channel exists aswell. + $chan = lc $1; - if (scalar @chans == 0) { - &::notice($::who, "error: I couldn't find you on any chan. This must be a bug!"); - return; - } + if ( !&::IsNickInChan( $who, $chan ) ) { + &::notice( $who, "sorry but you're not on $chan." ); + return; + } + } - $chan = $chans[0]; - &::VERB("Guessed $::who being on chan $chan",2); - $::chan = $chan; # hack for IsChanConf(). + if ( !defined $chan ) { + my @chans = &::getNickInChans($who); + + if ( scalar @chans > 1 ) { + &::notice( $who, +"error: I dunno which channel you are referring to since you're on more than one. Try 'news #chan ...' instead" + ); + return; + } + + if ( scalar @chans == 0 ) { + &::notice( $who, + "error: I couldn't find you on any chan. This must be a bug!" ); + return; + } + + $chan = $chans[0]; + &::VERB( "Guessed $who being on chan $chan", 2 ); + $::chan = $chan; # hack for IsChanConf(). } - if (!defined $what or $what =~ /^\s*$/) { - &list(); - return; + if ( !defined $what or $what =~ /^\s*$/ ) { + &list(); + return; } - if ($what =~ /^add(\s+(.*))?$/i) { - &add($2); + if ( $what =~ /^add(\s+(.*))?$/i ) { + &add($2); - } elsif ($what =~ /^del(\s+(.*))?$/i) { - &del($2); + } + elsif ( $what =~ /^del(\s+(.*))?$/i ) { + &del($2); - } elsif ($what =~ /^mod(\s+(.*))?$/i) { - &mod($2); + } + elsif ( $what =~ /^mod(\s+(.*))?$/i ) { + &mod($2); - } elsif ($what =~ /^set(\s+(.*))?$/i) { - &set($2); + } + elsif ( $what =~ /^set(\s+(.*))?$/i ) { + &set($2); - } elsif ($what =~ /^(\d+)$/i) { - &::DEBUG("read shortcut called."); - &read($1); + } + elsif ( $what =~ /^(\d+)$/i ) { + &::VERB( "News: read shortcut called.", 2 ); + &read($1); - } elsif ($what =~ /^read(\s+(.*))?$/i) { - &read($2); + } + elsif ( $what =~ /^read(\s+(.*))?$/i ) { + &read($2); - } elsif ($what =~ /^(latest|new)(\s+(.*))?$/i) { - &latest($3 || $chan, 1); + } + elsif ( $what =~ /^(latest|new)(\s+(.*))?$/i ) { + &latest( $3 || $chan, 1 ); - } elsif ($what =~ /^list$/i) { - &::DEBUG("list longcut called."); - &list(); + # $::cmdstats{'News latest'}++; - } elsif ($what =~ /^(expire|text|desc)(\s+(.*))?$/i) { - # shortcut/link. - # nice hack. - my($arg1,$arg2) = split(/\s+/, $3, 2); - &set("$arg1 $1 $arg2"); + } + elsif ( $what =~ /^stats?$/i ) { + &stats(); - } elsif ($what =~ /^help(\s+(.*))?$/i) { - &::help("news$1"); + } + elsif ( $what =~ /^list$/i ) { + &list(); - } elsif ($what =~ /^newsflush$/i) { - &::msg($::who, "newsflush called... check out the logs!"); - &::newsFlush(); + } + elsif ( $what =~ /^(expire|text|desc)(\s+(.*))?$/i ) { - } elsif ($what =~ /^(un)?notify$/i) { - my $state = ($1) ? 0 : 1; + # shortcut/link. + # nice hack. + my $cmd = $1; + my ( $arg1, $arg2 ) = split( /\s+/, $3, 2 ); + &set("$arg1 $cmd $arg2"); - # todo: don't notify even if "news" is called. - if (!&::IsChanConf("newsNotifyAll")) { - &::DEBUG("chan => $chan, ::chan => $::chan."); - &::notice($::who, "not available for this channel or disabled altogether."); - return; - } + } + elsif ( $what =~ /^help(\s+(.*))?$/i ) { + &::help("news $2"); - my $t = $::newsuser{$chan}{$::who}; - if ($state) { # state = 1 - if (defined $t and ($t == 0 or $t == -1)) { - &::notice($::who, "enabled notify."); - delete $::newsuser{$chan}{$::who}; - return; - } - &::notice($::who, "already enabled."); + } + elsif ( $what =~ /^newsflush$/i ) { + &::msg( $who, "newsflush called... check out the logs!" ); + &::newsFlush(); - } else { # state = 0 - my $x = $::newsuser{$chan}{$::who}; - if (defined $x and ($x == 0 or $x == -1)) { - &::notice($::who, "notify already disabled"); - return; - } - $::newsuser{$chan}{$::who} = -1; - &::notice($::who, "notify is now disabled."); - } + } + elsif ( $what =~ /^(un)?notify$/i ) { + my $state = ($1) ? 0 : 1; + + # TODO: don't notify even if 'News' is called. + if ( &::IsChanConf('newsNotifyAll') <= 0 ) { + &::DEBUG("news: chan => $chan, ::chan => $::chan."); + &::notice( $who, + "not available for this channel or disabled altogether." ); + return; + } + + my $t = $::newsuser{$chan}{$who}; + if ($state) { # state = 1 + if ( defined $t and ( $t == 0 or $t == -1 ) ) { + &::notice( $who, "enabled notify." ); + delete $::newsuser{$chan}{$who}; + return; + } + &::notice( $who, "already enabled." ); + + } + else { # state = 0 + my $x = $::newsuser{$chan}{$who}; + if ( defined $x and ( $x == 0 or $x == -1 ) ) { + &::notice( $who, 'notify already disabled' ); + return; + } + $::newsuser{$chan}{$who} = -1; + &::notice( $who, "notify is now disabled." ); + } - } else { - &::DEBUG("could not parse '$what'."); - &::notice($::who, "unknown command: $what"); + } + else { + &::notice( $who, "unknown command: $what" ); } } sub readNews { - my $file = "$::bot_base_dir/blootbot-news.txt"; - if (! -f $file or -z $file) { - return; + my $file = "$::bot_base_dir/infobot-news.txt"; + if ( !-f $file or -z $file ) { + return; } - if (fileno NEWS) { - &::DEBUG("readNews: fileno exists, should never happen."); - return; + if ( fileno NEWS ) { + &::DEBUG("readNews: fileno exists, should never happen."); + return; } - my($item,$chan); - my($ci,$cu) = (0,0); + my ( $item, $chan ); + my ( $ci, $cu ) = ( 0, 0 ); - open(NEWS, $file); + open( NEWS, $file ); while () { - chop; - - # todo: allow commands. - - if (/^[\s\t]+(\S+):[\s\t]+(.*)$/) { - if (!defined $item) { - &::DEBUG("!defined item, never happen!"); - next; - } - - $::news{$chan}{$item}{$1} = $2; - next; - } - - # U