]> git.donarmstrong.com Git - infobot.git/blobdiff - src/DynaConfig.pl
gmtime
[infobot.git] / src / DynaConfig.pl
index b76e7579763d94f8bbf519822a8c75ccf0ea4e97..e5b6eb609117b3793716799647329959439cbe68 100644 (file)
@@ -6,7 +6,14 @@
 #         NOTE: Merged from User.pl
 #
 
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+
+use vars qw(%chanconf %cache %bans %channels %nuh %users %ignore
+       %talkWho %dcc %mask);
+use vars qw($utime_userfile $ucount_userfile $utime_chanfile $who
+       $ucount_chanfile $userHandle $chan $msgType $talkchannel
+       $ident $bot_state_dir $talkWho $flag_quit $wtime_userfile
+       $wcount_userfile $wtime_chanfile $nuh $message);
 
 #####
 ##### USERFILE CONFIGURATION READER/WRITER
@@ -30,14 +37,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/) {
@@ -123,11 +130,11 @@ sub writeUserFile {
     }
 
     if (!open OUT,">$bot_state_dir/blootbot.users") {
-       &ERROR("cannot write to userfile.");
+       &ERROR("Cannot write userfile ($bot_state_dir/blootbot.users): $!");
        return;
     }
 
-    my $time           = scalar(localtime);
+    my $time           = scalar(gmtime);
 
     print OUT "#v1: blootbot -- $ident -- written $time\n\n";
 
@@ -217,7 +224,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...");
     }
 }
 
@@ -237,7 +244,7 @@ sub readChanFile {
     }
 
     if (!open IN, $f) {
-       &ERROR("cannot erad chanfile.");
+       &ERROR("Cannot read chanfile ($f): $!");
        return;
     }
 
@@ -249,7 +256,8 @@ sub readChanFile {
     while (<IN>) {
        chop;
 
-       next if /^$/;
+       next if /^\s*$/;
+       next if /^\// or /^\;/; # / or ; are comment lines.
 
        if (/^(\S+)\s*$/) {
            $chan       = $1;
@@ -279,7 +287,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}{$_};
@@ -298,11 +307,11 @@ sub writeChanFile {
     }
 
     if (!open OUT,">$bot_state_dir/blootbot.chan") {
-       &ERROR("cannot write chanfile.");
+       &ERROR("Cannot write chanfile ($bot_state_dir/blootbot.chan): $!");
        return;
     }
 
-    my $time           = scalar(localtime);
+    my $time           = scalar(gmtime);
     print OUT "#v1: blootbot -- $ident -- written $time\n\n";
 
     if ($flag_quit) {
@@ -320,6 +329,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};
            }
@@ -387,7 +397,7 @@ sub writeChanFile {
                " chans) at $time");
 
     if (defined $msgType and $msgType =~ /^chat$/) {
-       &performStrictReply("--- Writing chan file...");
+       &pSReply("--- Writing chan file...");
     }
 }
 
@@ -395,6 +405,7 @@ sub writeChanFile {
 ##### USER COMMANDS.
 #####
 
+# todo: support multiple flags.
 sub IsFlag {
     my $flags = shift;
     my ($ret, $f, $o) = "";
@@ -415,7 +426,7 @@ sub IsFlag {
 
 sub verifyUser {
     my ($nick, $lnuh) = @_;
-    my ($user,$m);
+    my ($user, $m);
 
     if ($userHandle = $dcc{'CHATvrfy'}{$who}) {
        &VERB("vUser: cached auth for $who.",2);
@@ -489,7 +500,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;
     }
 }
@@ -503,7 +514,7 @@ sub ignoreAdd {
     my $count  ||= 0;
 
     if ($expire > 0) {
-       $expire         = $expire*60 + time();
+       $expire         = ($expire*60) + time();
     } else {
        $expire         = 0;
     }
@@ -513,6 +524,13 @@ sub ignoreAdd {
 
     $ignore{$chan}{$mask} = [$expire, time(), $who, $comment];
 
+    # todo: improve this.
+    if ($expire == 0) {
+       &status("ignore: Added $mask for $chan to NEVER expire, by $who, for $comment");
+    } else {
+       &status("ignore: Added $mask for $chan to expire $expire mins, by $who, for $comment");
+    }
+
     if ($exist) {
        $utime_userfile = time();
        $ucount_userfile++;
@@ -681,7 +699,7 @@ sub chanSet {
            return;
        }
        $chanconf{$chan}{_time_added}   = time();
-       $chanconf{$what}{autojoin}      = 1;
+       $chanconf{$chan}{autojoin}      = 1;
 
        &pSReply("Joining $chan...");
        &joinchan($chan);
@@ -696,9 +714,10 @@ sub chanSet {
 
     my $update = 0;
 
-    ### ".chanset +blah"
-    ### ".chanset +blah 10"            -- error.
     if (defined $what and $what =~ s/^([+-])(\S+)/$2/) {
+       ### ".chanset +blah"
+       ### ".chanset +blah 10"         -- error.
+
        my $state       = ($1 eq "+") ? 1 : 0;
        my $was         = $chanconf{$chan}{$what};
 
@@ -708,7 +727,6 @@ sub chanSet {
                return;
            }
 
-           $was        = ($was) ? "; was '$was'" : "";
            $val        = 1;
 
        } else {                        # delete/unset.
@@ -722,10 +740,12 @@ sub chanSet {
                return;
            }
 
-           $was        = ($was) ? "; was '$was'" : "";
            $val        = 0;
        }
 
+       # alter for cosmetic (print out) reasons only.
+       $was    = ($was) ? "; was '$was'" : "";
+
        if ($val eq "0") {
            &pSReply("Unsetting $what for $chan$was.");
            delete $chanconf{$chan}{$what};
@@ -736,8 +756,9 @@ sub chanSet {
 
        $update++;
 
-    ### ".chanset blah testing"
     } elsif (defined $val) {
+       ### ".chanset blah testing"
+
        my $was = $chanconf{$chan}{$what};
        if (defined $was and $was eq $val) {
            &pSReply("setting $what for $chan already '$val'.");
@@ -750,9 +771,10 @@ sub chanSet {
 
        $update++;
 
-    ### ".chanset"
-    ### ".chanset blah"
     } else {                           # read only.
+       ### ".chanset"
+       ### ".chanset blah"
+
        if (!defined $what) {
            &WARN("chanset/DC: what == undefine.");
            return;
@@ -774,8 +796,8 @@ sub chanSet {
 }
 
 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.
+    # this is an attempt to fix where an option is enabled but the module
+    # has been not loaded. it also can be used for other things.
 
     foreach (keys %{ $cache{confvars} }) {
        my $i = $cache{confvars}{$_};
@@ -802,6 +824,7 @@ sub rehashConfVars {
     delete $cache{confvars};
 }
 
+# following arrays are not used... forgot what I intended to use them for.
 my @regFlagsChan = (
        "autojoin",
        "freshmeat",
@@ -813,9 +836,14 @@ my @regFlagsChan = (
 );
 
 my @regFlagsUser = (
-       "m",            # master
-       "n",            # owner
-       "o",            # op
+       "m",            # modify factoid.
+       "r",            # remove factoid.
+       "s",            # search (deprecated)
+       "t",            # teach/add factoid.
+       "a",            # ask/request factoid.
+       "n",            # bot owner
+       "o",            # master of bot (automatic +amrt)
+       "O",            # dynamic ops (as on channel). (automatic +o)
 );     # todo...
 
 1;