]> git.donarmstrong.com Git - infobot.git/blobdiff - src/DynaConfig.pl
add initial SQLite support
[infobot.git] / src / DynaConfig.pl
index fad4ab27d8303da880bd5ead71ce05ce7c730552..da1739a0070b3d19b2292cf0b5b091bb028001b1 100644 (file)
@@ -6,14 +6,14 @@
 #         NOTE: Merged from User.pl
 #
 
-if (&IsParam("useStrict")) { use strict; }
+#use strict;
 
 #####
 ##### USERFILE CONFIGURATION READER/WRITER
 #####
 
 sub readUserFile {
-    my $f = "$bot_misc_dir/blootbot.users";
+    my $f = "$bot_state_dir/blootbot.users";
 
     if (! -f $f) {
        &DEBUG("userfile not found; new fresh run detected.");
@@ -30,14 +30,14 @@ sub readUserFile {
     }
 
     if (!open IN, $f) {
-       &ERROR("cannot read userfile.");
+       &ERROR("Cannot read userfile ($f): $!");
        &closeLog();
        exit 1;
     }
 
     undef %users;      # clear on reload.
     undef %bans;       # reset.
-    undef %ingore;     # reset.
+    undef %ignore;     # reset.
 
     my $ver = <IN>;
     if ($ver !~ /^#v1/) {
@@ -62,6 +62,11 @@ sub readUserFile {
                next;
            }
 
+           if (!defined $nick) {
+               &WARN("DynaConfig: invalid line: $_");
+               next;
+           }
+
            # nice little hack.
            if ($what eq "HOSTS") {
                $users{$nick}{$what}{$val} = 1;
@@ -117,8 +122,8 @@ sub writeUserFile {
        return;
     }
 
-    if (!open OUT,">$bot_misc_dir/blootbot.users") {
-       &ERROR("cannot write to userfile.");
+    if (!open OUT,">$bot_state_dir/blootbot.users") {
+       &ERROR("Cannot write userfile ($bot_state_dir/blootbot.users): $!");
        return;
     }
 
@@ -212,7 +217,7 @@ sub writeUserFile {
     $wtime_userfile = time();
     &status("--- Saved USERFILE ($cusers users; $cbans bans; $cignore ignore) at $time");
     if (defined $msgType and $msgType =~ /^chat$/) {
-       &performStrictReply("--- Writing user file...");
+       &pSReply("--- Writing user file...");
     }
 }
 
@@ -221,7 +226,7 @@ sub writeUserFile {
 #####
 
 sub readChanFile {
-    my $f = "$bot_misc_dir/blootbot.chan";
+    my $f = "$bot_state_dir/blootbot.chan";
     if ( -f $f and -f "$f~") {
        my $s1 = -s $f;
        my $s2 = -s "$f~";
@@ -232,7 +237,7 @@ sub readChanFile {
     }
 
     if (!open IN, $f) {
-       &ERROR("cannot erad chanfile.");
+       &ERROR("Cannot read chanfile ($f): $!");
        return;
     }
 
@@ -244,7 +249,8 @@ sub readChanFile {
     while (<IN>) {
        chop;
 
-       next if /^$/;
+       next if /^\s*$/;
+       next if /^\// or /^\;/; # / or ; are comment lines.
 
        if (/^(\S+)\s*$/) {
            $chan       = $1;
@@ -274,7 +280,8 @@ sub readChanFile {
     ### TODO: check against valid params.
     foreach $chan (keys %chanconf) {
        foreach (keys %{ $chanconf{$chan} }) {
-           next unless (/^[+-]/);
+           next unless /^[+-]/;
+
            &WARN("invalid param: chanconf{$chan}{$_}; removing.");
            delete $chanconf{$chan}{$_};
            undef $chanconf{$chan}{$_};
@@ -292,8 +299,8 @@ sub writeChanFile {
        return;
     }
 
-    if (!open OUT,">$bot_misc_dir/blootbot.chan") {
-       &ERROR("cannot write chanfile.");
+    if (!open OUT,">$bot_state_dir/blootbot.chan") {
+       &ERROR("Cannot write chanfile ($bot_state_dir/blootbot.chan): $!");
        return;
     }
 
@@ -315,6 +322,7 @@ sub writeChanFile {
                next if ($chan eq "_default");
                next unless (exists $chanconf{$chan}{$opt});
                next unless ($val eq $chanconf{$chan}{$opt});
+
                push(@chans,$chan);
                delete $chanconf{$chan}{$opt};
            }
@@ -344,7 +352,7 @@ sub writeChanFile {
        }
 
        foreach (keys %opts) {
-           next unless ($opts{$_} > 1);
+           next unless ($opts{$_} > 2);
            &DEBUG("  opts{$_} => $opts{$_}");
        }
 
@@ -382,7 +390,7 @@ sub writeChanFile {
                " chans) at $time");
 
     if (defined $msgType and $msgType =~ /^chat$/) {
-       &performStrictReply("--- Writing chan file...");
+       &pSReply("--- Writing chan file...");
     }
 }
 
@@ -484,7 +492,7 @@ sub hasFlag {
        return 1;
     } else {
        &status("DCC CHAT: <$who> $message -- not enough flags.");
-       &performStrictReply("error: you do not have enough flags for that. ($flag required)");
+       &pSReply("error: you do not have enough flags for that. ($flag required)");
        return 0;
     }
 }
@@ -508,6 +516,9 @@ sub ignoreAdd {
 
     $ignore{$chan}{$mask} = [$expire, time(), $who, $comment];
 
+    # todo: improve this.
+    &status("ignore: Added $mask for $chan to expire $expire, by $who, for $comment");
+
     if ($exist) {
        $utime_userfile = time();
        $ucount_userfile++;
@@ -768,6 +779,35 @@ sub chanSet {
     return;
 }
 
+sub rehashConfVars {
+    # this is an attempt to fix where an option is loaded but the module
+    # has not loaded. it also can be used for other things.
+
+    foreach (keys %{ $cache{confvars} }) {
+       my $i = $cache{confvars}{$_};
+       &DEBUG("rehashConfVars: _ => $_");
+
+       if (/^news$/ and $i) {
+           &loadMyModule("news");
+           delete $cache{confvars}{$_};
+       }
+
+       if (/^uptime$/ and $i) {
+           &loadMyModule("uptime");
+           delete $cache{confvars}{$_};
+       }
+
+       if (/^rootwarn$/i and $i) {
+           &loadMyModule($_);
+           delete $cache{confvars}{$_};
+       }
+    }
+
+    &DEBUG("end of rehashConfVars");
+
+    delete $cache{confvars};
+}
+
 my @regFlagsChan = (
        "autojoin",
        "freshmeat",