]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/UserDCC.pl
news: added news->factoid redirection
[infobot.git] / src / Modules / UserDCC.pl
index f1918b042c9d19ff73b306442e8c40d798ade5ed..06fe68c8c4b5f723b39af826992c85fe561a2680 100644 (file)
@@ -17,7 +17,7 @@ sub userDCC {
        # do ircII clients support remote close? if so, cool!
        &status("userDCC: quit called. FIXME");
        &dcc_close($who);
-       &status("hrmm....");
+       &status("userDCC: after dcc_close!");
 
        return;
     }
@@ -95,7 +95,7 @@ sub userDCC {
     # dump variables.
     if ($message =~ /^dumpvars$/i) {
        return unless (&hasFlag("o"));
-       return '' unless (&IsParam("dumpvars"));
+       return unless (&IsParam("dumpvars"));
 
        &status("Dumping all variables...");
        &dumpallvars();
@@ -130,7 +130,7 @@ sub userDCC {
 
     # kick.
     if ($message =~ /^mode(\s+(.*))?$/) {
-       return unless (&hasFlag("m"));
+       return unless (&hasFlag("n"));
        my ($chan,$mode) = split /\s+/,$2,2;
 
        if ($chan eq "") {
@@ -191,12 +191,16 @@ sub userDCC {
     # unlobotomy.
     if ($message =~ /^(unlobotomy|benoisy)$/i) {
        return unless (&hasFlag("o"));
+
        if ($lobotomized) {
            &performReply("i have been unlobotomized, woohoo");
            $lobotomized = 0;
+           delete $cache{lobotomy};
+#          undef $cache{lobotomy};     # ??
        } else {
            &performReply("i'm not lobotomized");
        }
+
        return;
     }
 
@@ -228,21 +232,20 @@ sub userDCC {
            next unless (&IsNickInChan($opee,$_));
            $found++;
            if ($channels{$_}{'o'}{$opee}) {
-               &status("op: $opee already has ops on $_");
+               &pSReply("op: $opee already has ops on $_");
                next;
            }
            $op++;
 
-           &status("opping $opee on $_ at ${who}'s request");
            &pSReply("opping $opee on $_");
            &op($_, $opee);
        }
 
        if ($found != $op) {
-           &status("op: opped on all possible channels.");
+           &pSReply("op: opped on all possible channels.");
        } else {
-           &DEBUG("found => '$found'.");
-           &DEBUG("op => '$op'.");
+           &DEBUG("op: found => '$found'.");
+           &DEBUG("op:    op => '$op'.");
        }
 
        return;
@@ -470,101 +473,41 @@ sub userDCC {
            return;
        }
 
-       my $chan;
-       if ($args =~ s/^($mask{chan})\s*//) {
-           $chan       = $1;
-       } else {
-           $chan       = "_default";
+       my @chans;
+       while ($args =~ s/^($mask{chan})\s*//) {
+           push(@chans, $1);
+       }
+
+       if (!scalar @chans) {
+           push(@chans, "_default");
            $no_chan    = 1;
        }
 
        my($what,$val) = split /[\s\t]+/, $args, 2;
 
        ### TODO: "cannot set values without +m".
-       return unless (&hasFlag("m"));
-
-       if ($cmd eq "+chan") {
-           if (exists $chanconf{$chan}) {
-               &pSReply("chan $chan already exists.");
-               return;
-           }
-           $chanconf{$chan}{_time_added}       = time();
-           $chanconf{$what}{autojoin}          = 1;
-
-           &pSReply("Joining $chan...");
-           &joinchan($chan);
-
-           return;
-       }
-
-       if (!exists $chanconf{$chan}) {
-           &pSReply("no such channel $chan");
-           return;
-       }
-
-       my $update      = 0;
-### FIX THIS UP.
-    if (defined $what) {
-       if ($what =~ s/^\+(\S+)/$1/) {
-           my $was     = $chanconf{$chan}{$1};
-           if (defined $was and $was eq "1") {
-               &pSReply("setting $what for $chan already 1.");
-               return;
-           }
-
-           $was        = ($was) ? "; was '$was'" : "";
-           &pSReply("Setting $what for $chan to '1'$was.");
+       return unless (&hasFlag("n"));
 
-           $chanconf{$chan}{$what} = 1;
+       # READ ONLY.
+       if (defined $what and $what !~ /^[-+]/ and !defined $val and $no_chan) {
+           &pSReply("Showing $what values on all channels...");
 
-           $update++;
-       } elsif ($what =~ s/^\-(\S+)/$1/) {
-           my $was     = $chanconf{$chan}{$1};
-           # hrm...
-           if (!defined $was) {
-               &pSReply("setting $what for $chan is not set.");
-               return;
+           my %vals;
+           foreach (keys %chanconf) {
+               my $val = $chanconf{$_}{$what} || "NOT-SET";
+               $vals{$val}{$_} = 1;
            }
 
-           if ($was eq "0") {
-               &pSReply("setting $what for $chan already 0.");
-               return;
+           foreach (keys %vals) {
+               &pSReply("  $what = $_: ".join(' ', keys %{ $vals{$_} } ) );
            }
 
-           $was        = ($was) ? "; was '$was'" : "";
-           &pSReply("Setting $what for $chan to '0'$was.");
-
-           $chanconf{$chan}{$what} = 0;
+           &pSReply("End of list.");
 
-           $update++;
-       } elsif (defined $val) {
-           my $was     = $chanconf{$chan}{$what};
-           if (defined $was and $was eq $val) {
-               &pSReply("setting $what for $chan already '$val'.");
-               return;
-           }
-           $was        = ($was) ? "; was '$was'" : "";
-           &pSReply("Setting $what for $chan to '$val'$was.");
-
-           $chanconf{$chan}{$what} = $val;
-
-           $update++;
-       } else {
-           if (exists $chanconf{$chan}{$what}) {
-               &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
-           } else {
-               &pSReply("$what for $chan is not set.'");
-           }
-       }
-    }
-### END OF cheap insert of if statement.
-
-       if ($update) {
-           $utime_chanfile = time();
-           $ucount_chanfile++;
            return;
        }
 
+       ### TODO: move to UserDCC again.
        if ($cmd eq "chanset" and !defined $what) {
            &DEBUG("showing channel conf.");
 
@@ -582,19 +525,22 @@ sub userDCC {
                    $str = $newstr;
                    push(@items, "$_ => $chanconf{$chan}{$_}");
                }
-
                &pSReply("    $str") if (@items);
            }
-
            return;
        }
 
+       foreach (@chans) {
+           &chanSet($cmd, $_, $what, $val);
+       }
+
        return;
     }
 
     if ($message =~ /^(chanunset|\-chan)(\s+(.*))?$/) {
-       return unless (&hasFlag("m"));
+       return unless (&hasFlag("n"));
        my $args        = $3;
+       my $no_chan     = 0;
 
        if (!defined $args) {
            &help("chanunset");
@@ -610,6 +556,7 @@ sub userDCC {
        } else {
            &VERB("no chan arg; setting to default.",2);
            $chan       = "_default";
+           $no_chan    = 1;
        }
 
        if (!exists $chanconf{$chan}) {
@@ -618,14 +565,41 @@ sub userDCC {
        }
 
        if ($args ne "") {
-           if (&getChanConf($args,$chan)) {
-               &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
-               delete $chanconf{$chan}{$args};
 
-           } else {
+           if (!&getChanConf($args,$chan)) {
                &pSReply("$args does not exist for $chan");
+               return;
            }
 
+           my @chans = &ChanConfList($args);
+           &DEBUG("scalar chans => ".scalar(@chans) );
+           if (scalar @chans == 1 and $chans[0] eq "_default" and !$no_chan) {
+               &psReply("ok, $args was set only for _default; unsetting for _defaul but setting for other chans.");
+
+               my $val = $chanconf{$_}{_default};
+               foreach (keys %chanconf) {
+                   $chanconf{$_}{$args} = $val;
+               }
+               delete $chanconf{_default}{$args};
+
+               return;
+           }
+
+           if ($no_chan and !exists($chanconf{_default}{$args})) {
+               &pSReply("ok, $args for _default does not exist, removing from all chans.");
+
+               foreach (keys %chanconf) {
+                   next unless (exists $chanconf{$_}{$args});
+                   &DEBUG("delete chanconf{$_}{$args};");
+                   delete $chanconf{$_}{$args};
+               }
+
+               return;
+           }
+
+           &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
+           delete $chanconf{$chan}{$args};
+
            return;
        }
 
@@ -645,6 +619,25 @@ sub userDCC {
        return;
     }
 
+    if ($message =~ /^newpass(\s+(.*))?$/) {
+       my(@args) = split /[\s\t]+/, $2 || '';
+
+       if (scalar @args != 1) {
+           &help("newpass");
+           return;
+       }
+
+       my $u           = &getUser($who);
+       my $crypt       = &mkcrypt($args[0]);
+
+       &pSReply("Set your passwd to '$crypt'");
+       $users{$u}{PASS} = $crypt;
+
+       $utime_userfile = time();
+       $ucount_userfile++;
+
+       return;
+    }
 
     if ($message =~ /^chpass(\s+(.*))?$/) {
        my(@args) = split /[\s\t]+/, $2 || '';
@@ -659,10 +652,14 @@ sub userDCC {
            return;
        }
 
-       my $u = &getUser($who);
+       my $u = &getUser($args[0]);
+       if (!defined $u) {
+           &pSReply("Internal error, u = NULL.");
+           return;
+       }
 
        if (scalar @args == 1) {        # del pass.
-           if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
+           if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
                &pSReply("cannto remove passwd of others.");
                return;
            }
@@ -682,8 +679,7 @@ sub userDCC {
            return;
        }
 
-       my $salt = join '',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64];
-       my $crypt = crypt($args[1], $salt);
+       my $crypt       = &mkcrypt($args[1]);
        &pSReply("Set $u's passwd to '$crypt'");
        $users{$u}{PASS} = $crypt;
 
@@ -713,7 +709,7 @@ sub userDCC {
        }
 
        if (!defined $user) {
-           &pSReply("user $user does not exist.");
+           &pSReply("user does not exist.");
            return;
        }
 
@@ -725,7 +721,7 @@ sub userDCC {
 
        &DEBUG("who => $who");
        &DEBUG("verifyUser => $verifyUser");
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
            &pSReply("cannto change attributes of others.");
            return "REPLY";
        }
@@ -808,7 +804,7 @@ sub userDCC {
            return;
        }
 
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
            &pSReply("cannto change nick of others.");
            return "REPLY" if ($who eq "_default");
            return;
@@ -845,7 +841,7 @@ sub userDCC {
 
        my ($user,$mask);
        if ($args[0] =~ /^$mask{nick}$/i) {     # <nick>
-           return unless (&hasFlag("m"));
+           return unless (&hasFlag("n"));
            $user       = &getUser($args[0]);
            $mask       = $args[1];
        } else {                                # <mask>
@@ -866,7 +862,7 @@ sub userDCC {
            return;
        }
 
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
            &pSReply("cannto change masks of others.");
            return;
        }
@@ -939,10 +935,14 @@ sub userDCC {
        }
 
        if ($state == 0) {              # delete.
-           my $c = join(' ', &banDel($mask) );
+           my @c = &banDel($mask);
+
+           foreach (@c) {
+               &unban($mask, $_);
+           }
 
            if ($c) {
-               &pSReply("Removed $mask from chans: $c");
+               &pSReply("Removed $mask from chans: @c");
            } else {
                &pSReply("$mask was not found in ban list.");
            }
@@ -970,7 +970,7 @@ sub userDCC {
            $reason     = $1;
        }
 
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
            &pSReply("cannto change masks of others.");
            return;
        }
@@ -1084,6 +1084,7 @@ sub userDCC {
 
        &writeUserFile();
        &writeChanFile();
+       &News::writeNews() if (&ChanConfList("news"));
 
        return;
     }
@@ -1256,15 +1257,26 @@ sub userDCC {
     if ($message =~ /^sched$/) {
        my @list;
        my @run;
+
+       my %time;
        foreach (keys %sched) {
            next unless (exists $sched{$_}{TIME});
+           $time{ $sched{$_}{TIME}-time() }{$_} = 1;
            push(@list,$_);
 
            next unless (exists $sched{$_}{RUNNING});
            push(@run,$_);
        }
 
-       &pSReply( &formListReply(0,"Scheds to run: ", sort @list ) );
+       my @time;
+       foreach (sort { $a <=> $b } keys %time) {
+           my $str = join(", ", sort keys %{ $time{$_} });
+           &DEBUG("time => $_, str => $str");
+           push(@time, "$str (".&Time2String($_).")");
+       }
+
+       &pSReply( &formListReply(0, "Schedulers: ", @time ) );
+       &pSReply( &formListReply(0, "Scheds to run: ", sort @list ) );
        &pSReply( &formListReply(0, "Scheds running(should not happen?) ", sort @run ) );
 
        return;