]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/Modules/UserDCC.pl
Minor cleanup
[infobot.git] / blootbot / src / Modules / UserDCC.pl
index a69c9fe491a2159d3bbc4529207f927185fc5641..8112f49dbe9ae9da77c3aedbc93f20669393f992 100644 (file)
@@ -18,37 +18,43 @@ sub userDCC {
        &status("userDCC: quit called. FIXME");
 ###    $irc->removeconn($dcc{'CHAT'}{lc $who});
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # who.
-    if ($message =~ /^who$/i) {
+    if ($message =~ s/^who//i) {
        my $count = scalar(keys %{$dcc{'CHAT'}});
+       my $dccCHAT = $message;
+
        &performStrictReply("Start of who ($count users).");
        foreach (keys %{$dcc{'CHAT'}}) {
            &performStrictReply("=> $_");
        }
        &performStrictReply("End of who.");
 
-       return 'NOREPLY';
+       if ($message) { foreach (`$dccCHAT`) {
+           &performStrictReply("OUT: $_"); }
+       }
+
+       return $noreply;
     }
 
     ### for those users with enough flags.
 
     # 4op.
     if ($message =~ /^4op(\s+($mask{chan}))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
 
        my $chan = $2;
 
        if ($chan eq "") {
            &help("4op");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if (!$channels{$chan}{'o'}{$ident}) {
            &msg($who, "i don't have ops on $chan to do that.");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        # on non-4mode(<4) servers, this may be exploited.
@@ -58,25 +64,25 @@ sub userDCC {
            rawout("MODE $chan +o-o+o-o". (" $who" x 4));
        }
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # backlog.
     if ($message =~ /^backlog(\s+(.*))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
-       return 'NOREPLY' unless (&hasParam("backlog"));
+       return $noreply unless (&hasFlag("o"));
+       return $noreply unless (&hasParam("backlog"));
        my $num = $2;
        my $max = $param{'backlog'};
 
        if (!defined $num) {
            &help("backlog");
-           return 'NOREPLY';
+           return $noreply;
        } elsif ($num !~ /^\d+/) {
            &msg($who, "error: argument is not positive integer.");
-           return 'NOREPLY';
+           return $noreply;
        } elsif ($num > $max or $num < 0) {
            &msg($who, "error: argument is out of range (max $max).");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        &msg($who, "Start of backlog...");
@@ -86,53 +92,74 @@ sub userDCC {
        }
        &msg($who, "End of backlog.");
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # dump variables.
     if ($message =~ /^dumpvars$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        return '' unless (&IsParam("dumpvars"));
 
        &status("Dumping all variables...");
        &dumpallvars();
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # kick.
     if ($message =~ /^kick(\s+(\S+)(\s+(\S+))?)?/) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        my ($nick,$chan) = (lc $2,lc $4);
 
        if ($nick eq "") {
            &help("kick");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if (&validChan($chan) == 0) {
            &msg($who,"error: invalid channel \002$chan\002");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if (&IsNickInChan($nick,$chan) == 0) {
            &msg($who,"$nick is not in $chan.");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        &kick($nick,$chan);
 
-       return 'NOREPLY';
+       return $noreply;
+    }
+
+    # part.
+    if ($message =~ /^part(\s+(\S+))?$/i) {
+       return $noreply unless (&hasFlag("o"));
+       my $jchan = $2;
+
+       if ($jchan !~ /^$mask{chan}$/) {
+           &msg($who, "error, invalid chan.");
+           &help("part");
+           return $noreply;
+       }
+
+       if (!&validChan($jchan)) {
+           &msg($who, "error, I'm not on that chan.");
+           return $noreply;
+       }
+
+       &msg($jchan, "Leaving. (courtesy of $who).");
+       &part($jchan);
+       return $noreply;
     }
 
     # ignore.
     if ($message =~ /^ignore(\s+(\S+))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        my $what = lc $2;
 
        if ($what eq "") {
            &help("ignore");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        my $expire = $param{'ignoreTempExpire'} || 60;
@@ -140,17 +167,17 @@ sub userDCC {
        &status("ignoring $what at $who's request");
        &msg($who, "added $what to the ignore list");
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # unignore.
     if ($message =~ /^unignore(\s+(\S+))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        my $what = $2;
 
        if ($what eq "") {
            &help("unignore");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if ($ignoreList{$what}) {
@@ -161,21 +188,21 @@ sub userDCC {
            &status("unignore FAILED for $1 at $who's request");
            &msg($who, "no entry for $1 on the ignore list");
        }
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # clear unignore list.
     if ($message =~ /^clear ignorelist$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        undef %ignoreList;
        &status("unignoring all ($who said the word)");
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # lobotomy. sometimes we want the bot to be _QUIET_.
     if ($message =~ /^(lobotomy|bequiet)$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
 
        if ($lobotomized) {
            &performReply("i'm already lobotomized");
@@ -184,24 +211,24 @@ sub userDCC {
            $lobotomized = 1;
        }
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # unlobotomy.
     if ($message =~ /^(unlobotomy|benoisy)$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        if ($lobotomized) {
            &performReply("i have been unlobotomized, woohoo");
            $lobotomized = 0;
        } else {
            &performReply("i'm not lobotomized");
        }
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # op.
     if ($message =~ /^op(\s+(.*))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        my ($opee) = lc $2;
        my @chans;
 
@@ -211,11 +238,11 @@ sub userDCC {
                @chans = ($2);
                if (!&validChan($2)) {
                    &msg($who,"error: invalid chan ($2).");
-                   return 'NOREPLY';
+                   return $noreply;
                }
            } else {
                &msg($who,"error: invalid params.");
-               return 'NOREPLY';
+               return $noreply;
            }
        } else {
            @chans = keys %channels;
@@ -233,6 +260,7 @@ sub userDCC {
            $op++;
 
            &status("opping $opee on $_ at ${who}'s request");
+           &performStrictReply("opping $opee on $_");
            &op($_, $opee);
        }
 
@@ -243,12 +271,12 @@ sub userDCC {
            &DEBUG("op => '$op'.");
        }
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # deop.
     if ($message =~ /^deop(\s+(.*))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        my ($opee) = lc $2;
        my @chans;
 
@@ -258,11 +286,11 @@ sub userDCC {
                @chans = ($2);
                if (!&validChan($2)) {
                    &msg($who,"error: invalid chan ($2).");
-                   return 'NOREPLY';
+                   return $noreply;
                }
            } else {
                &msg($who,"error: invalid params.");
-               return 'NOREPLY';
+               return $noreply;
            }
        } else {
            @chans = keys %channels;
@@ -290,12 +318,12 @@ sub userDCC {
            &DEBUG("deop: op => '$op'.");
        }
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # say.
     if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
-       return 'NOREPLY' unless (&hasFlag("o"));
+       return $noreply unless (&hasFlag("o"));
        my ($chan,$msg) = (lc $1, $2);
        &DEBUG("chan => '$1', msg => '$msg'.");
 
@@ -304,26 +332,90 @@ sub userDCC {
        } else {
            &msg($who,"i'm not on \002$1\002, sorry.");
        }
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # die.
     if ($message =~ /^die$/) {
-       return 'NOREPLY' unless (&hasFlag("n"));
+       return $noreply unless (&hasFlag("n"));
 
        &doExit();
 
-       status("Dying by $who\'s request");
+       &status("Dying by $who\'s request");
        exit 0;
     }
 
+    # global factoid substitution.
+    if ($message =~ m|^s([/,#])(.+?)\1(.*?)\1;?\s*$|) {
+       my ($delim,$op,$np) = ($1, $2, $3);
+       return $noreply unless (&hasFlag("n"));
+       ### TODO: support flags to do full-on global.
+
+       # incorrect format.
+       if ($np =~ /$delim/) {
+           &performReply("looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
+           return $noreply;
+       }
+
+       ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
+       ### TODO: => add db/sql specific function to fix this.
+       my @list = &searchTable("factoids", "factoid_key",
+                       "factoid_value", $op);
+
+       if (!scalar @list) {
+           &performReply("Expression didn't match anything.");
+           return $noreply;
+       }
+
+       if (scalar @list > 100) {
+           &performReply("regex found more than 100 matches... not doing.");
+           return $noreply;
+       }
+
+       &status("gsubst: going to alter ".scalar(@list)." factoids.");
+       &performReply("going to alter ".scalar(@list)." factoids.");
+
+       my $error = 0;
+       foreach (@list) {
+           my $faqtoid = $_;
+
+           next if (&IsLocked($faqtoid) == 1);
+           my $result = &getFactoid($faqtoid);
+           my $was = $result;
+           &DEBUG("was($faqtoid) => '$was'.");
+
+           # global global
+           # we could support global local (once off).
+           if ($result =~ s/\Q$op/$np/gi) {
+               if (length $result > $param{'maxDataSize'}) {
+                   &performReply("that's too long (or was long)");
+                   return $noreply;
+               }
+               &setFactInfo($faqtoid, "factoid_value", $result);
+               &status("update: '$faqtoid' =is=> '$result'; was '$was'");
+           } else {
+               &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
+               $error++;
+           }
+       }
+
+       if ($error) {
+           &ERROR("Some warnings/errors?");
+       }
+
+       &performReply("Ok... did s/$op/$np/ for ".
+                               (scalar(@list) - $error)." factoids");
+
+       return $noreply;
+    }
+
     # jump.
     if ($message =~ /^jump(\s+(\S+))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("n"));
+       return $noreply unless (&hasFlag("n"));
 
        if ($2 eq "") {
            &help("jump");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        my ($server,$port);
@@ -332,7 +424,7 @@ sub userDCC {
            $port   = $3 || 6667;
        } else {
            &msg($who,"invalid format.");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        &status("jumping servers... $server...");
@@ -345,41 +437,41 @@ sub userDCC {
 
     # reload.
     if ($message =~ /^reload$/i) {
-       return 'NOREPLY' unless (&hasFlag("n"));
+       return $noreply unless (&hasFlag("n"));
 
        &status("USER reload $who");
        &msg($who,"reloading...");
-       &reloadModules();
+       &reloadAllModules();
        &msg($who,"reloaded.");
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # rehash.
     if ($message =~ /^rehash$/) {
-       return 'NOREPLY' unless (&hasFlag("n"));
+       return $noreply unless (&hasFlag("n"));
 
        &msg($who,"rehashing...");
        &restart("REHASH");
        &status("USER rehash $who");
        &msg($who,"rehashed");
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # set.
     if ($message =~ /^set(\s+(\S+)?(\s+(.*))?)?$/i) {
-       return 'NOREPLY' unless (&hasFlag("n"));
+       return $noreply unless (&hasFlag("n"));
        my ($param,$what) = ($2,$4);
 
        if ($param eq "" and $what eq "") {
            &msg($who,"\002Usage\002: set <param> [what]");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if (!exists $param{$param}) {
            &msg($who,"error: param{$param} cannot be set");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if ($what eq "") {
@@ -388,44 +480,44 @@ sub userDCC {
            } else {
                &msg($who,"param{$param} has value of '\002$param{$param}\002'.");
            }
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if ($param{$param} eq $what) {
            &msg($who,"param{$param} already has value of '\002$what\002'.");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        $param{$param} = $what;
        &msg($who,"setting param{$param} to '\002$what\002'.");
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # unset.
     if ($message =~ /^unset(\s+(\S+))?$/i) {
-       return 'NOREPLY' unless (&hasFlag("n"));
+       return $noreply unless (&hasFlag("n"));
        my ($param) = $2;
 
        if ($param eq "") {
            &msg($who,"\002Usage\002: unset <param>");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if (!exists $param{$param}) {
            &msg($who,"error: \002$param\002 cannot be unset");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        if ($param{$param} == 0) {
            &msg($who,"\002param{$param}\002 has already been unset.");
-           return 'NOREPLY';
+           return $noreply;
        }
 
        $param{$param} = 0;
        &msg($who,"unsetting \002param{$param}\002.");
 
-       return 'NOREPLY';
+       return $noreply;
     }
 
     # more...