# 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.");
}
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/) {
}
if (!defined $nick) {
- &WARN("invalid line: $_");
+ &WARN("DynaConfig: invalid line: $_");
next;
}
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";
$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...");
}
}
#####
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~";
}
if (!open IN, $f) {
- &ERROR("cannot erad chanfile.");
+ &ERROR("Cannot read chanfile ($f): $!");
return;
}
while (<IN>) {
chop;
- next if /^$/;
+ next if /^\s*$/;
+ next if /^\// or /^\;/; # / or ; are comment lines.
if (/^(\S+)\s*$/) {
$chan = $1;
### 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}{$_};
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) {
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};
}
" chans) at $time");
if (defined $msgType and $msgType =~ /^chat$/) {
- &performStrictReply("--- Writing chan file...");
+ &pSReply("--- Writing chan file...");
}
}
##### USER COMMANDS.
#####
+# todo: support multiple flags.
sub IsFlag {
my $flags = shift;
my ($ret, $f, $o) = "";
sub verifyUser {
my ($nick, $lnuh) = @_;
- my ($user,$m);
+ my ($user, $m);
if ($userHandle = $dcc{'CHATvrfy'}{$who}) {
&VERB("vUser: cached auth for $who.",2);
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;
}
}
my $count ||= 0;
if ($expire > 0) {
- $expire = $expire*60 + time();
+ $expire = ($expire*60) + time();
} else {
$expire = 0;
}
$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++;
return;
}
$chanconf{$chan}{_time_added} = time();
- $chanconf{$what}{autojoin} = 1;
+ $chanconf{$chan}{autojoin} = 1;
&pSReply("Joining $chan...");
&joinchan($chan);
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};
return;
}
- $was = ($was) ? "; was '$was'" : "";
$val = 1;
} else { # delete/unset.
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};
$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'.");
$update++;
- ### ".chanset"
- ### ".chanset blah"
} else { # read only.
+ ### ".chanset"
+ ### ".chanset blah"
+
if (!defined $what) {
&WARN("chanset/DC: what == undefine.");
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.
+ # 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}{$_};
delete $cache{confvars};
}
+# following arrays are not used... forgot what I intended to use them for.
my @regFlagsChan = (
"autojoin",
"freshmeat",
);
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;