]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/UserDCC.pl
more fixups.
[infobot.git] / src / Modules / UserDCC.pl
index d6df2fdfb9498ffbae3fed0cb89c8496e7d41395..894f0d4d9feb5139e77695cf8f4eedbcbe0b60f9 100644 (file)
@@ -414,9 +414,9 @@ sub userDCC {
        return unless (&hasFlag("n"));
 
        &status("USER reload $who");
-       &msg($who,"reloading...");
+       &pSReply("reloading...");
        &reloadAllModules();
-       &msg($who,"reloaded.");
+       &pSReply("reloaded.");
 
        return;
     }
@@ -461,21 +461,21 @@ sub userDCC {
 
     # +chan.
     if ($message =~ /^(chanset|\+chan)(\s+(.*?))?$/) {
-       my $cmd  = $1;
-       my $args = $3;
+       my $cmd         = $1;
+       my $args        = $3;
+       my $no_chan     = 0;
 
        if (!defined $args) {
            &help($cmd);
            return;
        }
 
-       my ($chan);
+       my $chan;
        if ($args =~ s/^($mask{chan})\s*//) {
            $chan       = $1;
-           &DEBUG("chan => $chan.");
        } else {
-           &DEBUG("no chan arg; setting to default.");
            $chan       = "_default";
+           $no_chan    = 1;
        }
 
        my($what,$val) = split /[\s\t]+/, $args, 2;
@@ -499,24 +499,44 @@ sub userDCC {
        }
 
        my $update      = 0;
-       if ($what =~ /^\+(\S+)/) {
+       if (defined $what and $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 $1 for $chan to '1'$was.");
+           &pSReply("Setting $what for $chan to '1'$was.");
 
-           $chanconf{$chan}{$1} = 1;
+           $chanconf{$chan}{$what} = 1;
 
            $update++;
-       } elsif ($what =~ /^\-(\S+)/) {
+       } elsif (defined $what and $what =~ s/^\-(\S+)/$1/) {
            my $was     = $chanconf{$chan}{$1};
+           # hrm...
+           if (!defined $was) {
+               &pSReply("setting $1 for $chan is not set.");
+               return;
+           }
+
+           if ($was eq "0") {
+               &pSReply("setting $1 for $chan already 0.");
+               return;
+           }
+
            $was        = ($was) ? "; was '$was'" : "";
-           &pSReply("Setting $1 for $chan to '0'$was.");
+           &pSReply("Setting $what for $chan to '0'$was.");
 
-           $chanconf{$chan}{$1} = 0;
+           $chanconf{$chan}{$what} = 0;
 
            $update++;
        } elsif (defined $val) {
            my $was     = $chanconf{$chan}{$what};
+           if (defined $was and $was eq $val) {
+               &pSReply("setting $1 for $chan already '$val'.");
+               return;
+           }
            $was        = ($was) ? "; was '$was'" : "";
            &pSReply("Setting $what for $chan to '$val'$was.");
 
@@ -524,7 +544,11 @@ sub userDCC {
 
            $update++;
        } elsif (defined $what) {
-           &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
+           if (exists $chanconf{$chan}{$what}) {
+               &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
+           } else {
+               &pSReply("$what for $chan is not set.'");
+           }
        }
 
        if ($update) {
@@ -536,8 +560,20 @@ sub userDCC {
        if ($cmd eq "chanset" and !defined $what) {
            &DEBUG("showing channel conf.");
 
-           foreach (keys %{ $chanconf{$chan} }) {
-               &DEBUG("$chan: $_ => $chanconf{$chan}{$_}");
+           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}{$_}");
+               }
            }
 
            return;
@@ -562,7 +598,7 @@ sub userDCC {
            $delete     = ($1) ? 1 : 0;
            &DEBUG("chan => $chan.");
        } else {
-           &DEBUG("no chan arg; setting to default.");
+           &VERB("no chan arg; setting to default.",2);
            $chan       = "_default";
        }
 
@@ -574,7 +610,7 @@ sub userDCC {
        if ($args ne "") {
            if (&getChanConf($args,$chan)) {
                &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
-               undef $chanconf{$chan}{$args};
+               delete $chanconf{$chan}{$args};
 
            } else {
                &pSReply("$args does not exist for $chan");
@@ -993,7 +1029,7 @@ sub userDCC {
        }
 
        my $c;
-       &pSReply("      expire, count, who-by, time-added, reason");
+       &pSReply("     mask: expire, time-added, count, who-by, reason");
        foreach $c (keys %bans) {
            next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
            &pSReply("  $c:");
@@ -1003,7 +1039,7 @@ sub userDCC {
 
                if (ref $val eq "ARRAY") {
                    my @array = @{ $val };
-                   &pSReply("      @array");
+                   &pSReply("    $_: @array");
                } else {
                    &DEBUG("unknown ban: $val");
                }
@@ -1084,7 +1120,6 @@ sub userDCC {
        # chan.
        if ($args =~ s/^($mask{chan}|\*)\s*//) {
            $chan = $1;
-           &DEBUG("chan => $chan");
        } else {
            $chan = "*";
        }
@@ -1092,7 +1127,6 @@ sub userDCC {
        # time.
        if ($args =~ s/^(\d+)\s*//) {
            $time = $1*60;      # ??
-           &DEBUG("time => $time");
        } else {
            $time = 0;
        }
@@ -1100,15 +1134,14 @@ sub userDCC {
        # time.
        if ($args) {
            $comment = $args;
-           &DEBUG("comment => $comment");
        } else {
            $comment = "added by $who";
        }
 
        if ( &ignoreAdd($mask, $chan, $time, $comment) > 1) {
-           &pSReply("added $mask to ignore list.");
-       } else {
            &pSReply("warn: $mask already in ignore list; written over anyway. FIXME");
+       } else {
+           &pSReply("added $mask to ignore list.");
        }
 
        return;
@@ -1138,7 +1171,7 @@ sub userDCC {
 
        ### TODO: proper (eggdrop-like) formatting.
        my $c;
-       &pSReply("    expire, count, who, added, comment");
+       &pSReply("    mask: expire, time-added, who, comment");
        foreach $c (keys %ignore) {
            next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
            &pSReply("  $c:");