X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FNews.pl;h=a161cd9d7e25a9566edc677d5c348e9f63d776c3;hb=5f858217e186c9d7849c0f7e650d1ebae5a6eaeb;hp=1446db18a8694aaa79363549a77e8bd67da8298e;hpb=42592566d0395b130f1acd43d55b17c663e91d05;p=infobot.git diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 1446db1..a161cd9 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -1,14 +1,14 @@ # # News.pl: Advanced news management # Author: dms -# Version: v0.2 (20010326) +# Version: v0.3 (20010412) # Created: 20010326 # Notes: Testing done by greycat, kudos! # ### structure: -# news{ channel }{ string } { items } +# news{ channel }{ string } { item } # newsuser{ channel }{ user } = time() -### where items is: +### where item is: # Time - when it was added (used for sorting) # Author - Who by. # Expire - Time to expire. @@ -17,167 +17,272 @@ package News; +use strict; + +use vars qw($who $chan); + sub Parse { - my($what) = @_; - $chan = undef; - - if ($::msgType eq "private") { - } else { - $chan = $::chan; - } - - if (defined $what and $what =~ s/^($::mask{chan})\s*//) { - # todo: check if the channel exists aswell. - $chan = $1; - } - - if (!defined $chan) { - my @chans = &::GetNickInChans($::who); - - if (scalar @chans > 1) { - &::msg($::who, "error: I dunno which channel you are referring to since you're on more than one."); - return; - } - - if (scalar @chans == 0) { - &::msg($::who, "error: I couldn't find you on any chan. This must be a bug!"); - return; - } - - $chan = $chans[0]; - &::DEBUG("Guessed $::who being on chan $chan"); - } - - if (!defined $what or $what =~ /^\s*$/) { - &list(); - return; - } - - if ($what =~ /^add(\s+(.*))?$/i) { - &add($2); - } elsif ($what =~ /^del(\s+(.*))?$/i) { - &del($2); - } elsif ($what =~ /^mod(\s+(.*))?$/i) { - &mod($2); - } elsif ($what =~ /^set(\s+(.*))?$/i) { - &set($2); - } elsif ($what =~ /^(\d)$/i) { - &::DEBUG("read shortcut called."); - &read($1); - } elsif ($what =~ /^read(\s+(.*))?$/i) { - &read($2); - } elsif ($what =~ /^list$/i) { - &::DEBUG("list longcut called."); - &list(); - } elsif ($what =~ /^(expire|text|desc)(\s+(.*))?$/i) { - # shortcut/link. - # nice hack. - my($arg1,$arg2) = split(/\s+/, $3, 2); - &set("$arg1 Text $arg2"); - } elsif ($what =~ /^help(\s+(.*))?$/i) { - &::help("news$1"); - } else { - &::DEBUG("could not parse '$what'."); - &::msg($::who, "unknown command: $what"); + 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 ( $::msgType ne 'private' ) { + $chan = $::chan; + } + + 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 ( !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 ( $what =~ /^add(\s+(.*))?$/i ) { + &add($2); + + } + elsif ( $what =~ /^del(\s+(.*))?$/i ) { + &del($2); + + } + elsif ( $what =~ /^mod(\s+(.*))?$/i ) { + &mod($2); + + } + elsif ( $what =~ /^set(\s+(.*))?$/i ) { + &set($2); + + } + elsif ( $what =~ /^(\d+)$/i ) { + &::VERB( "News: read shortcut called.", 2 ); + &read($1); + + } + elsif ( $what =~ /^read(\s+(.*))?$/i ) { + &read($2); + + } + elsif ( $what =~ /^(latest|new)(\s+(.*))?$/i ) { + &latest( $3 || $chan, 1 ); + + # $::cmdstats{'News latest'}++; + + } + elsif ( $what =~ /^stats?$/i ) { + &stats(); + + } + elsif ( $what =~ /^list$/i ) { + &list(); + + } + elsif ( $what =~ /^(expire|text|desc)(\s+(.*))?$/i ) { + + # shortcut/link. + # nice hack. + my $cmd = $1; + my ( $arg1, $arg2 ) = split( /\s+/, $3, 2 ); + &set("$arg1 $cmd $arg2"); + + } + elsif ( $what =~ /^help(\s+(.*))?$/i ) { + &::help("news $2"); + + } + elsif ( $what =~ /^newsflush$/i ) { + &::msg( $who, "newsflush called... check out the logs!" ); + &::newsFlush(); + + } + 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 { + &::notice( $who, "unknown command: $what" ); } } sub readNews { - my $file = "$::bot_base_dir/blootbot-news.txt"; - if (! -f $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