]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/RootWarn.pl
- fixed dns lookup
[infobot.git] / src / Modules / RootWarn.pl
1 #
2 # RootWarn.pl: Warn people about usage of root on IRC.
3 #      Author: dms
4 #     Version: v0.3 (20000923)
5 #     Created: 19991008
6 #
7
8 ### use strict;
9
10 sub rootWarn {
11     my ($nick,$user,$host,$chan) = @_;
12     my $attempt = &dbGet("rootwarn", "attempt", "nick='".lc($nick)."'") || 0;
13     my $warnmode        = &getChanConf("rootWarnMode");
14
15     if ($attempt == 0) {        # first timer.
16         if (defined $warnmode and $warnmode =~ /aggressive/i) {
17             &status("rootwarn: Detected root user; notifying nick and channel.");
18             rawout("PRIVMSG $chan :R".("O" x int(rand 80 + 2))."T has landed!");
19         } else {
20             &status("rootwarn: Detected root user; notifying user");
21         }
22
23         if ($_ = &getFactoid("root")) {
24             &msg($nick, "root is $_");
25         } else {
26             &status("root needs to be defined in database.");
27         }
28
29     } elsif ($attempt < 2) {    # 2nd/3rd time occurrance.
30         &status("RootWarn: not first time root user; msg'ing $nick.");
31         if ($_ = &getFactoid("root again")) {
32             &msg($nick, $_);
33         } else {
34             &status("root again needs to be defined in database.");
35         }
36
37     } else {                    # >3rd time occurrance.
38         if ($warnmode =~ /aggressive/i) {
39             if ($channels{$chan}{'o'}{$ident}) {
40                 &status("RootWarn: $nick... sigh... bye bye.");
41                 rawout("MODE $chan +b *!root\@$host");  # ban
42                 &kick($chan,$nick,"bye bye");
43             }
44         }
45     }
46
47     $attempt++;
48     ### TODO: OPTIMIZE THIS.
49     if (1) {    # old
50         &dbSet("rootwarn", { nick => lc($nick) }, { attempt => $attempt });
51         &dbSet("rootwarn", { nick => lc($nick) }, { time => time() });
52         &dbSet("rootwarn", { nick => lc($nick) }, { host => $user."\@".$host });
53         &dbSet("rootwarn", { nick => lc($nick) }, { channel => $chan });
54     } else {    # new. replace.
55         &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
56         &dbSet("rootwarn", "nick", lc($nick), "time", time());
57         &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
58         &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
59     }
60
61     return;
62 }
63
64 # Extras function.
65 sub CmdrootWarn {
66     my $reply;
67     my $count = &countKeys("rootwarn");
68
69     if ($count == 0) {
70         &performReply("no-one has been warned about root, woohoo");
71         return;
72     }
73
74     # reply #1.
75     $reply = "there ".&fixPlural("has",$count) ." been \002$i\002 ".
76                 &fixPlural("rooter",$count) ." warned about root.";
77
78     if ($param{'DBType'} !~ /^mysql$/i) {
79         &FIXME("rootwarn does not yet support non-mysql.");
80         return;
81     }
82
83     # reply #2.
84     $found = 0;
85     my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
86     my $sth = $dbh->prepare($query);
87     $sth->execute;
88
89     while (my @row = $sth->fetchrow_array) {
90         $found++;
91     }
92
93     $sth->finish;
94
95     if ($found) {
96         $reply .= " Of which, \002$found\002 ".
97                 &fixPlural("rooter",$found)." ".
98                 &fixPlural("has",$found).
99                 " done it at least 3 times.";
100     }
101
102     &performStrictReply($reply);
103 }
104
105 1;