]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/UserDCC.pl
changed email address
[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     # ignore.
129     if ($message =~ /^ignore(\s+(\S+))?$/i) {
130         return 'NOREPLY' unless (&hasFlag("o"));
131         my $what = lc $2;
132
133         if ($what eq "") {
134             &help("ignore");
135             return 'NOREPLY';
136         }
137
138         my $expire = $param{'ignoreTempExpire'} || 60;
139         $ignoreList{$what} = time() + ($expire * 60);
140         &status("ignoring $what at $who's request");
141         &msg($who, "added $what to the ignore list");
142
143         return 'NOREPLY';
144     }
145
146     # unignore.
147     if ($message =~ /^unignore(\s+(\S+))?$/i) {
148         return 'NOREPLY' unless (&hasFlag("o"));
149         my $what = $2;
150
151         if ($what eq "") {
152             &help("unignore");
153             return 'NOREPLY';
154         }
155
156         if ($ignoreList{$what}) {
157             &status("unignoring $what at $userHandle's request");
158             delete $ignoreList{$what};
159             &msg($who, "removed $what from the ignore list");
160         } else {
161             &status("unignore FAILED for $1 at $who's request");
162             &msg($who, "no entry for $1 on the ignore list");
163         }
164         return 'NOREPLY';
165     }
166
167     # clear unignore list.
168     if ($message =~ /^clear ignorelist$/i) {
169         return 'NOREPLY' unless (&hasFlag("o"));
170         undef %ignoreList;
171         &status("unignoring all ($who said the word)");
172
173         return 'NOREPLY';
174     }
175
176     # lobotomy. sometimes we want the bot to be _QUIET_.
177     if ($message =~ /^(lobotomy|bequiet)$/i) {
178         return 'NOREPLY' unless (&hasFlag("o"));
179
180         if ($lobotomized) {
181             &performReply("i'm already lobotomized");
182         } else {
183             &performReply("i have been lobotomized");
184             $lobotomized = 1;
185         }
186
187         return 'NOREPLY';
188     }
189
190     # unlobotomy.
191     if ($message =~ /^(unlobotomy|benoisy)$/i) {
192         return 'NOREPLY' unless (&hasFlag("o"));
193         if ($lobotomized) {
194             &performReply("i have been unlobotomized, woohoo");
195             $lobotomized = 0;
196         } else {
197             &performReply("i'm not lobotomized");
198         }
199         return 'NOREPLY';
200     }
201
202     # op.
203     if ($message =~ /^op(\s+(.*))?$/i) {
204         return 'NOREPLY' unless (&hasFlag("o"));
205         my ($opee) = lc $2;
206         my @chans;
207
208         if ($opee =~ / /) {
209             if ($opee =~ /^(\S+)\s+(\S+)$/) {
210                 $opee  = $1;
211                 @chans = ($2);
212                 if (!&validChan($2)) {
213                     &msg($who,"error: invalid chan ($2).");
214                     return 'NOREPLY';
215                 }
216             } else {
217                 &msg($who,"error: invalid params.");
218                 return 'NOREPLY';
219             }
220         } else {
221             @chans = keys %channels;
222         }
223
224         my $found = 0;
225         my $op = 0;
226         foreach (@chans) {
227             next unless (&IsNickInChan($opee,$_));
228             $found++;
229             if ($channels{$_}{'o'}{$opee}) {
230                 &status("op: $opee already has ops on $_");
231                 next;
232             }
233             $op++;
234
235             &status("opping $opee on $_ at ${who}'s request");
236             &op($_, $opee);
237         }
238
239         if ($found != $op) {
240             &status("op: opped on all possible channels.");
241         } else {
242             &DEBUG("found => '$found'.");
243             &DEBUG("op => '$op'.");
244         }
245
246         return 'NOREPLY';
247     }
248
249     # deop.
250     if ($message =~ /^deop(\s+(.*))?$/i) {
251         return 'NOREPLY' unless (&hasFlag("o"));
252         my ($opee) = lc $2;
253         my @chans;
254
255         if ($opee =~ / /) {
256             if ($opee =~ /^(\S+)\s+(\S+)$/) {
257                 $opee  = $1;
258                 @chans = ($2);
259                 if (!&validChan($2)) {
260                     &msg($who,"error: invalid chan ($2).");
261                     return 'NOREPLY';
262                 }
263             } else {
264                 &msg($who,"error: invalid params.");
265                 return 'NOREPLY';
266             }
267         } else {
268             @chans = keys %channels;
269         }
270
271         my $found = 0;
272         my $op = 0;
273         foreach (@chans) {
274             next unless (&IsNickInChan($opee,$_));
275             $found++;
276             if (!exists $channels{$_}{'o'}{$opee}) {
277                 &status("deop: $opee already has no ops on $_");
278                 next;
279             }
280             $op++;
281
282             &status("deopping $opee on $_ at ${who}'s request");
283             &deop($_, $opee);
284         }
285
286         if ($found != $op) {
287             &status("deop: deopped on all possible channels.");
288         } else {
289             &DEBUG("deop: found => '$found'.");
290             &DEBUG("deop: op => '$op'.");
291         }
292
293         return 'NOREPLY';
294     }
295
296     # say.
297     if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
298         return 'NOREPLY' unless (&hasFlag("o"));
299         my ($chan,$msg) = (lc $1, $2);
300         &DEBUG("chan => '$1', msg => '$msg'.");
301
302         if (&validChan($chan)) {
303             &msg($chan, $2);
304         } else {
305             &msg($who,"i'm not on \002$1\002, sorry.");
306         }
307         return 'NOREPLY';
308     }
309
310     # die.
311     if ($message =~ /^die$/) {
312         return 'NOREPLY' unless (&hasFlag("n"));
313
314         &doExit();
315
316         status("Dying by $who\'s request");
317         exit 0;
318     }
319
320     # jump.
321     if ($message =~ /^jump(\s+(\S+))?$/i) {
322         return 'NOREPLY' unless (&hasFlag("n"));
323
324         if ($2 eq "") {
325             &help("jump");
326             return 'NOREPLY';
327         }
328
329         my ($server,$port);
330         if ($2 =~ /^(\S+)(:(\d+))?$/) {
331             $server = $1;
332             $port   = $3 || 6667;
333         } else {
334             &msg($who,"invalid format.");
335             return 'NOREPLY';
336         }
337
338         &status("jumping servers... $server...");
339         &rawout("QUIT :jumping to $server");
340
341         if (&irc($server,$port) == 0) {
342             &ircloop();
343         }
344     }
345
346     # reload.
347     if ($message =~ /^reload$/i) {
348         return 'NOREPLY' unless (&hasFlag("n"));
349
350         &status("USER reload $who");
351         &msg($who,"reloading...");
352         &reloadModules();
353         &msg($who,"reloaded.");
354
355         return 'NOREPLY';
356     }
357
358     # rehash.
359     if ($message =~ /^rehash$/) {
360         return 'NOREPLY' unless (&hasFlag("n"));
361
362         &msg($who,"rehashing...");
363         &restart("REHASH");
364         &status("USER rehash $who");
365         &msg($who,"rehashed");
366
367         return 'NOREPLY';
368     }
369
370     # set.
371     if ($message =~ /^set(\s+(\S+)?(\s+(.*))?)?$/i) {
372         return 'NOREPLY' unless (&hasFlag("n"));
373         my ($param,$what) = ($2,$4);
374
375         if ($param eq "" and $what eq "") {
376             &msg($who,"\002Usage\002: set <param> [what]");
377             return 'NOREPLY';
378         }
379
380         if (!exists $param{$param}) {
381             &msg($who,"error: param{$param} cannot be set");
382             return 'NOREPLY';
383         }
384
385         if ($what eq "") {
386             if ($param{$param} eq "") {
387                 &msg($who,"param{$param} has \002no value\002.");
388             } else {
389                 &msg($who,"param{$param} has value of '\002$param{$param}\002'.");
390             }
391             return 'NOREPLY';
392         }
393
394         if ($param{$param} eq $what) {
395             &msg($who,"param{$param} already has value of '\002$what\002'.");
396             return 'NOREPLY';
397         }
398
399         $param{$param} = $what;
400         &msg($who,"setting param{$param} to '\002$what\002'.");
401
402         return 'NOREPLY';
403     }
404
405     # unset.
406     if ($message =~ /^unset(\s+(\S+))?$/i) {
407         return 'NOREPLY' unless (&hasFlag("n"));
408         my ($param) = $2;
409
410         if ($param eq "") {
411             &msg($who,"\002Usage\002: unset <param>");
412             return 'NOREPLY';
413         }
414
415         if (!exists $param{$param}) {
416             &msg($who,"error: \002$param\002 cannot be unset");
417             return 'NOREPLY';
418         }
419
420         if ($param{$param} == 0) {
421             &msg($who,"\002param{$param}\002 has already been unset.");
422             return 'NOREPLY';
423         }
424
425         $param{$param} = 0;
426         &msg($who,"unsetting \002param{$param}\002.");
427
428         return 'NOREPLY';
429     }
430
431     # more...
432 }
433
434 1;