X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FNews.pl;h=a161cd9d7e25a9566edc677d5c348e9f63d776c3;hb=f06ee2cec2996f92167474845aee2f5112588288;hp=33d8933d86b923f3b833bd29b5cb98ab8abc91aa;hpb=cc8ab9a5235b29e43af923836d24579413c882d6;p=infobot.git diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 33d8933..a161cd9 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -15,242 +15,274 @@ # Text - Actual text. ### -use vars qw($who $chan); - package News; +use strict; + +use vars qw($who $chan); + sub Parse { - my($what) = @_; - $chan = undef; - $who = lc $::who; + 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; - } + 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(); + &readNews(); } - if ($::msgType ne "private") { - $chan = $::chan; + 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 ( 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 ( !&::IsNickInChan( $who, $chan ) ) { + &::notice( $who, "sorry but you're not on $chan." ); + return; + } } - if (!defined $chan) { - my @chans = &::getNickInChans($who); + 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 > 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; - } + 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(). + $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) { - &::VERB("News: read shortcut called.",2); - &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); -# $::cmdstats{'News latest'}++; + } + elsif ( $what =~ /^(latest|new)(\s+(.*))?$/i ) { + &latest( $3 || $chan, 1 ); - } elsif ($what =~ /^stats?$/i) { - &stats(); + # $::cmdstats{'News latest'}++; - } elsif ($what =~ /^list$/i) { - &list(); + } + elsif ( $what =~ /^stats?$/i ) { + &stats(); - } 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 =~ /^list$/i ) { + &list(); - } elsif ($what =~ /^help(\s+(.*))?$/i) { - &::help("news $2"); + } + elsif ( $what =~ /^(expire|text|desc)(\s+(.*))?$/i ) { - } elsif ($what =~ /^newsflush$/i) { - &::msg($who, "newsflush called... check out the logs!"); - &::newsFlush(); + # shortcut/link. + # nice hack. + my $cmd = $1; + my ( $arg1, $arg2 ) = split( /\s+/, $3, 2 ); + &set("$arg1 $cmd $arg2"); - } elsif ($what =~ /^(un)?notify$/i) { - my $state = ($1) ? 0 : 1; + } + elsif ( $what =~ /^help(\s+(.*))?$/i ) { + &::help("news $2"); - # 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."); - return; - } + } + 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."); + 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 { # 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"); + } + 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; + chop; - # todo: allow commands. + # TODO: allow commands. - if (/^[\s\t]+(\S+):[\s\t]+(.*)$/) { - if (!defined $item) { - &::DEBUG("news: !defined item, never happen!"); - next; - } + if (/^[\s\t]+(\S+):[\s\t]+(.*)$/) { + if ( !defined $item ) { + &::DEBUG("news: !defined item, never happen!"); + next; + } - $::news{$chan}{$item}{$1} = $2; - next; - } + $::news{$chan}{$item}{$1} = $2; + next; + } - # U