]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/UserDCC.pl
global SAR. only avail to +n and DCC.
[infobot.git] / src / Modules / UserDCC.pl
1 #
2 #  UserDCC.pl: User Commands, DCC CHAT.
3 #      Author: dms
4 #     Version: v0.1 (20000707)
5 #     Created: 20000707 (from UserExtra.pl)
6 #
7
8 if (&IsParam("useStrict")) { use strict; }
9
10 sub userDCC {
11     # hrm...
12     $message =~ s/\s+$//;
13
14     ### for all users.
15     # quit.
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});
20
21         return $noreply;
22     }
23
24     # who.
25     if ($message =~ /^who$/i) {
26         my $count = scalar(keys %{$dcc{'CHAT'}});
27         &performStrictReply("Start of who ($count users).");
28         foreach (keys %{$dcc{'CHAT'}}) {
29             &performStrictReply("=> $_");
30         }
31         &performStrictReply("End of who.");
32
33         return $noreply;
34     }
35
36     ### for those users with enough flags.
37
38     # 4op.
39     if ($message =~ /^4op(\s+($mask{chan}))?$/i) {
40         return $noreply unless (&hasFlag("o"));
41
42         my $chan = $2;
43
44         if ($chan eq "") {
45             &help("4op");
46             return $noreply;
47         }
48
49         if (!$channels{$chan}{'o'}{$ident}) {
50             &msg($who, "i don't have ops on $chan to do that.");
51             return $noreply;
52         }
53
54         # on non-4mode(<4) servers, this may be exploited.
55         if ($channels{$chan}{'o'}{$who}) {
56             rawout("MODE $chan -o+o-o+o". (" $who" x 4));
57         } else {
58             rawout("MODE $chan +o-o+o-o". (" $who" x 4));
59         }
60
61         return $noreply;
62     }
63
64     # backlog.
65     if ($message =~ /^backlog(\s+(.*))?$/i) {
66         return $noreply unless (&hasFlag("o"));
67         return $noreply unless (&hasParam("backlog"));
68         my $num = $2;
69         my $max = $param{'backlog'};
70
71         if (!defined $num) {
72             &help("backlog");
73             return $noreply;
74         } elsif ($num !~ /^\d+/) {
75             &msg($who, "error: argument is not positive integer.");
76             return $noreply;
77         } elsif ($num > $max or $num < 0) {
78             &msg($who, "error: argument is out of range (max $max).");
79             return $noreply;
80         }
81
82         &msg($who, "Start of backlog...");
83         for (0..$num-1) {
84             sleep 1 if ($_ % 4 == 0 and $_ != 0);
85             $conn->privmsg($who, "[".($_+1)."]: $backlog[$max-$num+$_]");
86         }
87         &msg($who, "End of backlog.");
88
89         return $noreply;
90     }
91
92     # dump variables.
93     if ($message =~ /^dumpvars$/i) {
94         return $noreply unless (&hasFlag("o"));
95         return '' unless (&IsParam("dumpvars"));
96
97         &status("Dumping all variables...");
98         &dumpallvars();
99
100         return $noreply;
101     }
102
103     # kick.
104     if ($message =~ /^kick(\s+(\S+)(\s+(\S+))?)?/) {
105         return $noreply unless (&hasFlag("o"));
106         my ($nick,$chan) = (lc $2,lc $4);
107
108         if ($nick eq "") {
109             &help("kick");
110             return $noreply;
111         }
112
113         if (&validChan($chan) == 0) {
114             &msg($who,"error: invalid channel \002$chan\002");
115             return $noreply;
116         }
117
118         if (&IsNickInChan($nick,$chan) == 0) {
119             &msg($who,"$nick is not in $chan.");
120             return $noreply;
121         }
122
123         &kick($nick,$chan);
124
125         return $noreply;
126     }
127
128     # part.
129     if ($message =~ /^part(\s+(\S+))?$/i) {
130         return $noreply unless (&hasFlag("o"));
131         my $jchan = $2;
132
133         if ($jchan !~ /^$mask{chan}$/) {
134             &msg($who, "error, invalid chan.");
135             &help("part");
136             return $noreply;
137         }
138
139         if (!&validChan($jchan)) {
140             &msg($who, "error, I'm not on that chan.");
141             return $noreply;
142         }
143
144         &msg($jchan, "Leaving. (courtesy of $who).");
145         &part($jchan);
146         return $noreply;
147     }
148
149     # ignore.
150     if ($message =~ /^ignore(\s+(\S+))?$/i) {
151         return $noreply unless (&hasFlag("o"));
152         my $what = lc $2;
153
154         if ($what eq "") {
155             &help("ignore");
156             return $noreply;
157         }
158
159         my $expire = $param{'ignoreTempExpire'} || 60;
160         $ignoreList{$what} = time() + ($expire * 60);
161         &status("ignoring $what at $who's request");
162         &msg($who, "added $what to the ignore list");
163
164         return $noreply;
165     }
166
167     # unignore.
168     if ($message =~ /^unignore(\s+(\S+))?$/i) {
169         return $noreply unless (&hasFlag("o"));
170         my $what = $2;
171
172         if ($what eq "") {
173             &help("unignore");
174             return $noreply;
175         }
176
177         if ($ignoreList{$what}) {
178             &status("unignoring $what at $userHandle's request");
179             delete $ignoreList{$what};
180             &msg($who, "removed $what from the ignore list");
181         } else {
182             &status("unignore FAILED for $1 at $who's request");
183             &msg($who, "no entry for $1 on the ignore list");
184         }
185         return $noreply;
186     }
187
188     # clear unignore list.
189     if ($message =~ /^clear ignorelist$/i) {
190         return $noreply unless (&hasFlag("o"));
191         undef %ignoreList;
192         &status("unignoring all ($who said the word)");
193
194         return $noreply;
195     }
196
197     # lobotomy. sometimes we want the bot to be _QUIET_.
198     if ($message =~ /^(lobotomy|bequiet)$/i) {
199         return $noreply unless (&hasFlag("o"));
200
201         if ($lobotomized) {
202             &performReply("i'm already lobotomized");
203         } else {
204             &performReply("i have been lobotomized");
205             $lobotomized = 1;
206         }
207
208         return $noreply;
209     }
210
211     # unlobotomy.
212     if ($message =~ /^(unlobotomy|benoisy)$/i) {
213         return $noreply unless (&hasFlag("o"));
214         if ($lobotomized) {
215             &performReply("i have been unlobotomized, woohoo");
216             $lobotomized = 0;
217         } else {
218             &performReply("i'm not lobotomized");
219         }
220         return $noreply;
221     }
222
223     # op.
224     if ($message =~ /^op(\s+(.*))?$/i) {
225         return $noreply unless (&hasFlag("o"));
226         my ($opee) = lc $2;
227         my @chans;
228
229         if ($opee =~ / /) {
230             if ($opee =~ /^(\S+)\s+(\S+)$/) {
231                 $opee  = $1;
232                 @chans = ($2);
233                 if (!&validChan($2)) {
234                     &msg($who,"error: invalid chan ($2).");
235                     return $noreply;
236                 }
237             } else {
238                 &msg($who,"error: invalid params.");
239                 return $noreply;
240             }
241         } else {
242             @chans = keys %channels;
243         }
244
245         my $found = 0;
246         my $op = 0;
247         foreach (@chans) {
248             next unless (&IsNickInChan($opee,$_));
249             $found++;
250             if ($channels{$_}{'o'}{$opee}) {
251                 &status("op: $opee already has ops on $_");
252                 next;
253             }
254             $op++;
255
256             &status("opping $opee on $_ at ${who}'s request");
257             &performStrictReply("opping $opee on $_");
258             &op($_, $opee);
259         }
260
261         if ($found != $op) {
262             &status("op: opped on all possible channels.");
263         } else {
264             &DEBUG("found => '$found'.");
265             &DEBUG("op => '$op'.");
266         }
267
268         return $noreply;
269     }
270
271     # deop.
272     if ($message =~ /^deop(\s+(.*))?$/i) {
273         return $noreply unless (&hasFlag("o"));
274         my ($opee) = lc $2;
275         my @chans;
276
277         if ($opee =~ / /) {
278             if ($opee =~ /^(\S+)\s+(\S+)$/) {
279                 $opee  = $1;
280                 @chans = ($2);
281                 if (!&validChan($2)) {
282                     &msg($who,"error: invalid chan ($2).");
283                     return $noreply;
284                 }
285             } else {
286                 &msg($who,"error: invalid params.");
287                 return $noreply;
288             }
289         } else {
290             @chans = keys %channels;
291         }
292
293         my $found = 0;
294         my $op = 0;
295         foreach (@chans) {
296             next unless (&IsNickInChan($opee,$_));
297             $found++;
298             if (!exists $channels{$_}{'o'}{$opee}) {
299                 &status("deop: $opee already has no ops on $_");
300                 next;
301             }
302             $op++;
303
304             &status("deopping $opee on $_ at ${who}'s request");
305             &deop($_, $opee);
306         }
307
308         if ($found != $op) {
309             &status("deop: deopped on all possible channels.");
310         } else {
311             &DEBUG("deop: found => '$found'.");
312             &DEBUG("deop: op => '$op'.");
313         }
314
315         return $noreply;
316     }
317
318     # say.
319     if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
320         return $noreply unless (&hasFlag("o"));
321         my ($chan,$msg) = (lc $1, $2);
322         &DEBUG("chan => '$1', msg => '$msg'.");
323
324         if (&validChan($chan)) {
325             &msg($chan, $2);
326         } else {
327             &msg($who,"i'm not on \002$1\002, sorry.");
328         }
329         return $noreply;
330     }
331
332     # die.
333     if ($message =~ /^die$/) {
334         return $noreply unless (&hasFlag("n"));
335
336         &doExit();
337
338         status("Dying by $who\'s request");
339         exit 0;
340     }
341
342     # global factoid substitution.
343     if ($message =~ m|^s([/,#])(.+?)\2(.*?)\2;?\s*$|) {
344         &DEBUG("global factoid subst called!");
345         my ($delim,$op,$np) = ($1, $2, $3);
346         return $noreply unless (&hasFlag("n"));
347
348         # incorrect format.
349         if ($np =~ /$delim/) {
350             &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
351             return $noreply;
352         }
353
354         ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
355         ### TODO: => add db/sql specific function to fix this.
356         my @list = &searchTable("factoids", "factoid_key",
357                         "factoid_value", $op);
358
359         if (!scalar @list) {
360             &performStrictReply("Expression didn't match anything.");
361             return $noreply;
362         }
363
364         my $error = 0;
365         foreach (@list) {
366             my $faqtoid = $_;
367
368             next if (&IsLocked($faqtoid) == 1);
369             my $result = &getFactoid($faqtoid);
370             my $was = $result;
371             &DEBUG("was($faqtoid) => '$was'.");
372
373             # global global
374             # we could support global local (once off).
375             if ($result =~ s/\Q$op/$np/gi) {
376                 if (length $result > $param{'maxDataSize'}) {
377                     &performReply("that's too long (or was long)");
378                     return $noreply;
379                 }
380 ###             &setFactInfo($faqtoid, "factoid_value", $result);
381                 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
382             } else {
383                 &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
384                 $error++;
385             }
386         }
387
388         if ($error) {
389             &ERROR("Something happened...");
390         }
391
392         return $noreply;
393     }
394
395     # jump.
396     if ($message =~ /^jump(\s+(\S+))?$/i) {
397         return $noreply unless (&hasFlag("n"));
398
399         if ($2 eq "") {
400             &help("jump");
401             return $noreply;
402         }
403
404         my ($server,$port);
405         if ($2 =~ /^(\S+)(:(\d+))?$/) {
406             $server = $1;
407             $port   = $3 || 6667;
408         } else {
409             &msg($who,"invalid format.");
410             return $noreply;
411         }
412
413         &status("jumping servers... $server...");
414         &rawout("QUIT :jumping to $server");
415
416         if (&irc($server,$port) == 0) {
417             &ircloop();
418         }
419     }
420
421     # reload.
422     if ($message =~ /^reload$/i) {
423         return $noreply unless (&hasFlag("n"));
424
425         &status("USER reload $who");
426         &msg($who,"reloading...");
427         &reloadModules();
428         &msg($who,"reloaded.");
429
430         return $noreply;
431     }
432
433     # rehash.
434     if ($message =~ /^rehash$/) {
435         return $noreply unless (&hasFlag("n"));
436
437         &msg($who,"rehashing...");
438         &restart("REHASH");
439         &status("USER rehash $who");
440         &msg($who,"rehashed");
441
442         return $noreply;
443     }
444
445     # set.
446     if ($message =~ /^set(\s+(\S+)?(\s+(.*))?)?$/i) {
447         return $noreply unless (&hasFlag("n"));
448         my ($param,$what) = ($2,$4);
449
450         if ($param eq "" and $what eq "") {
451             &msg($who,"\002Usage\002: set <param> [what]");
452             return $noreply;
453         }
454
455         if (!exists $param{$param}) {
456             &msg($who,"error: param{$param} cannot be set");
457             return $noreply;
458         }
459
460         if ($what eq "") {
461             if ($param{$param} eq "") {
462                 &msg($who,"param{$param} has \002no value\002.");
463             } else {
464                 &msg($who,"param{$param} has value of '\002$param{$param}\002'.");
465             }
466             return $noreply;
467         }
468
469         if ($param{$param} eq $what) {
470             &msg($who,"param{$param} already has value of '\002$what\002'.");
471             return $noreply;
472         }
473
474         $param{$param} = $what;
475         &msg($who,"setting param{$param} to '\002$what\002'.");
476
477         return $noreply;
478     }
479
480     # unset.
481     if ($message =~ /^unset(\s+(\S+))?$/i) {
482         return $noreply unless (&hasFlag("n"));
483         my ($param) = $2;
484
485         if ($param eq "") {
486             &msg($who,"\002Usage\002: unset <param>");
487             return $noreply;
488         }
489
490         if (!exists $param{$param}) {
491             &msg($who,"error: \002$param\002 cannot be unset");
492             return $noreply;
493         }
494
495         if ($param{$param} == 0) {
496             &msg($who,"\002param{$param}\002 has already been unset.");
497             return $noreply;
498         }
499
500         $param{$param} = 0;
501         &msg($who,"unsetting \002param{$param}\002.");
502
503         return $noreply;
504     }
505
506     # more...
507 }
508
509 1;