]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/UserDCC.pl
- strictify
[infobot.git] / src / Modules / UserDCC.pl
index 4be0e86646ac25f1d2416fac3410556c9d6d8955..49c10f0fa2073ab5ab490a6ad6aa51f26dd74b34 100644 (file)
@@ -5,7 +5,14 @@
 #     Created: 20000707 (from UserExtra.pl)
 #
 
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+
+use vars qw(%users %ignore %sched %bans %mask %cache %channels %param
+       %chanconf %dcc);
+use vars qw($who $chan $message $msgType $user $chnick $conn $ident
+       $verifyUser $ucount_userfile $utime_userfile $lobotomized
+       $utime_chanfile $ucount_chanfile);
+use vars qw(@backlog);
 
 sub userDCC {
     # hrm...
@@ -38,6 +45,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"));
@@ -103,6 +123,17 @@ sub userDCC {
        return;
     }
 
+    # dump variables ][.
+    if ($message =~ /^symdump$/i) {
+       return unless (&hasFlag("o"));
+       return unless (&IsParam("symdump"));
+
+       &status("Dumping all variables...");
+       &symdumpAllFile();
+
+       return;
+    }
+
     # kick.
     if ($message =~ /^kick(\s+(\S+)(\s+(\S+))?)?/) {
        return unless (&hasFlag("o"));
@@ -334,7 +365,7 @@ sub userDCC {
            return;
        }
 
-       ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
+       ### TODO: fix up $op to support mysql/sqlite/pgsql/dbm(perl)
        ### TODO: => add db/sql specific function to fix this.
        my @list = &searchTable("factoids", "factoid_key",
                        "factoid_value", $op);
@@ -405,7 +436,7 @@ sub userDCC {
        }
 
        &status("jumping servers... $server...");
-       &rawout("QUIT :jumping to $server");
+       $conn->quit("jumping to $server");
 
        if (&irc($server,$port) == 0) {
            &ircloop();
@@ -424,6 +455,33 @@ sub userDCC {
        return;
     }
 
+    # reset.
+    if ($message =~ /^reset$/i) {
+       return unless (&hasFlag("n"));
+
+       &msg($who,"resetting...");
+       my @done;
+       foreach ( keys %channels, keys %chanconf ) {
+           my $c = $_;
+           next if (grep /^\Q$c\E$/i, @done);
+
+           &part($_);
+
+           push(@done, $_);
+           sleep 1;
+       }
+       &DEBUG("before clearircvars");
+       &clearIRCVars();
+       &DEBUG("before joinnextchan");
+       &joinNextChan();
+       &DEBUG("after joinnextchan");
+
+       &status("USER reset $who");
+       &msg($who,"resetted");
+
+       return;
+    }
+
     # rehash.
     if ($message =~ /^rehash$/) {
        return unless (&hasFlag("n"));
@@ -530,6 +588,9 @@ sub userDCC {
            return;
        }
 
+       $cache{confvars}{$what} = $val;
+       &rehashConfVars();
+
        foreach (@chans) {
            &chanSet($cmd, $_, $what, $val);
        }
@@ -581,6 +642,8 @@ sub userDCC {
                    $chanconf{$_}{$args} = $val;
                }
                delete $chanconf{_default}{$args};
+               $cache{confvars}{$args} = 0;
+               &rehashConfVars();
 
                return;
            }
@@ -593,6 +656,8 @@ sub userDCC {
                    &DEBUG("delete chanconf{$_}{$args};");
                    delete $chanconf{$_}{$args};
                }
+               $cache{confvars}{$args} = 0;
+               &rehashConfVars();
 
                return;
            }
@@ -660,7 +725,7 @@ sub userDCC {
 
        if (scalar @args == 1) {        # del pass.
            if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
-               &pSReply("cannto remove passwd of others.");
+               &pSReply("cannot remove passwd of others.");
                return;
            }
 
@@ -697,6 +762,7 @@ sub userDCC {
            return;
        }
 
+       my $chflag;
        my $user;
        if ($args[0] =~ /^$mask{nick}$/i) {     # <nick>
            $user       = &getUser($args[0]);
@@ -845,7 +911,7 @@ sub userDCC {
            $user       = &getUser($args[0]);
            $mask       = $args[1];
        } else {                                # <mask>
-           # who or verifyUser. FIXME!!!
+           # who or verifyUser. FIXME (don't remember why)
            $user       = &getUser($who);
            $mask       = $args[0];
        }
@@ -941,7 +1007,7 @@ sub userDCC {
                &unban($mask, $_);
            }
 
-           if ($c) {
+           if (@c) {
                &pSReply("Removed $mask from chans: @c");
            } else {
                &pSReply("$mask was not found in ban list.");
@@ -1063,7 +1129,7 @@ sub userDCC {
     if ($message =~ /^banlist(\s+(.*))?$/) {
        my $arg = $2;
 
-       if (defined $arg and $arg !~ /^$mask_chan$/) {
+       if (defined $arg and $arg !~ /^$mask{chan}$/) {
            &pSReply("error: chan $chan is invalid.");
            return;
        }
@@ -1228,14 +1294,34 @@ sub userDCC {
        if ($state) {                   # adduser.
            if (scalar @args == 1) {
                $args[1]        = &getHostMask($args[0]);
-               if (!defined $args[1]) {
-                   &ERROR("could not get hostmask?");
-                   return;
-               }
+               &pSReply("Attemping to guess $args[0]'s hostmask...");
+
+               # crude hack... crappy Net::IRC
+               $conn->schedule(5, sub {
+       # hopefully this is right.
+       my $nick = (keys %{ $cache{nuhInfo} })[0];
+       if (!defined $nick) {
+           &pSReply("couldn't get nuhinfo... adding user without a hostmask.");
+           &userAdd($nick);
+           return;
+       }
+
+       my $mask = &makeHostMask( $cache{nuhInfo}{$nick}{NUH} );
+
+       if ( &userAdd($nick, $mask) ) { # success.
+               &pSReply("Added $nick with flags $users{$nick}{FLAGS}");
+               my @hosts = keys %{ $users{$nick}{HOSTS} };
+               &pSReply("hosts: @hosts");
+       }
+});
+               return;
            }
 
+           &DEBUG("args => @args");
            if ( &userAdd(@args) ) {    # success.
-               &pSReply("Added $args[0]...");
+               &pSReply("Added $args[0] with flags $users{$args[0]}{FLAGS}");
+               my @hosts = keys %{ $users{$args[0]}{HOSTS} };
+               &pSReply("hosts: @hosts");
 
            } else {                    # failure.
                &pSReply("User $args[0] already exists");
@@ -1282,6 +1368,19 @@ sub userDCC {
        return;
     }
 
+    # quite a cool hack: reply in DCC CHAT.
+    $msgType = "chat";
+
+    my $done = 0;
+    $done++ if &parseCmdHook("main", $message);
+    $done++ if &parseCmdHook("extra", $message);
+    $done++ unless (&Modules());
+
+    if ($done) {
+       &DEBUG("running non DCC CHAT command inside DCC CHAT!");
+       return;
+    }
+
     return "REPLY";
 }