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 =~ /^mode(\s+(.*))?$/) {
136 return $noreply unless (&hasFlag("m"));
137 my ($chan,$mode) = split /\s+/,$2,2;
144 if (&validChan($chan) == 0) {
145 &msg($who,"error: invalid channel \002$chan\002");
149 if (!$channels{$chan}{o}{$ident}) {
150 &msg($who,"error: don't have ops on \002$chan\002");
160 if ($message =~ /^part(\s+(\S+))?$/i) {
161 return $noreply unless (&hasFlag("o"));
164 if ($jchan !~ /^$mask{chan}$/) {
165 &msg($who, "error, invalid chan.");
170 if (!&validChan($jchan)) {
171 &msg($who, "error, I'm not on that chan.");
175 &msg($jchan, "Leaving. (courtesy of $who).");
181 if ($message =~ /^ignore(\s+(\S+))?$/i) {
182 return $noreply unless (&hasFlag("o"));
190 my $expire = $param{'ignoreTempExpire'} || 60;
191 $ignoreList{$what} = time() + ($expire * 60);
192 &status("ignoring $what at $who's request");
193 &msg($who, "added $what to the ignore list");
199 if ($message =~ /^unignore(\s+(\S+))?$/i) {
200 return $noreply unless (&hasFlag("o"));
208 if ($ignoreList{$what}) {
209 &status("unignoring $what at $userHandle's request");
210 delete $ignoreList{$what};
211 &msg($who, "removed $what from the ignore list");
213 &status("unignore FAILED for $1 at $who's request");
214 &msg($who, "no entry for $1 on the ignore list");
219 # clear unignore list.
220 if ($message =~ /^clear ignorelist$/i) {
221 return $noreply unless (&hasFlag("o"));
223 &status("unignoring all ($who said the word)");
228 # lobotomy. sometimes we want the bot to be _QUIET_.
229 if ($message =~ /^(lobotomy|bequiet)$/i) {
230 return $noreply unless (&hasFlag("o"));
233 &performReply("i'm already lobotomized");
235 &performReply("i have been lobotomized");
243 if ($message =~ /^(unlobotomy|benoisy)$/i) {
244 return $noreply unless (&hasFlag("o"));
246 &performReply("i have been unlobotomized, woohoo");
249 &performReply("i'm not lobotomized");
255 if ($message =~ /^op(\s+(.*))?$/i) {
256 return $noreply unless (&hasFlag("o"));
261 if ($opee =~ /^(\S+)\s+(\S+)$/) {
264 if (!&validChan($2)) {
265 &msg($who,"error: invalid chan ($2).");
269 &msg($who,"error: invalid params.");
273 @chans = keys %channels;
279 next unless (&IsNickInChan($opee,$_));
281 if ($channels{$_}{'o'}{$opee}) {
282 &status("op: $opee already has ops on $_");
287 &status("opping $opee on $_ at ${who}'s request");
288 &performStrictReply("opping $opee on $_");
293 &status("op: opped on all possible channels.");
295 &DEBUG("found => '$found'.");
296 &DEBUG("op => '$op'.");
303 if ($message =~ /^deop(\s+(.*))?$/i) {
304 return $noreply unless (&hasFlag("o"));
309 if ($opee =~ /^(\S+)\s+(\S+)$/) {
312 if (!&validChan($2)) {
313 &msg($who,"error: invalid chan ($2).");
317 &msg($who,"error: invalid params.");
321 @chans = keys %channels;
327 next unless (&IsNickInChan($opee,$_));
329 if (!exists $channels{$_}{'o'}{$opee}) {
330 &status("deop: $opee already has no ops on $_");
335 &status("deopping $opee on $_ at ${who}'s request");
340 &status("deop: deopped on all possible channels.");
342 &DEBUG("deop: found => '$found'.");
343 &DEBUG("deop: op => '$op'.");
350 if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
351 return $noreply unless (&hasFlag("o"));
352 my ($chan,$msg) = (lc $1, $2);
353 &DEBUG("chan => '$1', msg => '$msg'.");
355 if (&validChan($chan)) {
358 &msg($who,"i'm not on \002$1\002, sorry.");
364 if ($message =~ /^die$/) {
365 return $noreply unless (&hasFlag("n"));
369 &status("Dying by $who\'s request");
373 # global factoid substitution.
374 if ($message =~ m|^s([/,#])(.+?)\1(.*?)\1;?\s*$|) {
375 my ($delim,$op,$np) = ($1, $2, $3);
376 return $noreply unless (&hasFlag("n"));
377 ### TODO: support flags to do full-on global.
380 if ($np =~ /$delim/) {
381 &performReply("looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
385 ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
386 ### TODO: => add db/sql specific function to fix this.
387 my @list = &searchTable("factoids", "factoid_key",
388 "factoid_value", $op);
391 &performReply("Expression didn't match anything.");
395 if (scalar @list > 100) {
396 &performReply("regex found more than 100 matches... not doing.");
400 &status("gsubst: going to alter ".scalar(@list)." factoids.");
401 &performReply("going to alter ".scalar(@list)." factoids.");
407 next if (&IsLocked($faqtoid) == 1);
408 my $result = &getFactoid($faqtoid);
410 &DEBUG("was($faqtoid) => '$was'.");
413 # we could support global local (once off).
414 if ($result =~ s/\Q$op/$np/gi) {
415 if (length $result > $param{'maxDataSize'}) {
416 &performReply("that's too long (or was long)");
419 &setFactInfo($faqtoid, "factoid_value", $result);
420 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
422 &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
428 &ERROR("Some warnings/errors?");
431 &performReply("Ok... did s/$op/$np/ for ".
432 (scalar(@list) - $error)." factoids");
438 if ($message =~ /^jump(\s+(\S+))?$/i) {
439 return $noreply unless (&hasFlag("n"));
447 if ($2 =~ /^(\S+)(:(\d+))?$/) {
451 &msg($who,"invalid format.");
455 &status("jumping servers... $server...");
456 &rawout("QUIT :jumping to $server");
458 if (&irc($server,$port) == 0) {
464 if ($message =~ /^reload$/i) {
465 return $noreply unless (&hasFlag("n"));
467 &status("USER reload $who");
468 &msg($who,"reloading...");
470 &msg($who,"reloaded.");
476 if ($message =~ /^rehash$/) {
477 return $noreply unless (&hasFlag("n"));
479 &msg($who,"rehashing...");
481 &status("USER rehash $who");
482 &msg($who,"rehashed");
488 if ($message =~ /^set(\s+(\S+)?(\s+(.*))?)?$/i) {
489 return $noreply unless (&hasFlag("n"));
490 my ($param,$what) = ($2,$4);
492 if ($param eq "" and $what eq "") {
493 &msg($who,"\002Usage\002: set <param> [what]");
497 if (!exists $param{$param}) {
498 &msg($who,"error: param{$param} cannot be set");
503 if ($param{$param} eq "") {
504 &msg($who,"param{$param} has \002no value\002.");
506 &msg($who,"param{$param} has value of '\002$param{$param}\002'.");
511 if ($param{$param} eq $what) {
512 &msg($who,"param{$param} already has value of '\002$what\002'.");
516 $param{$param} = $what;
517 &msg($who,"setting param{$param} to '\002$what\002'.");
523 if ($message =~ /^unset(\s+(\S+))?$/i) {
524 return $noreply unless (&hasFlag("n"));
528 &msg($who,"\002Usage\002: unset <param>");
532 if (!exists $param{$param}) {
533 &msg($who,"error: \002$param\002 cannot be unset");
537 if ($param{$param} == 0) {
538 &msg($who,"\002param{$param}\002 has already been unset.");
543 &msg($who,"unsetting \002param{$param}\002.");