]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/UserDCC.pl
send DCC message when using 'op'
[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             &performStrictReply("opping $opee on $_");
237             &op($_, $opee);
238         }
239
240         if ($found != $op) {
241             &status("op: opped on all possible channels.");
242         } else {
243             &DEBUG("found => '$found'.");
244             &DEBUG("op => '$op'.");
245         }
246
247         return $noreply;
248     }
249
250     # deop.
251     if ($message =~ /^deop(\s+(.*))?$/i) {
252         return $noreply unless (&hasFlag("o"));
253         my ($opee) = lc $2;
254         my @chans;
255
256         if ($opee =~ / /) {
257             if ($opee =~ /^(\S+)\s+(\S+)$/) {
258                 $opee  = $1;
259                 @chans = ($2);
260                 if (!&validChan($2)) {
261                     &msg($who,"error: invalid chan ($2).");
262                     return $noreply;
263                 }
264             } else {
265                 &msg($who,"error: invalid params.");
266                 return $noreply;
267             }
268         } else {
269             @chans = keys %channels;
270         }
271
272         my $found = 0;
273         my $op = 0;
274         foreach (@chans) {
275             next unless (&IsNickInChan($opee,$_));
276             $found++;
277             if (!exists $channels{$_}{'o'}{$opee}) {
278                 &status("deop: $opee already has no ops on $_");
279                 next;
280             }
281             $op++;
282
283             &status("deopping $opee on $_ at ${who}'s request");
284             &deop($_, $opee);
285         }
286
287         if ($found != $op) {
288             &status("deop: deopped on all possible channels.");
289         } else {
290             &DEBUG("deop: found => '$found'.");
291             &DEBUG("deop: op => '$op'.");
292         }
293
294         return $noreply;
295     }
296
297     # say.
298     if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
299         return $noreply unless (&hasFlag("o"));
300         my ($chan,$msg) = (lc $1, $2);
301         &DEBUG("chan => '$1', msg => '$msg'.");
302
303         if (&validChan($chan)) {
304             &msg($chan, $2);
305         } else {
306             &msg($who,"i'm not on \002$1\002, sorry.");
307         }
308         return $noreply;
309     }
310
311     # die.
312     if ($message =~ /^die$/) {
313         return $noreply unless (&hasFlag("n"));
314
315         &doExit();
316
317         status("Dying by $who\'s request");
318         exit 0;
319     }
320
321     # jump.
322     if ($message =~ /^jump(\s+(\S+))?$/i) {
323         return $noreply unless (&hasFlag("n"));
324
325         if ($2 eq "") {
326             &help("jump");
327             return $noreply;
328         }
329
330         my ($server,$port);
331         if ($2 =~ /^(\S+)(:(\d+))?$/) {
332             $server = $1;
333             $port   = $3 || 6667;
334         } else {
335             &msg($who,"invalid format.");
336             return $noreply;
337         }
338
339         &status("jumping servers... $server...");
340         &rawout("QUIT :jumping to $server");
341
342         if (&irc($server,$port) == 0) {
343             &ircloop();
344         }
345     }
346
347     # reload.
348     if ($message =~ /^reload$/i) {
349         return $noreply unless (&hasFlag("n"));
350
351         &status("USER reload $who");
352         &msg($who,"reloading...");
353         &reloadModules();
354         &msg($who,"reloaded.");
355
356         return $noreply;
357     }
358
359     # rehash.
360     if ($message =~ /^rehash$/) {
361         return $noreply unless (&hasFlag("n"));
362
363         &msg($who,"rehashing...");
364         &restart("REHASH");
365         &status("USER rehash $who");
366         &msg($who,"rehashed");
367
368         return $noreply;
369     }
370
371     # set.
372     if ($message =~ /^set(\s+(\S+)?(\s+(.*))?)?$/i) {
373         return $noreply unless (&hasFlag("n"));
374         my ($param,$what) = ($2,$4);
375
376         if ($param eq "" and $what eq "") {
377             &msg($who,"\002Usage\002: set <param> [what]");
378             return $noreply;
379         }
380
381         if (!exists $param{$param}) {
382             &msg($who,"error: param{$param} cannot be set");
383             return $noreply;
384         }
385
386         if ($what eq "") {
387             if ($param{$param} eq "") {
388                 &msg($who,"param{$param} has \002no value\002.");
389             } else {
390                 &msg($who,"param{$param} has value of '\002$param{$param}\002'.");
391             }
392             return $noreply;
393         }
394
395         if ($param{$param} eq $what) {
396             &msg($who,"param{$param} already has value of '\002$what\002'.");
397             return $noreply;
398         }
399
400         $param{$param} = $what;
401         &msg($who,"setting param{$param} to '\002$what\002'.");
402
403         return $noreply;
404     }
405
406     # unset.
407     if ($message =~ /^unset(\s+(\S+))?$/i) {
408         return $noreply unless (&hasFlag("n"));
409         my ($param) = $2;
410
411         if ($param eq "") {
412             &msg($who,"\002Usage\002: unset <param>");
413             return $noreply;
414         }
415
416         if (!exists $param{$param}) {
417             &msg($who,"error: \002$param\002 cannot be unset");
418             return $noreply;
419         }
420
421         if ($param{$param} == 0) {
422             &msg($who,"\002param{$param}\002 has already been unset.");
423             return $noreply;
424         }
425
426         $param{$param} = 0;
427         &msg($who,"unsetting \002param{$param}\002.");
428
429         return $noreply;
430     }
431
432     # more...
433 }
434
435 1;