]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/UserDCC.pl
adduser/deluser
[infobot.git] / src / Modules / UserDCC.pl
index 195fdf846d0d0d548a2da50af88c3dd90b8b3674..3e108f0c0b9827ed87e75c7b9a73e7966dfe2929 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...
@@ -15,7 +22,7 @@ sub userDCC {
     # quit.
     if ($message =~ /^(exit|quit)$/i) {
        # do ircII clients support remote close? if so, cool!
-       &status("userDCC: quit called. FIXME");
+       &FIXME("userDCC: quit called.");
        &dcc_close($who);
        &status("userDCC: after dcc_close!");
 
@@ -108,7 +115,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();
@@ -116,15 +123,29 @@ sub userDCC {
        return;
     }
 
+    # dump variables ][.
+    if ($message =~ /^symdump$/i) {
+       return unless (&hasFlag('o'));
+       return unless (&IsParam('DumpVars2'));
+
+       &status("Dumping all variables...");
+       &symdumpAllFile();
+
+       return;
+    }
+
     # kick.
-    if ($message =~ /^kick(\s+(\S+)(\s+(\S+))?)?/) {
+    if ($message =~ /^kick(\s+(.*?))$/) {
        return unless (&hasFlag("o"));
-       my ($nick,$chan) = (lc $2,lc $4);
 
-       if ($nick eq "") {
+       my $arg = $2;
+
+       if ($arg eq "") {
            &help("kick");
            return;
        }
+       my @args = split(/\s+/, $arg);
+       my ($nick,$chan,$reason) = @args;
 
        if (&validChan($chan) == 0) {
            &msg($who,"error: invalid channel \002$chan\002");
@@ -136,12 +157,12 @@ sub userDCC {
            return;
        }
 
-       &kick($nick,$chan);
+       &kick($nick,$chan,$reason);
 
        return;
     }
 
-    # kick.
+    # mode.
     if ($message =~ /^mode(\s+(.*))?$/) {
        return unless (&hasFlag("n"));
        my ($chan,$mode) = split /\s+/,$2,2;
@@ -315,13 +336,33 @@ sub userDCC {
     if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
        return unless (&hasFlag("o"));
        my ($chan,$msg) = (lc $1, $2);
+
+       &DEBUG("chan => '$1', msg => '$msg'.");
+
+       # TODO: add nick destination.
+       if (&validChan($chan)) {
+           &msg($chan, $msg);
+       } else {
+           &msg($who,"i'm not on \002$chan\002, sorry.");
+       }
+
+       return;
+    }
+
+    # do.
+    if ($message =~ s/^do\s+(\S+)\s+(.*)//) {
+       return unless (&hasFlag("o"));
+       my ($chan,$msg) = (lc $1, $2);
+
        &DEBUG("chan => '$1', msg => '$msg'.");
 
+       # TODO: add nick destination.
        if (&validChan($chan)) {
-           &msg($chan, $2);
+           &action($chan, $msg);
        } else {
-           &msg($who,"i'm not on \002$1\002, sorry.");
+           &msg($who,"i'm not on \002$chan\002, sorry.");
        }
+
        return;
     }
 
@@ -347,7 +388,7 @@ sub userDCC {
            return;
        }
 
-       ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
+       ### TODO: fix up $op to support mysql/sqlite/pgsql
        ### TODO: => add db/sql specific function to fix this.
        my @list = &searchTable("factoids", "factoid_key",
                        "factoid_value", $op);
@@ -418,7 +459,7 @@ sub userDCC {
        }
 
        &status("jumping servers... $server...");
-       &rawout("QUIT :jumping to $server");
+       $conn->quit("jumping to $server");
 
        if (&irc($server,$port) == 0) {
            &ircloop();
@@ -444,10 +485,9 @@ sub userDCC {
        &msg($who,"resetting...");
        my @done;
        foreach ( keys %channels, keys %chanconf ) {
-           &DEBUG("reset: c => $c");
-           next if (grep /^\Q$_\E$/i, @done);
+           my $c = $_;
+           next if (grep /^\Q$c\E$/i, @done);
 
-           &DEBUG("reset: should part... c => $c");
            &part($_);
 
            push(@done, $_);
@@ -460,7 +500,7 @@ sub userDCC {
        &DEBUG("after joinnextchan");
 
        &status("USER reset $who");
-       &msg($who,"resetted");
+       &msg($who,"reset complete");
 
        return;
     }
@@ -516,7 +556,7 @@ sub userDCC {
 
        my @chans;
        while ($args =~ s/^($mask{chan})\s*//) {
-           push(@chans, $1);
+           push(@chans, lc($1));
        }
 
        if (!scalar @chans) {
@@ -535,12 +575,17 @@ sub userDCC {
 
            my %vals;
            foreach (keys %chanconf) {
-               my $val = $chanconf{$_}{$what} || "NOT-SET";
+               my $val;
+               if (defined $chanconf{$_}{$what}) {
+                   $val = $chanconf{$_}{$what};
+               } else {
+                   $val = "NOT-SET";
+               }
                $vals{$val}{$_} = 1;
            }
 
            foreach (keys %vals) {
-               &pSReply("  $what = $_: ".join(' ', keys %{ $vals{$_} } ) );
+               &pSReply("  $what = $_(" . scalar(keys %{$vals{$_}}) . "): ".join(' ', sort keys %{ $vals{$_} } ) );
            }
 
            &pSReply("End of list.");
@@ -552,21 +597,25 @@ sub userDCC {
        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.
+           foreach $chan (@chans) {
+               if ($chan eq '_default') {
+                   &pSReply("Default channel settings");
+               } else {
+                   &pSReply("chan: $chan (see _default also)");
+               }
                my @items;
                my $str = "";
                foreach (sort keys %{ $chanconf{$chan} }) {
                    my $newstr = join(', ', @items);
-                   if (length $newstr > 60) {
-                       &pSReply("    $str");
+                   ### TODO: make length use channel line limit?
+                   if (length $newstr > 370) {
+                       &pSReply(" $str");
                        @items = ();
                    }
                    $str = $newstr;
                    push(@items, "$_ => $chanconf{$chan}{$_}");
                }
-               &pSReply("    $str") if (@items);
+               &pSReply(" $str") if (@items);
            }
            return;
        }
@@ -596,7 +645,6 @@ sub userDCC {
        if ($args =~ s/^(\-)?($mask{chan})\s*//) {
            $chan       = $2;
            $delete     = ($1) ? 1 : 0;
-           &DEBUG("chan => $chan.");
        } else {
            &VERB("no chan arg; setting to default.",2);
            $chan       = "_default";
@@ -675,8 +723,8 @@ sub userDCC {
            return;
        }
 
-       my $u           = &getUser($who);
-       my $crypt       = &mkcrypt($args[0]);
+       my $u = &getUser($who);
+       my $crypt = &mkcrypt($args[0]);
 
        &pSReply("Set your passwd to '$crypt'");
        $users{$u}{PASS} = $crypt;
@@ -706,7 +754,8 @@ sub userDCC {
            return;
        }
 
-       if (scalar @args == 1) {        # del pass.
+       if (scalar @args == 1) {
+           # del pass.
            if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
                &pSReply("cannot remove passwd of others.");
                return;
@@ -745,11 +794,14 @@ sub userDCC {
            return;
        }
 
+       my $chflag;
        my $user;
-       if ($args[0] =~ /^$mask{nick}$/i) {     # <nick>
+       if ($args[0] =~ /^$mask{nick}$/i) {
+           # <nick>
            $user       = &getUser($args[0]);
            $chflag     = $args[1];
-       } else {                                # <flags>
+       } else {
+           # <flags>
            $user       = &getUser($who);
            &DEBUG("user $who... nope.") unless (defined $user);
            $user       = &getUser($verifyUser);
@@ -893,7 +945,7 @@ sub userDCC {
            $user       = &getUser($args[0]);
            $mask       = $args[1];
        } else {                                # <mask>
-           # who or verifyUser. FIXME!!!
+           # FIXME: who or verifyUser. (don't remember why)
            $user       = &getUser($who);
            $mask       = $args[0];
        }
@@ -904,9 +956,7 @@ sub userDCC {
        }
 
        if (!defined $mask) {
-           ### FIXME.
-           &pSReply("Hostmasks for $user: $users{$user}{HOSTS}");
-
+           &pSReply("Hostmasks for $user: " . join(" ", keys %{$users{$user}{HOSTS}}));
            return;
        }
 
@@ -915,14 +965,14 @@ sub userDCC {
            return;
        }
 
-       if ($mask !~ /^$mask{nuh}$/) {
-           &pSReply("error: mask ($mask) is not a real hostmask.");
-           return;
-       }
-
        my $count = scalar keys %{ $users{$user}{HOSTS} };
 
        if ($state) {                           # add.
+           if ($mask !~ /^$mask{nuh}$/) {
+               &pSReply("error: mask ($mask) is not a real hostmask.");
+               return;
+           }
+
            if (exists $users{$user}{HOSTS}{$mask}) {
                &pSReply("mask $mask already exists.");
                return;
@@ -989,7 +1039,7 @@ sub userDCC {
                &unban($mask, $_);
            }
 
-           if ($c) {
+           if (@c) {
                &pSReply("Removed $mask from chans: @c");
            } else {
                &pSReply("$mask was not found in ban list.");
@@ -1111,7 +1161,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;
        }
@@ -1132,7 +1182,7 @@ sub userDCC {
 
        &writeUserFile();
        &writeChanFile();
-       &News::writeNews() if (&ChanConfList("news"));
+       &pSReply("saved user and chan files");
 
        return;
     }
@@ -1165,7 +1215,7 @@ sub userDCC {
 
        if (!$state) {                  # delignore.
            if ( &ignoreDel($mask) ) {
-               &pSReply("ok, deleted X ignores.");
+               &pSReply("ok, deleted ignores for $mask.");
            } else {
                &pSReply("could not find $mask in ignore list.");
            }
@@ -1185,7 +1235,7 @@ sub userDCC {
 
        # time.
        if ($args =~ s/^(\d+)\s*//) {
-           $time = $1*60;      # ??
+           $time = $1; # time is in minutes
        } else {
            $time = 0;
        }
@@ -1198,7 +1248,7 @@ sub userDCC {
        }
 
        if ( &ignoreAdd($mask, $chan, $time, $comment) > 1) {
-           &pSReply("warn: $mask already in ignore list; written over anyway. FIXME");
+           &pSReply("FIXME: $mask already in ignore list; written over anyway.");
        } else {
            &pSReply("added $mask to ignore list.");
        }
@@ -1251,51 +1301,52 @@ sub userDCC {
     }
 
     # adduser/deluser.
-    if ($message =~ /^(\+|\-|add|del)user(\s+(.*))?$/i) {
+    if ($message =~ /^(add|del)user(\s+(.*))?$/i) {
        my $str         = $1;
        my $strstr      = $1."user";
        my @args        = split /\s+/, $3 || '';
        my $args        = $3;
-       my $state       = ($str =~ /^(\+|add)$/) ? 1 : 0;
+       my $state       = ($str =~ /^(add)$/) ? 1 : 0;
 
        if (!scalar @args) {
            &help($strstr);
            return;
        }
 
-       if ($str eq "+") {
+       if ($str eq 'add') {
            if (scalar @args != 2) {
-               &pSReply(".+host requires hostmask argument.");
+               &pSReply('adduser requires hostmask argument.');
                return;
            }
        } elsif (scalar @args != 1) {
-           &pSReply("too many arguments.");
+           &pSReply('too many arguments.');
            return;
        }
 
-       if ($state) {                   # adduser.
+       if ($state) {
+           # adduser.
            if (scalar @args == 1) {
                $args[1]        = &getHostMask($args[0]);
                &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} );
+                   # 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");
-       }
-});
+                   if ( &userAdd($nick, $mask) ) {
+                       # success.
+                       &pSReply("Added $nick with flags $users{$nick}{FLAGS}");
+                       my @hosts = keys %{ $users{$nick}{HOSTS} };
+                       &pSReply("hosts: @hosts");
+                   }
+               });
                return;
            }
 
@@ -1351,7 +1402,7 @@ sub userDCC {
     }
 
     # quite a cool hack: reply in DCC CHAT.
-    $msgType = "chat";
+    $msgType = "chat" if (exists $dcc{'CHAT'}{$who});
 
     my $done = 0;
     $done++ if &parseCmdHook("main", $message);