From 11e57f735626f775a95284a0d8ff284ec3617dc7 Mon Sep 17 00:00:00 2001 From: timriker Date: Fri, 6 Jan 2006 08:36:43 +0000 Subject: [PATCH] really support negative booleans and and return -1 for IsChanConf() when they are around git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@1250 c11ca15a-4712-0410-83d8-924469b57eb5 --- TODO | 2 -- files/sample/blootbot.chan | 3 ++- src/DynaConfig.pl | 6 +----- src/Factoids/Core.pl | 4 ++-- src/Factoids/Question.pl | 6 +++--- src/Factoids/Update.pl | 2 +- src/IRC/Irc.pl | 2 +- src/IRC/IrcHelpers.pl | 14 ++++++------- src/IRC/IrcHooks.pl | 14 ++++++------- src/IRC/Schedulers.pl | 4 ++-- src/Misc.pl | 2 +- src/Modules/News.pl | 9 ++++---- src/core.pl | 42 ++++++++++++++------------------------ src/modules.pl | 2 +- 14 files changed, 47 insertions(+), 65 deletions(-) diff --git a/TODO b/TODO index 133a453..b3ddccc 100644 --- a/TODO +++ b/TODO @@ -10,8 +10,6 @@ TODO: - move channel flags to sql table, include initial state - move praise from blootbot.lang to "praise:" in factoids? - move lart from blootbot.lang to "lart:" in factoids? - - all IsChanConf tests MUST check for >0 as -1 is possible there are a - lot of incorrect "if(IsChanConf("foo")) instances now - debian BTS frontend "bugs" - !country - !dinstall diff --git a/files/sample/blootbot.chan b/files/sample/blootbot.chan index 01af304..42a4086 100644 --- a/files/sample/blootbot.chan +++ b/files/sample/blootbot.chan @@ -1,6 +1,7 @@ -#v1: blootbot -- blootbot -- written Sun Jan 1 22:59:37 2006 +#v1: blootbot -- InfoBot -- written Fri Jan 6 08:29:25 2006 #botpark + -OnJoin +RootWarn +autojoin diff --git a/src/DynaConfig.pl b/src/DynaConfig.pl index e1cf464..ea94e5b 100644 --- a/src/DynaConfig.pl +++ b/src/DynaConfig.pl @@ -271,10 +271,8 @@ sub readChanFile { $chanconf{$chan}{$1} = 1; } elsif (/^[\s\t]+\-(\S+)$/) { # bool, false. - &DEBUG("deprecated support of negative options.") unless ($cache{negative}); # although this is supported in run-time configuration. - $cache{negative} = 1; -# $chanconf{$chan}{$1} = 0; + $chanconf{$chan}{$1} = 0; } elsif (/^[\s\t]+(\S+)[\s\t]+(.*)$/) {# what = val. $chanconf{$chan}{$1} = $2; @@ -297,8 +295,6 @@ sub readChanFile { } } - delete $cache{negative}; - &status("CHANFILE: Loaded: ".(scalar(keys %chanconf)-1)." chans"); } diff --git a/src/Factoids/Core.pl b/src/Factoids/Core.pl index 797e0fb..e33685c 100644 --- a/src/Factoids/Core.pl +++ b/src/Factoids/Core.pl @@ -241,7 +241,7 @@ sub FactoidStuff { # lets do it! - if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) { + if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay") > 0) { if (!($isop or $isau) and $faqtoid =~ / #DEL#$/) { &msg($who, "cannot delete it ($faqtoid)."); return; @@ -290,7 +290,7 @@ sub FactoidStuff { my $i = 0; $i++ if (&IsParam("factoidDeleteDelay")); - $i++ if (&IsChanConf("factoidDeleteDelay")); + $i++ if (&IsChanConf("factoidDeleteDelay") > 0); if (!$i) { &performReply("safe delete has been disable so what is there to undelete?"); return; diff --git a/src/Factoids/Question.pl b/src/Factoids/Question.pl index 5b26105..44fd742 100644 --- a/src/Factoids/Question.pl +++ b/src/Factoids/Question.pl @@ -33,7 +33,7 @@ sub doQuestion { if (!$addressed) { return '' unless ($finalQMark); - return '' unless &IsChanConf("minVolunteerLength"); + return '' unless &IsChanConf("minVolunteerLength") > 0; return '' if (length $query < &::getChanConf('minVolunteerLength')); } else { ### TODO: this should be caught in Process.pl? @@ -93,7 +93,7 @@ sub doQuestion { $query =~ s/^\s+|\s+$//g; # bleh. hacked. push(@query, $query) if ($query ne $x); - if (&IsChanConf("factoidArguments")) { + if (&IsChanConf("factoidArguments") > 0) { $result = &factoidArgs($query[0]); return $result if (defined $result); @@ -154,7 +154,7 @@ sub doQuestion { } ### TODO: Use &Forker(); move function to Debian.pl - if (&IsChanConf('debianForFactoid')) { + if (&IsChanConf('debianForFactoid') > 0) { &loadMyModule('Debian'); $result = &Debian::DebianFind($query); # ??? ### TODO: debian module should tell, through shm, that it went diff --git a/src/Factoids/Update.pl b/src/Factoids/Update.pl index 915eec1..400012e 100644 --- a/src/Factoids/Update.pl +++ b/src/Factoids/Update.pl @@ -54,7 +54,7 @@ sub update { # factoid arguments handler. # must start with a non-variable - if (&IsChanConf("factoidArguments") and $lhs =~ /^[^\$]+.*\$/) { + if (&IsChanConf("factoidArguments") > 0 and $lhs =~ /^[^\$]+.*\$/) { &status("Update: Factoid Arguments found."); &status("Update: orig lhs => '$lhs'."); &status("Update: orig rhs => '$rhs'."); diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 7eecd58..b121fdf 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -895,7 +895,7 @@ sub closeDCC { sub joinfloodCheck { my($who,$chan,$userhost) = @_; - return unless (&IsChanConf("joinfloodCheck")); + return unless (&IsChanConf("joinfloodCheck") > 0); if (exists $netsplit{lc $who}) { # netsplit join. &DEBUG("joinfloodCheck: $who was in netsplit; not checking."); diff --git a/src/IRC/IrcHelpers.pl b/src/IRC/IrcHelpers.pl index 1d1ea47..200ddfd 100644 --- a/src/IRC/IrcHelpers.pl +++ b/src/IRC/IrcHelpers.pl @@ -91,7 +91,7 @@ sub hookMsg { if ($msgType =~ /private/) { # private messages. $addressed = 1; - if (&IsChanConf('addressCharacter')) { + if (&IsChanConf('addressCharacter') > 0) { $addressCharacter = getChanConf('addressCharacter'); if ($message =~ s/^\Q$addressCharacter\E//) { &msg($who, "The addressCharacter \"$addressCharacter\" is to get my attention in a normal channel. Please leave it off when messaging me directly."); @@ -101,7 +101,7 @@ sub hookMsg { # public messages. # addressing revamped by the xk. ### below needs to be fixed... - if (&IsChanConf('addressCharacter')) { + if (&IsChanConf('addressCharacter') > 0) { $addressCharacter = getChanConf('addressCharacter'); if ($message =~ s/^\Q$addressCharacter\E//) { $addrchar = 1; @@ -141,7 +141,7 @@ sub hookMsg { if ($addressed) { my $time = $flood{$floodwho}{$message} || 0; - if ($msgType eq "public" and (time() - $time < $interval)) { + if (!&hasFlag("o") and $msgType eq "public" and (time() - $time < $interval)) { ### public != personal who so the below is kind of pointless. my @who; foreach (keys %flood) { @@ -183,7 +183,7 @@ sub hookMsg { } $flood{$floodwho}{$message} = time(); - } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) { + } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat") > 0) { # unaddressed, public only. ### TODO: use a separate "short-time" hash. @@ -241,7 +241,7 @@ sub hookMsg { $seencache{$who}{'msg'} = $orig{message}; $seencache{$who}{'msgcount'}++; } - if (&IsChanConf("minVolunteerLength")) { + if (&IsChanConf("minVolunteerLength") > 0) { # FIXME hack to treat unaddressed as if using addrchar $addrchar = 1; } @@ -294,7 +294,7 @@ sub chanLimitVerify { $chan = $c; my $l = $channels{$chan}{'l'}; - return unless (&IsChanConf("chanlimitcheck")); + return unless (&IsChanConf("chanlimitcheck") > 0); if (scalar keys %netsplit) { &WARN("clV: netsplit active (1, chan = $chan); skipping."); @@ -349,7 +349,7 @@ sub chanServCheck { &DEBUG("chanServCheck: lowercased chan ($chan)"); } - if (! &IsChanConf("chanServ_ops") ) { + if (! &IsChanConf("chanServ_ops") > 0) { return 0; } diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index 542ba63..d105d8e 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -171,7 +171,7 @@ sub on_endofmotd { } # end of first time run. - if (&IsChanConf('Wingate')) { + if (&IsChanConf('Wingate') > 0) { my $file = "$bot_base_dir/$param{'ircUser'}.wingate"; open(IN, $file); while () { @@ -580,15 +580,15 @@ sub on_join { ### ROOTWARN: &rootWarn($who,$user,$host,$chan) if ( - &IsChanConf('RootWarn') && + &IsChanConf('RootWarn') > 0 && $user =~ /^~?r(oo|ew|00)t$/i ); ### emit a message based on who just joined - &onjoin($who,$user,$host,$chan) if (&IsChanConf('OnJoin')); + &onjoin($who,$user,$host,$chan) if (&IsChanConf('OnJoin') > 0); ### NEWS: - if (&IsChanConf('News') && &IsChanConf('newsKeepRead')) { + if (&IsChanConf('News') > 0 && &IsChanConf('newsKeepRead') > 0) { if (!&loadMyModule('News')) { # just in case. &DEBUG('could not load news.'); } else { @@ -597,7 +597,7 @@ sub on_join { } ### botmail: - if (&IsChanConf('botmail')) { + if (&IsChanConf('botmail') > 0) { &botmail::check(lc $who); } @@ -974,7 +974,7 @@ sub on_quit { # chanlimit code. foreach $chan ( &getNickInChans($nick) ) { - next unless ( &IsChanConf("chanlimitcheck") ); + next unless ( &IsChanConf("chanlimitcheck") > 0); next unless ( exists $channels{$_}{'l'} ); &DEBUG("on_quit: netsplit detected on $_; disabling chan limit."); @@ -1070,7 +1070,7 @@ sub on_topic { &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic"); } else { # join. my ($nick, $chan, $topic) = $event->args; - if (&IsChanConf('Topic')) { + if (&IsChanConf('Topic') > 0) { $topic{$chan}{'Current'} = $topic; &topicAddHistory($chan,$topic); } diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index d18a35d..8d8f9e2 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -924,12 +924,12 @@ sub kernelLoop { } sub wingateCheck { - return unless &IsChanConf('Wingate'); + return unless &IsChanConf('Wingate') > 0; ### FILE CACHE OF OFFENDING WINGATES. foreach (grep /^$host$/, @wingateBad) { &status("Wingate: RUNNING ON $host BY $who"); - &ban("*!*\@$host", "") if &IsChanConf('wingateBan'); + &ban("*!*\@$host", "") if &IsChanConf('wingateBan') > 0; my $reason = &getChanConf('wingateKick'); diff --git a/src/Misc.pl b/src/Misc.pl index fc6f037..bf95b60 100644 --- a/src/Misc.pl +++ b/src/Misc.pl @@ -593,7 +593,7 @@ sub hasProfanity { sub IsChanConfOrWarn { my ($param) = @_; - if (&IsChanConf($param)) { + if (&IsChanConf($param) > 0) { return 1; } else { ### TODO: specific reason why it failed. diff --git a/src/Modules/News.pl b/src/Modules/News.pl index c82b577..25b049c 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -119,7 +119,7 @@ sub Parse { my $state = ($1) ? 0 : 1; # TODO: don't notify even if "News" is called. - if (!&::IsChanConf("newsNotifyAll")) { + if (&::IsChanConf("newsNotifyAll") <= 0) { &::DEBUG("news: chan => $chan, ::chan => $::chan."); &::notice($who, "not available for this channel or disabled altogether."); return; @@ -371,7 +371,7 @@ sub list { return; } - if (&::IsChanConf("newsKeepRead")) { + if (&::IsChanConf("newsKeepRead") > 0) { my $x = $::newsuser{$chan}{$who}; if (defined $x and ($x == 0 or $x == -1)) { @@ -751,8 +751,7 @@ sub latest { } $::chan = $chan; - my $x = &::IsChanConf("newsNotifyAll"); - return if (!$x); + return if (&::IsChanConf("newsNotifyAll") <= 0); # I don't understand this code ;) $t = 1 if (!defined $t); @@ -792,7 +791,7 @@ sub latest { # scalar @new, !$flag my $unread = scalar @new; my $total = scalar keys %{ $::news{$chan} }; - if (!$flag && !&::IsChanConf("newsTellUnread")) { + if (!$flag && &::IsChanConf("newsTellUnread") <= 0) { return; } diff --git a/src/core.pl b/src/core.pl index ccb526b..ba82171 100644 --- a/src/core.pl +++ b/src/core.pl @@ -197,8 +197,8 @@ sub getChanConfList { foreach (keys %chanconf) { my $chan = $_; -# &DEBUG("chan => $chan"); my @array = grep /^$param$/, keys %{ $chanconf{$chan} }; + #&DEBUG("gCCL param => $param, chan => $chan, keys => " . join(':',keys %{ $chanconf{$chan} }) . " array => " . join(':', @array)) if ($param eq 'whatever'); next unless (scalar @array); @@ -206,7 +206,7 @@ sub getChanConfList { &WARN("multiple items found?"); } - if ($array[0] eq "0") { + if ($chanconf{$chan}{$param} eq "0") { $chan{$chan} = -1; } else { $chan{$chan} = 1; @@ -222,7 +222,9 @@ sub getChanConfList { # Return: 1 for enabled, 0 for passive disable, -1 for active disable. sub IsChanConf { my($param) = shift; - my $debug = 0; # knocked tons of bugs with this! :) + + # knocked tons of bugs with this! :) + my $debug = 0 # 1 if ($param eq "whatever"); if (!defined $param) { &WARN("IsChanConf: param == NULL."); @@ -236,7 +238,7 @@ sub IsChanConf { return 1; } - $chan ||= "_default"; + $chan ||= "_default"; my $old = $chan; if ($chan =~ tr/A-Z/a-z/) { @@ -254,9 +256,11 @@ sub IsChanConf { } ### debug purposes only. -# &DEBUG("param => $param, msgType => $msgType."); -# foreach (keys %chan) { -# &DEBUG(" $_ => $chan{$_}"); +# if ($debug) { +# &DEBUG("param => $param, msgType => $msgType."); +# foreach (keys %chan) { +# &DEBUG(" $_ => $chan{$_}"); +# } # } if ($nomatch) { @@ -267,31 +271,15 @@ sub IsChanConf { } else { &DEBUG("ICC: other: 0 ($param)") if ($debug); } - return $chan{$chan} || $chan{_default} || 0; - } - - if ($msgType eq "public") { + } elsif ($msgType =~ /^(public|private)$/i) { if ($chan{$chan}) { - &DEBUG("ICC: public: $chan{$chan} ($chan/$param)") if ($debug); + &DEBUG("ICC: $msgType: $chan{$chan} ($chan/$param)") if ($debug); } elsif ($chan{_default}) { - &DEBUG("ICC: public: $chan{_default} (_default/$param)") if ($debug); - } else { - &DEBUG("ICC: public: 0 ($param)") if ($debug); - } - - return $chan{$chan} || $chan{_default} || 0; - } - - if ($msgType eq "private") { - if ($chan{_default}) { - &DEBUG("ICC: private: $chan{_default} (_default/$param)") if ($debug); - } elsif ($chan{$chan}) { - &DEBUG("ICC: private: $chan{$chan} ($chan/$param) (hack)") if ($debug); + &DEBUG("ICC: $msgType: $chan{_default} (_default/$param)") if ($debug); } else { - &DEBUG("ICC: private: 0 ($param)") if ($debug); + &DEBUG("ICC: $msgType: 0 ($param)") if ($debug); } - return $chan{$chan} || $chan{_default} || 0; } diff --git a/src/modules.pl b/src/modules.pl index 961b90b..bcbd328 100644 --- a/src/modules.pl +++ b/src/modules.pl @@ -140,7 +140,7 @@ sub loadMyModulesNow { next; } - if (!&IsParam($_) and !&IsChanConf($_) and !&getChanConfList($_)) { + if (!&IsParam($_) and &IsChanConf($_) <= 0 and !&getChanConfList($_)) { &DEBUG("loadMyModuleNow: $_ (2) not loaded."); next; } -- 2.39.2