]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/UserDCC.pl
closed 17554 -- re-add part/leave to DCC CHAT only
[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     # jump.
343     if ($message =~ /^jump(\s+(\S+))?$/i) {
344         return $noreply unless (&hasFlag("n"));
345
346         if ($2 eq "") {
347             &help("jump");
348             return $noreply;
349         }
350
351         my ($server,$port);
352         if ($2 =~ /^(\S+)(:(\d+))?$/) {
353             $server = $1;
354             $port   = $3 || 6667;
355         } else {
356             &msg($who,"invalid format.");
357             return $noreply;
358         }
359
360         &status("jumping servers... $server...");
361         &rawout("QUIT :jumping to $server");
362
363         if (&irc($server,$port) == 0) {
364             &ircloop();
365         }
366     }
367
368     # reload.
369     if ($message =~ /^reload$/i) {
370         return $noreply unless (&hasFlag("n"));
371
372         &status("USER reload $who");
373         &msg($who,"reloading...");
374         &reloadModules();
375         &msg($who,"reloaded.");
376
377         return $noreply;
378     }
379
380     # rehash.
381     if ($message =~ /^rehash$/) {
382         return $noreply unless (&hasFlag("n"));
383
384         &msg($who,"rehashing...");
385         &restart("REHASH");
386         &status("USER rehash $who");
387         &msg($who,"rehashed");
388
389         return $noreply;
390     }
391
392     # set.
393     if ($message =~ /^set(\s+(\S+)?(\s+(.*))?)?$/i) {
394         return $noreply unless (&hasFlag("n"));
395         my ($param,$what) = ($2,$4);
396
397         if ($param eq "" and $what eq "") {
398             &msg($who,"\002Usage\002: set <param> [what]");
399             return $noreply;
400         }
401
402         if (!exists $param{$param}) {
403             &msg($who,"error: param{$param} cannot be set");
404             return $noreply;
405         }
406
407         if ($what eq "") {
408             if ($param{$param} eq "") {
409                 &msg($who,"param{$param} has \002no value\002.");
410             } else {
411                 &msg($who,"param{$param} has value of '\002$param{$param}\002'.");
412             }
413             return $noreply;
414         }
415
416         if ($param{$param} eq $what) {
417             &msg($who,"param{$param} already has value of '\002$what\002'.");
418             return $noreply;
419         }
420
421         $param{$param} = $what;
422         &msg($who,"setting param{$param} to '\002$what\002'.");
423
424         return $noreply;
425     }
426
427     # unset.
428     if ($message =~ /^unset(\s+(\S+))?$/i) {
429         return $noreply unless (&hasFlag("n"));
430         my ($param) = $2;
431
432         if ($param eq "") {
433             &msg($who,"\002Usage\002: unset <param>");
434             return $noreply;
435         }
436
437         if (!exists $param{$param}) {
438             &msg($who,"error: \002$param\002 cannot be unset");
439             return $noreply;
440         }
441
442         if ($param{$param} == 0) {
443             &msg($who,"\002param{$param}\002 has already been unset.");
444             return $noreply;
445         }
446
447         $param{$param} = 0;
448         &msg($who,"unsetting \002param{$param}\002.");
449
450         return $noreply;
451     }
452
453     # more...
454 }
455
456 1;