From 6586c8555f4257dcd956c04303fe2fdbcf155706 Mon Sep 17 00:00:00 2001 From: dms Date: Tue, 3 Apr 2001 12:06:08 +0000 Subject: [PATCH] More clean ups, forgotten what they were, heh. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@427 c11ca15a-4712-0410-83d8-924469b57eb5 --- blootbot/src/DynaConfig.pl | 35 ++++++++++++++++++++++++++++++++-- blootbot/src/IRC/IrcHooks.pl | 7 +++++-- blootbot/src/IRC/Schedulers.pl | 12 ++++++------ blootbot/src/Modules/News.pl | 20 ++++++++++--------- blootbot/src/modules.pl | 5 +---- 5 files changed, 56 insertions(+), 23 deletions(-) diff --git a/blootbot/src/DynaConfig.pl b/blootbot/src/DynaConfig.pl index 2a78ebf..d121937 100644 --- a/blootbot/src/DynaConfig.pl +++ b/blootbot/src/DynaConfig.pl @@ -13,7 +13,18 @@ if (&IsParam("useStrict")) { use strict; } ##### sub readUserFile { - if (!open IN,"$bot_misc_dir/blootbot.users") { + my $f = "$bot_misc_dir/blootbot.users"; + + if ( -f $f and -f "$f~") { + my $s1 = -s $f; + my $s2 = -s "$f~"; + + if ($s2 > $s1*3) { + &DEBUG("rUF: backup file bigger than current file. FIXME"); + } + } + + if (!open IN, $f) { &ERROR("cannot read userfile."); &closeLog(); exit 1; @@ -96,6 +107,11 @@ sub readUserFile { } sub writeUserFile { + if (!scalar keys %users) { + &DEBUG("wUF: nothing to write."); + return; + } + if (!open OUT,">$bot_misc_dir/blootbot.users") { &ERROR("cannot write to userfile."); return; @@ -200,7 +216,17 @@ sub writeUserFile { ##### sub readChanFile { - if (!open IN,"$bot_misc_dir/blootbot.chan") { + my $f = "$bot_misc_dir/blootbot.chan"; + if ( -f $f and -f "$f~") { + my $s1 = -s $f; + my $s2 = -s "$f~"; + + if ($s2 > $s1*3) { + &DEBUG("rCF: backup file bigger than current file. FIXME"); + } + } + + if (!open IN, $f) { &ERROR("cannot erad chanfile."); return; } @@ -256,6 +282,11 @@ sub readChanFile { } sub writeChanFile { + if (!scalar keys %chanconf) { + &DEBUG("wCF: nothing to write."); + return; + } + if (!open OUT,">$bot_misc_dir/blootbot.chan") { &ERROR("cannot write chanfile."); return; diff --git a/blootbot/src/IRC/IrcHooks.pl b/blootbot/src/IRC/IrcHooks.pl index 0fce62e..006f106 100644 --- a/blootbot/src/IRC/IrcHooks.pl +++ b/blootbot/src/IRC/IrcHooks.pl @@ -359,6 +359,9 @@ sub on_endofnames { if (scalar @joinchan) { # remaining channels to join. &joinNextChan(); + } else { + &DEBUG("running ircCheck to get chanserv ops."); + &ircCheck(); } return unless (&IsChanConf("chanServ_ops") > 0); @@ -1222,8 +1225,8 @@ sub chanLimitVerify { ### todo: check if we have ops. ### todo: if not, check if nickserv/chanserv is avail. ### todo: unify code with chanlimitcheck() - if ($delta > 3) { - &WARN("clc: nowl($nowl) > l($l) - 3"); + if ($delta > 5) { + &status("clc: big change in limit; changing."); &rawout("MODE $chan +l ".($nowl+$plus) ); } } diff --git a/blootbot/src/IRC/Schedulers.pl b/blootbot/src/IRC/Schedulers.pl index 2abf5ea..1bdba62 100644 --- a/blootbot/src/IRC/Schedulers.pl +++ b/blootbot/src/IRC/Schedulers.pl @@ -310,8 +310,8 @@ sub newsFlush { next unless (time() > $t); # todo: show how old it was. - &DEBUG("delete $chan/'$item'."); delete $::news{$chan}{$item}; + &VERB("NEWS: deleted '$item'", 2); $delete++; } } @@ -333,10 +333,10 @@ sub newsFlush { } } - &News::writeNews(); - # &VERB("NEWS deleted $delete seen entries.",2); - &status("NEWS deleted $delete news entries; $duser user cache."); + &status("NEWS deleted: $delete news entries; $duser user cache."); + + &News::writeNews(); } sub chanlimitCheck { @@ -364,7 +364,7 @@ sub chanlimitCheck { next unless (!defined $limit or $limit != $newlimit); if (!exists $channels{$chan}{'o'}{$ident}) { - &ERROR("chanlimitcheck: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan}); + &status("ChanLimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan}); $cache{warn}{chanlimit}{$chan} = 1; ### TODO: check chanserv? next; @@ -372,7 +372,7 @@ sub chanlimitCheck { delete $cache{warn}{chanlimit}{$chan}; if (!defined $limit) { - &DEBUG("setting limit for first time or from netsplit for $chan"); + &status("ChanLimit: setting for first time or from netsplit, for $chan"); } &rawout("MODE $chan +l $newlimit"); diff --git a/blootbot/src/Modules/News.pl b/blootbot/src/Modules/News.pl index c21799a..28ca58a 100644 --- a/blootbot/src/Modules/News.pl +++ b/blootbot/src/Modules/News.pl @@ -11,7 +11,7 @@ ### where items is: # Time - when it was added (used for sorting) # Author - Who by. -# Expire - Time to expire +# Expire - Time to expire. # Text - Actual text. ### @@ -140,6 +140,7 @@ sub writeNews { # todo: add commands to output file. my $c = 0; my($cc,$ci,$cu) = (0,0,0); + open(NEWS, ">$file"); foreach $chan (sort keys %::news) { $c = scalar keys %{ $::news{$chan} }; @@ -163,11 +164,10 @@ sub writeNews { if (&::getChanConfList("newsKeepRead")) { # old users are removed in newsFlush(), perhaps it should be # done here. - &::DEBUG("newsuser cache..."); + foreach $chan (sort keys %::newsuser) { - &::DEBUG("newsuser cache: chan => $chan"); + foreach (sort keys %{ $::newsuser{$chan} }) { - &::DEBUG("newsuser cache: user => $_"); print NEWS "U $chan $_ $::newsuser{$chan}{$_}\n"; $cu++; } @@ -204,11 +204,14 @@ sub add { my $agestr = &::Time2String($::news{$chan}{$str}{Expire} - time() ); my $item = &getNewsItem($str); + if ($item eq $str) { + &::DEBUG("item eq str ($item): should never happen."); + } &::msg($::who, "Added '\037$str\037' at [".localtime(time). "] by \002$::who\002 for item #\002$item\002."); &::msg($::who, "Now do 'news text $item '"); &::msg($::who, "This item will expire at \002". - localtime($::news{$chan}{$str}{Expire})."\002 [$agestr] " + localtime($::news{$chan}{$str}{Expire})."\002 [$agestr from now] " ); } @@ -297,8 +300,8 @@ sub list { my $t = $::news{$chan}{$_}{Time}; $newest = $t if ($t > $newest); } - &::msg($::who, "|= Last updated ". - &::Time2String(time() - $newest). " ago."); + my $timestr = &::Time2String(time() - $newest); + &::msg($::who, "|= Last updated $timestr ago."); &::msg($::who, " \037No\037 \037Item ".(" "x40)." \037"); my $i = 1; @@ -316,10 +319,9 @@ sub list { $i, $subtopic)); $i++; } + &::msg($::who, "|= End of News."); &::msg($::who, "use 'news read <#>' or 'news read '"); - - &::DEBUG("news cache => ".scalar(keys %::newsuser) ); } sub read { diff --git a/blootbot/src/modules.pl b/blootbot/src/modules.pl index d06ec19..ee86c38 100644 --- a/blootbot/src/modules.pl +++ b/blootbot/src/modules.pl @@ -59,8 +59,6 @@ sub loadCoreModules { exit 1; } - &status("Loading CORE modules..."); - my @mods; while (defined(my $file = readdir DIR)) { next unless $file =~ /\.pl$/; @@ -68,12 +66,11 @@ sub loadCoreModules { push(@mods, $file); } closedir DIR; - &DEBUG("mods: ".scalar(@mods)." to be loaded..."); + &status("Loading ".scalar(@mods)." CORE modules..."); foreach (sort @mods) { my $mod = "$bot_src_dir/$_"; - ### TODO: use eval and exit gracefully? eval "require \"$mod\""; if ($@) { &ERROR("lCM => $@"); -- 2.39.5