]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/UserDCC.pl
- dbGet: warn if $select is NULL
[infobot.git] / src / Modules / UserDCC.pl
index 7fef535c21fd3969b0b54c0c804db4f3395103b5..09082a86ee22c116f6a64ddcdb6b5e2cdfc154ba 100644 (file)
@@ -17,18 +17,18 @@ 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;
     }
 
     # who.
     if ($message =~ /^who$/) {
-       my $count = scalar(keys %{$dcc{'CHAT'}});
+       my $count = scalar(keys %{ $dcc{'CHAT'} });
        my $dccCHAT = $message;
 
        &pSReply("Start of who ($count users).");
-       foreach (keys %{$dcc{'CHAT'}}) {
+       foreach (keys %{ $dcc{'CHAT'} }) {
            &pSReply("=> $_");
        }
        &pSReply("End of who.");
@@ -38,6 +38,19 @@ sub userDCC {
 
     ### for those users with enough flags.
 
+    if ($message =~ /^tellme(\s+(.*))?$/i) {
+       my $args = $2;
+       if ($args =~ /^\s*$/) {
+           &help("tellme");
+           return;
+       }
+
+       my $result = &doQuestion($args);
+       &pSReply($result);
+
+       return;
+    }
+
     # 4op.
     if ($message =~ /^4op(\s+($mask{chan}))?$/i) {
        return unless (&hasFlag("o"));
@@ -130,7 +143,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 +204,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 +245,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;
@@ -421,6 +437,29 @@ sub userDCC {
        return;
     }
 
+    # reset.
+    if ($message =~ /^reset$/i) {
+       return unless (&hasFlag("n"));
+
+       &msg($who,"resetting...");
+       my @done;
+       foreach ( keys %channels, keys %chanconf ) {
+           next if (grep /^\Q$_\E$/i, @done);
+
+           &part($_);
+
+           push(@done, $_);
+           sleep 1;
+       }
+       &clearIRCVars();
+       &joinNextChan();
+
+       &status("USER reset $who");
+       &msg($who,"resetted");
+
+       return;
+    }
+
     # rehash.
     if ($message =~ /^rehash$/) {
        return unless (&hasFlag("n"));
@@ -483,7 +522,7 @@ sub userDCC {
        my($what,$val) = split /[\s\t]+/, $args, 2;
 
        ### TODO: "cannot set values without +m".
-       return unless (&hasFlag("m"));
+       return unless (&hasFlag("n"));
 
        # READ ONLY.
        if (defined $what and $what !~ /^[-+]/ and !defined $val and $no_chan) {
@@ -504,6 +543,29 @@ sub userDCC {
            return;
        }
 
+       ### TODO: move to UserDCC again.
+       if ($cmd eq "chanset" and !defined $what) {
+           &DEBUG("showing channel conf.");
+
+           foreach $chan ($chan, "_default") {
+               &pSReply("chan: $chan");
+               ### TODO: merge 2 or 3 per line.
+               my @items;
+               my $str = "";
+               foreach (sort keys %{ $chanconf{$chan} }) {
+                   my $newstr = join(', ', @items);
+                   if (length $newstr > 60) {
+                       &pSReply("    $str");
+                       @items = ();
+                   }
+                   $str = $newstr;
+                   push(@items, "$_ => $chanconf{$chan}{$_}");
+               }
+               &pSReply("    $str") if (@items);
+           }
+           return;
+       }
+
        foreach (@chans) {
            &chanSet($cmd, $_, $what, $val);
        }
@@ -512,7 +574,7 @@ sub userDCC {
     }
 
     if ($message =~ /^(chanunset|\-chan)(\s+(.*))?$/) {
-       return unless (&hasFlag("m"));
+       return unless (&hasFlag("n"));
        my $args        = $3;
        my $no_chan     = 0;
 
@@ -593,6 +655,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 || '';
@@ -607,10 +688,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;
            }
@@ -630,8 +715,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;
 
@@ -661,7 +745,7 @@ sub userDCC {
        }
 
        if (!defined $user) {
-           &pSReply("user $user does not exist.");
+           &pSReply("user does not exist.");
            return;
        }
 
@@ -673,7 +757,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";
        }
@@ -756,7 +840,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;
@@ -793,7 +877,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>
@@ -814,7 +898,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;
        }
@@ -887,10 +971,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.");
            }
@@ -918,7 +1006,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;
        }
@@ -1032,6 +1120,7 @@ sub userDCC {
 
        &writeUserFile();
        &writeChanFile();
+       &News::writeNews() if (&ChanConfList("news"));
 
        return;
     }
@@ -1204,15 +1293,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;