X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FDynaConfig.pl;h=4c406589a5eb09afd7ac2d0b418053c338fee0fc;hb=b28802c40e8775f2a9457b833e2014ccc2f4161c;hp=b64ba0b24183f182d12ccd97d5dbc2426bfdd815;hpb=c53a047e7a5f63c954a2ce515687a937ca8720f3;p=infobot.git diff --git a/src/DynaConfig.pl b/src/DynaConfig.pl index b64ba0b..4c40658 100644 --- a/src/DynaConfig.pl +++ b/src/DynaConfig.pl @@ -6,14 +6,21 @@ # 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 ##### 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 +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 = ; if ($ver !~ /^#v1/) { @@ -63,7 +70,7 @@ sub readUserFile { } if (!defined $nick) { - &WARN("invalid line: $_"); + &WARN("DynaConfig: invalid line: $_"); next; } @@ -122,12 +129,12 @@ 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; } - 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..."); } } @@ -226,7 +233,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~"; @@ -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 () { 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}{$_}; @@ -297,12 +306,12 @@ 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; } - 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}; } +# registered flags... not used yet. my @regFlagsChan = ( "autojoin", "freshmeat", @@ -813,18 +836,14 @@ my @regFlagsChan = ( ); my @regFlagsUser = ( - "m", # master - "n", # owner - "o", # op -); # todo... + "m", # modify factoid. + "r", # remove factoid. + "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) + "A", # bot administration over /msg (def: DCC CHAT) +); 1; - -##### -# Userflags -# +r - ability to remove factoids -# +t - ability to teach factoids -# +m - ability to modify factoids -# +n - bot owner -# +o - authorised user of bot (like +m on eggdrop) -#####