2 # UserDCC.pl: User Commands, DCC CHAT.
4 # Version: v0.1 (20000707)
5 # Created: 20000707 (from UserExtra.pl)
8 if (&IsParam("useStrict")) { use strict; }
16 if ($message =~ /^(exit|quit)$/i) {
17 # do ircII clients support remote close? if so, cool!
18 &status("userDCC: quit called. FIXME");
19 ### $irc->removeconn($dcc{'CHAT'}{lc $who});
25 if ($message =~ s/^who//i) {
26 my $count = scalar(keys %{$dcc{'CHAT'}});
27 my $dccCHAT = $message;
29 &performStrictReply("Start of who ($count users).");
30 foreach (keys %{$dcc{'CHAT'}}) {
31 &performStrictReply("=> $_");
33 &performStrictReply("End of who.");
35 if ($message) { foreach (`$dccCHAT`) {
36 &performStrictReply("OUT: $_"); }
42 ### for those users with enough flags.
45 if ($message =~ /^4op(\s+($mask{chan}))?$/i) {
46 return $noreply unless (&hasFlag("o"));
55 if (!$channels{$chan}{'o'}{$ident}) {
56 &msg($who, "i don't have ops on $chan to do that.");
60 # on non-4mode(<4) servers, this may be exploited.
61 if ($channels{$chan}{'o'}{$who}) {
62 rawout("MODE $chan -o+o-o+o". (" $who" x 4));
64 rawout("MODE $chan +o-o+o-o". (" $who" x 4));
71 if ($message =~ /^backlog(\s+(.*))?$/i) {
72 return $noreply unless (&hasFlag("o"));
73 return $noreply unless (&hasParam("backlog"));
75 my $max = $param{'backlog'};
80 } elsif ($num !~ /^\d+/) {
81 &msg($who, "error: argument is not positive integer.");
83 } elsif ($num > $max or $num < 0) {
84 &msg($who, "error: argument is out of range (max $max).");
88 &msg($who, "Start of backlog...");
90 sleep 1 if ($_ % 4 == 0 and $_ != 0);
91 $conn->privmsg($who, "[".($_+1)."]: $backlog[$max-$num+$_]");
93 &msg($who, "End of backlog.");
99 if ($message =~ /^dumpvars$/i) {
100 return $noreply unless (&hasFlag("o"));
101 return '' unless (&IsParam("dumpvars"));
103 &status("Dumping all variables...");
110 if ($message =~ /^kick(\s+(\S+)(\s+(\S+))?)?/) {
111 return $noreply unless (&hasFlag("o"));
112 my ($nick,$chan) = (lc $2,lc $4);
119 if (&validChan($chan) == 0) {
120 &msg($who,"error: invalid channel \002$chan\002");
124 if (&IsNickInChan($nick,$chan) == 0) {
125 &msg($who,"$nick is not in $chan.");
135 if ($message =~ /^part(\s+(\S+))?$/i) {
136 return $noreply unless (&hasFlag("o"));
139 if ($jchan !~ /^$mask{chan}$/) {
140 &msg($who, "error, invalid chan.");
145 if (!&validChan($jchan)) {
146 &msg($who, "error, I'm not on that chan.");
150 &msg($jchan, "Leaving. (courtesy of $who).");
156 if ($message =~ /^ignore(\s+(\S+))?$/i) {
157 return $noreply unless (&hasFlag("o"));
165 my $expire = $param{'ignoreTempExpire'} || 60;
166 $ignoreList{$what} = time() + ($expire * 60);
167 &status("ignoring $what at $who's request");
168 &msg($who, "added $what to the ignore list");
174 if ($message =~ /^unignore(\s+(\S+))?$/i) {
175 return $noreply unless (&hasFlag("o"));
183 if ($ignoreList{$what}) {
184 &status("unignoring $what at $userHandle's request");
185 delete $ignoreList{$what};
186 &msg($who, "removed $what from the ignore list");
188 &status("unignore FAILED for $1 at $who's request");
189 &msg($who, "no entry for $1 on the ignore list");
194 # clear unignore list.
195 if ($message =~ /^clear ignorelist$/i) {
196 return $noreply unless (&hasFlag("o"));
198 &status("unignoring all ($who said the word)");
203 # lobotomy. sometimes we want the bot to be _QUIET_.
204 if ($message =~ /^(lobotomy|bequiet)$/i) {
205 return $noreply unless (&hasFlag("o"));
208 &performReply("i'm already lobotomized");
210 &performReply("i have been lobotomized");
218 if ($message =~ /^(unlobotomy|benoisy)$/i) {
219 return $noreply unless (&hasFlag("o"));
221 &performReply("i have been unlobotomized, woohoo");
224 &performReply("i'm not lobotomized");
230 if ($message =~ /^op(\s+(.*))?$/i) {
231 return $noreply unless (&hasFlag("o"));
236 if ($opee =~ /^(\S+)\s+(\S+)$/) {
239 if (!&validChan($2)) {
240 &msg($who,"error: invalid chan ($2).");
244 &msg($who,"error: invalid params.");
248 @chans = keys %channels;
254 next unless (&IsNickInChan($opee,$_));
256 if ($channels{$_}{'o'}{$opee}) {
257 &status("op: $opee already has ops on $_");
262 &status("opping $opee on $_ at ${who}'s request");
263 &performStrictReply("opping $opee on $_");
268 &status("op: opped on all possible channels.");
270 &DEBUG("found => '$found'.");
271 &DEBUG("op => '$op'.");
278 if ($message =~ /^deop(\s+(.*))?$/i) {
279 return $noreply unless (&hasFlag("o"));
284 if ($opee =~ /^(\S+)\s+(\S+)$/) {
287 if (!&validChan($2)) {
288 &msg($who,"error: invalid chan ($2).");
292 &msg($who,"error: invalid params.");
296 @chans = keys %channels;
302 next unless (&IsNickInChan($opee,$_));
304 if (!exists $channels{$_}{'o'}{$opee}) {
305 &status("deop: $opee already has no ops on $_");
310 &status("deopping $opee on $_ at ${who}'s request");
315 &status("deop: deopped on all possible channels.");
317 &DEBUG("deop: found => '$found'.");
318 &DEBUG("deop: op => '$op'.");
325 if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
326 return $noreply unless (&hasFlag("o"));
327 my ($chan,$msg) = (lc $1, $2);
328 &DEBUG("chan => '$1', msg => '$msg'.");
330 if (&validChan($chan)) {
333 &msg($who,"i'm not on \002$1\002, sorry.");
339 if ($message =~ /^die$/) {
340 return $noreply unless (&hasFlag("n"));
344 &status("Dying by $who\'s request");
348 # global factoid substitution.
349 if ($message =~ m|^s([/,#])(.+?)\1(.*?)\1;?\s*$|) {
350 my ($delim,$op,$np) = ($1, $2, $3);
351 return $noreply unless (&hasFlag("n"));
352 ### TODO: support flags to do full-on global.
355 if ($np =~ /$delim/) {
356 &performReply("looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
360 ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
361 ### TODO: => add db/sql specific function to fix this.
362 my @list = &searchTable("factoids", "factoid_key",
363 "factoid_value", $op);
366 &performReply("Expression didn't match anything.");
370 if (scalar @list > 100) {
371 &performReply("regex found more than 100 matches... not doing.");
375 &status("gsubst: going to alter ".scalar(@list)." factoids.");
376 &performReply("going to alter ".scalar(@list)." factoids.");
382 next if (&IsLocked($faqtoid) == 1);
383 my $result = &getFactoid($faqtoid);
385 &DEBUG("was($faqtoid) => '$was'.");
388 # we could support global local (once off).
389 if ($result =~ s/\Q$op/$np/gi) {
390 if (length $result > $param{'maxDataSize'}) {
391 &performReply("that's too long (or was long)");
394 &setFactInfo($faqtoid, "factoid_value", $result);
395 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
397 &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
403 &ERROR("Some warnings/errors?");
406 &performReply("Ok... did s/$op/$np/ for ".
407 (scalar(@list) - $error)." factoids");
413 if ($message =~ /^jump(\s+(\S+))?$/i) {
414 return $noreply unless (&hasFlag("n"));
422 if ($2 =~ /^(\S+)(:(\d+))?$/) {
426 &msg($who,"invalid format.");
430 &status("jumping servers... $server...");
431 &rawout("QUIT :jumping to $server");
433 if (&irc($server,$port) == 0) {
439 if ($message =~ /^reload$/i) {
440 return $noreply unless (&hasFlag("n"));
442 &status("USER reload $who");
443 &msg($who,"reloading...");
445 &msg($who,"reloaded.");
451 if ($message =~ /^rehash$/) {
452 return $noreply unless (&hasFlag("n"));
454 &msg($who,"rehashing...");
456 &status("USER rehash $who");
457 &msg($who,"rehashed");
463 if ($message =~ /^set(\s+(\S+)?(\s+(.*))?)?$/i) {
464 return $noreply unless (&hasFlag("n"));
465 my ($param,$what) = ($2,$4);
467 if ($param eq "" and $what eq "") {
468 &msg($who,"\002Usage\002: set <param> [what]");
472 if (!exists $param{$param}) {
473 &msg($who,"error: param{$param} cannot be set");
478 if ($param{$param} eq "") {
479 &msg($who,"param{$param} has \002no value\002.");
481 &msg($who,"param{$param} has value of '\002$param{$param}\002'.");
486 if ($param{$param} eq $what) {
487 &msg($who,"param{$param} already has value of '\002$what\002'.");
491 $param{$param} = $what;
492 &msg($who,"setting param{$param} to '\002$what\002'.");
498 if ($message =~ /^unset(\s+(\S+))?$/i) {
499 return $noreply unless (&hasFlag("n"));
503 &msg($who,"\002Usage\002: unset <param>");
507 if (!exists $param{$param}) {
508 &msg($who,"error: \002$param\002 cannot be unset");
512 if ($param{$param} == 0) {
513 &msg($who,"\002param{$param}\002 has already been unset.");
518 &msg($who,"unsetting \002param{$param}\002.");