X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FDynaConfig.pl;h=94d608e838de3146d69824c5efb13a0b0c076c7d;hb=cb81fea9939f349b36e3b5a0cdc0343a6b781da1;hp=0e53f1187d41620cb31eabaf9253e3658062dbfa;hpb=da7fd06d82047c17f137afd1984d84dd480153ae;p=infobot.git diff --git a/src/DynaConfig.pl b/src/DynaConfig.pl index 0e53f11..94d608e 100644 --- a/src/DynaConfig.pl +++ b/src/DynaConfig.pl @@ -20,7 +20,7 @@ use vars qw($utime_userfile $ucount_userfile $utime_chanfile $who ##### sub readUserFile { - my $f = "$bot_state_dir/blootbot.users"; + my $f = "$bot_state_dir/infobot.users"; if (! -f $f) { &DEBUG("userfile not found; new fresh run detected."); @@ -64,7 +64,7 @@ sub readUserFile { if (/^--(\S+)[\s\t]+(.*)$/) { # user: middle entry. my ($what,$val) = ($1,$2); - if (!defined $val or $val eq "") { + if (!defined $val or $val eq '') { &WARN("$what: val == NULL."); next; } @@ -75,7 +75,7 @@ sub readUserFile { } # nice little hack. - if ($what eq "HOSTS") { + if ($what eq 'HOSTS') { $users{$nick}{$what}{$val} = 1; } else { $users{$nick}{$what} = $val; @@ -86,9 +86,9 @@ sub readUserFile { } elsif (/^::(\S+) ignore$/) { # ignore: start entry. $chan = $1; - $type = "ignore"; + $type = 'ignore'; - } elsif (/^- (\S+):\+(\d+):\+(\d+):(\S+):(.*)$/ and $type eq "ignore") { + } elsif (/^- (\S+):\+(\d+):\+(\d+):(\S+):(.*)$/ and $type eq 'ignore') { ### ignore: middle entry. my $mask = $1; my(@array) = ($2,$3,$4,$5); @@ -101,9 +101,9 @@ sub readUserFile { } elsif (/^::(\S+) bans$/) { # bans: start entry. $chan = $1; - $type = "bans"; + $type = 'bans'; - } elsif (/^- (\S+):\+(\d+):\+(\d+):(\d+):(\S+):(.*)$/ and $type eq "bans") { + } elsif (/^- (\S+):\+(\d+):\+(\d+):(\d+):(\S+):(.*)$/ and $type eq 'bans') { ### bans: middle entry. # $btime, $atime, $count, $whoby, $reason. my(@array) = ($2,$3,$4,$5,$6); @@ -129,14 +129,14 @@ sub writeUserFile { return; } - if (!open OUT,">$bot_state_dir/blootbot.users") { - &ERROR("Cannot write userfile ($bot_state_dir/blootbot.users): $!"); + if (!open OUT,">$bot_state_dir/infobot.users") { + &ERROR("Cannot write userfile ($bot_state_dir/infobot.users): $!"); return; } my $time = scalar(gmtime); - print OUT "#v1: blootbot -- $ident -- written $time\n\n"; + print OUT "#v1: infobot -- $ident -- written $time\n\n"; ### USER LIST. my $cusers = 0; @@ -155,11 +155,13 @@ sub writeUserFile { my $what = $_; my $val = $users{$user}{$_}; - if (ref($val) eq "HASH") { + if (ref($val) eq 'HASH') { foreach (sort keys %{ $users{$user}{$_} }) { print OUT "--$what\t\t$_\n"; } + } elsif ($_ eq 'FLAGS') { + print OUT "--$_\t\t" . join('', sort split('', $val)) . "\n"; } else { print OUT "--$_\t\t$val\n"; } @@ -224,7 +226,7 @@ sub writeUserFile { $wtime_userfile = time(); &status("--- Saved USERFILE ($cusers users; $cbans bans; $cignore ignore) at $time"); if (defined $msgType and $msgType =~ /^chat$/) { - &pSReply("--- Writing user file..."); + &performStrictReply("--- Writing user file..."); } } @@ -233,7 +235,7 @@ sub writeUserFile { ##### sub readChanFile { - my $f = "$bot_state_dir/blootbot.chan"; + my $f = "$bot_state_dir/infobot.chan"; if ( -f $f and -f "$f~") { my $s1 = -s $f; my $s2 = -s "$f~"; @@ -269,12 +271,10 @@ sub readChanFile { $chanconf{$chan}{$1} = 1; } elsif (/^[\s\t]+\-(\S+)$/) { # bool, false. - &DEBUG("deprecated support of negative options.") unless ($cache{negative}); # although this is supported in run-time configuration. - $cache{negative} = 1; -# $chanconf{$chan}{$1} = 0; + $chanconf{$chan}{$1} = 0; - } elsif (/^[\s\t]+(\S+)[\ss\t]+(.*)$/) {# what = val. + } elsif (/^[\s\t]+(\S+)[\s\t]+(.*)$/) {# what = val. $chanconf{$chan}{$1} = $2; } else { @@ -295,8 +295,6 @@ sub readChanFile { } } - delete $cache{negative}; - &status("CHANFILE: Loaded: ".(scalar(keys %chanconf)-1)." chans"); } @@ -306,13 +304,13 @@ sub writeChanFile { return; } - if (!open OUT,">$bot_state_dir/blootbot.chan") { - &ERROR("Cannot write chanfile ($bot_state_dir/blootbot.chan): $!"); + if (!open OUT,">$bot_state_dir/infobot.chan") { + &ERROR("Cannot write chanfile ($bot_state_dir/infobot.chan): $!"); return; } my $time = scalar(gmtime); - print OUT "#v1: blootbot -- $ident -- written $time\n\n"; + print OUT "#v1: infobot -- $ident -- written $time\n\n"; if ($flag_quit) { @@ -397,7 +395,7 @@ sub writeChanFile { " chans) at $time"); if (defined $msgType and $msgType =~ /^chat$/) { - &pSReply("--- Writing chan file..."); + &performStrictReply("--- Writing chan file..."); } } @@ -409,7 +407,7 @@ sub writeChanFile { # TODO: return all flags for opers sub IsFlag { my $flags = shift; - my ($ret, $f, $o) = ""; + my ($ret, $f, $o) = ''; &verifyUser($who, $nuh); @@ -434,7 +432,7 @@ sub verifyUser { return $userHandle; } - $userHandle = ""; + $userHandle = ''; foreach $user (keys %users) { next if ($user eq "_default"); @@ -455,7 +453,7 @@ sub verifyUser { last; } - last if ($userHandle ne ""); + last if ($userHandle ne ''); if ($user =~ /^\Q$nick\E$/i and !exists $cache{VUSERWARN}{$user}) { &status("vU: nick matched but host is not in list ($lnuh)."); @@ -474,10 +472,10 @@ sub verifyUser { sub ckpasswd { # returns true if arg1 encrypts to arg2 my ($plain, $encrypted) = @_; - if ($encrypted eq "") { + if ($encrypted eq '') { ($plain, $encrypted) = split(/\s+/, $plain, 2); } - return 0 unless ($plain ne "" and $encrypted ne ""); + return 0 unless ($plain ne '' and $encrypted ne ''); # MD5 // DES. Bobby Billingsley++. my $salt; @@ -501,7 +499,7 @@ sub hasFlag { return 1; } else { &status("DCC CHAT: <$who> $message -- not enough flags."); - &pSReply("error: you do not have enough flags for that. ($flag required)"); + &performStrictReply("error: you do not have enough flags for that. ($flag required)"); return 0; } } @@ -510,8 +508,8 @@ sub hasFlag { sub ignoreAdd { my($mask,$chan,$expire,$comment) = @_; - $chan ||= "*"; # global if undefined. - $comment ||= ""; # optional. + $chan ||= '*'; # global if undefined. + $comment ||= ''; # optional. $expire ||= 0; # permament. my $count ||= 0; @@ -605,7 +603,7 @@ sub userDel { sub banAdd { my($mask,$chan,$expire,$reason) = @_; - $chan ||= "*"; + $chan ||= '*'; $expire ||= 0; if ($expire > 0) { @@ -617,7 +615,7 @@ sub banAdd { exists $bans{'*'}{$mask}); $bans{$chan}{$mask} = [$expire, time(), 0, $who, $reason]; - my @chans = ($chan eq "*") ? keys %channels : $chan; + my @chans = ($chan eq '*') ? keys %channels : $chan; my $m = $mask; $m =~ s/\?/\\./g; $m =~ s/\*/\\S*/g; @@ -697,20 +695,20 @@ sub chanSet { if ($cmd eq "+chan") { if (exists $chanconf{$chan}) { - &pSReply("chan $chan already exists."); + &performStrictReply("chan $chan already exists."); return; } $chanconf{$chan}{_time_added} = time(); $chanconf{$chan}{autojoin} = $conn->nick(); - &pSReply("Joining $chan..."); + &performStrictReply("Joining $chan..."); &joinchan($chan); return; } if (!exists $chanconf{$chan}) { - &pSReply("no such channel $chan"); + &performStrictReply("no such channel $chan"); return; } @@ -720,12 +718,12 @@ sub chanSet { ### ".chanset +blah" ### ".chanset +blah 10" -- error. - my $state = ($1 eq "+") ? 1 : 0; + my $set = ($1 eq "+") ? 1 : 0; my $was = $chanconf{$chan}{$what}; - if ($state) { # add/set. - if (defined $was and $was eq "1") { - &pSReply("setting $what for $chan already 1."); + if ($set) { # add/set. + if (defined $was and $was eq '1') { + &performStrictReply("setting $what for $chan already 1."); return; } @@ -733,12 +731,7 @@ sub chanSet { } else { # delete/unset. if (!defined $was) { - &pSReply("setting $what for $chan is not set."); - return; - } - - if ($was eq "0") { - &pSReply("setting $what for $chan already 0."); + &performStrictReply("setting $what for $chan is not set."); return; } @@ -746,14 +739,16 @@ sub chanSet { } # alter for cosmetic (print out) reasons only. - $was = ($was) ? "; was '$was'" : ""; + $was = (defined $was) ? "; was '$was'" : ''; - if ($val eq "0") { - &pSReply("Unsetting $what for $chan$was."); + if ($val eq '0') { + &performStrictReply("Unsetting $what for $chan$was."); delete $chanconf{$chan}{$what}; + delete $cache{ircTextCounters} if $what eq 'ircTextCounters'; } else { - &pSReply("Setting $what for $chan to '$val'$was."); + &performStrictReply("Setting $what for $chan to '$val'$was."); $chanconf{$chan}{$what} = $val; + delete $cache{ircTextCounters} if $what eq 'ircTextCounters'; } $update++; @@ -763,13 +758,14 @@ sub chanSet { my $was = $chanconf{$chan}{$what}; if (defined $was and $was eq $val) { - &pSReply("setting $what for $chan already '$val'."); + &performStrictReply("setting $what for $chan already '$val'."); return; } - $was = ($was) ? "; was '$was'" : ""; - &pSReply("Setting $what for $chan to '$val'$was."); + $was = ($was) ? "; was '$was'" : ''; + &performStrictReply("Setting $what for $chan to '$val'$was."); $chanconf{$chan}{$what} = $val; + delete $cache{ircTextCounters} if $what eq 'ircTextCounters'; $update++; @@ -783,9 +779,9 @@ sub chanSet { } if (exists $chanconf{$chan}{$what}) { - &pSReply("$what for $chan is '$chanconf{$chan}{$what}'"); + &performStrictReply("$what for $chan is '$chanconf{$chan}{$what}'"); } else { - &pSReply("$what for $chan is not set."); + &performStrictReply("$what for $chan is not set."); } } @@ -819,6 +815,11 @@ sub rehashConfVars { &loadMyModule('RootWarn'); delete $cache{confvars}{$_}; } + + if (/^onjoin$/i and $i) { + &loadMyModule('OnJoin'); + delete $cache{confvars}{$_}; + } } &DEBUG("end of rehashConfVars"); @@ -826,31 +827,24 @@ sub rehashConfVars { delete $cache{confvars}; } -# registered flags... not used yet. -my @regFlagsChan = ( - "autojoin", - "limitcheckInterval", - "limitcheckPlus", - "allowConv", - "allowDNS", -### TODO: finish off this list. -); - my @regFlagsUser = ( - "m", # modify factoid. (includes renaming) - "r", # remove factoid. - "t", # teach/add factoid. - "a", # ask/request factoid. - "n", # bot owner - # can "reload" - "o", # master of bot (automatic +amrt) + # possible chars to include in FLAG + 'A', # bot administration over /msg + # default is only via DCC CHAT + 'O', # dynamic ops (as on channel). (automatic +o) + 'T', # add topics. + 'a', # ask/request factoid. + 'm', # modify factoid. (includes renaming) + 'n', # bot owner, can 'reload' + 'o', # master of bot (automatic +amrt) # can search on factoid strings shorter than 2 chars # can tell bot to join new channels # can [un]lock factoids - "O", # dynamic ops (as on channel). (automatic +o) - "A", # bot administration over /msg - # default is only via DCC CHAT - "T", # add topics. + 'r', # remove factoid. + 't', # teach/add factoid. + 's', # Bypass +silent on channels ); 1; + +# vim:ts=4:sw=4:expandtab:tw=80