]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/RootWarn.pl
- bot stats: "blah has blah... is ranked xx/yy (zz percentile)"
[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 $n       = lc $nick;
13     my $attempt = &dbGet("rootwarn", "attempt", "nick=".&dbQuote($n) ) || 0;
14     my $warnmode        = &getChanConf("rootWarnMode");
15
16     if ($attempt == 0) {        # first timer.
17         if (defined $warnmode and $warnmode =~ /quiet/i) {
18             &status("rootwarn: Detected root user; notifying user");
19         } else {
20             &status("rootwarn: Detected root user; notifying nick and channel.");
21             rawout("PRIVMSG $chan :ROO".("O" x int(rand 68))."T has landed!");
22         }
23
24         if ($_ = &getFactoid("root")) {
25             &msg($nick, "root is $_");
26         } else {
27             &status("root needs to be defined in database.");
28         }
29
30     } elsif ($attempt < 2) {    # 2nd/3rd time occurrance.
31         &status("RootWarn: not first time root user; msg'ing $nick.");
32         if ($_ = &getFactoid("root again")) {
33             &msg($nick, $_);
34         } else {
35             &status("root again needs to be defined in database.");
36         }
37
38     } else {                    # >3rd time occurrance.
39
40         # disable this for the time being.
41         if (0 and $warnmode =~ /aggressive/i) {
42             if ($channels{$chan}{'o'}{$ident}) {
43                 &status("RootWarn: $nick... sigh... bye bye.");
44                 rawout("MODE $chan +b *!root\@$host");  # ban
45                 &kick($chan,$nick,"bye bye");
46             }
47         }
48     }
49
50     $attempt++;
51     ### TODO: OPTIMIZE THIS.
52     # ok... don't record the attempt if nick==root.
53     return if ($nick eq "root");
54
55     &dbSet("rootwarn", { nick => lc($nick) }, {
56         attempt => $attempt,
57         time    => time(),
58         host    => $user."\@".$host,
59         channel => $chan,
60     } );
61
62     return;
63 }
64
65 # Extras function.
66 # todo: support arguments to get info on a particular nick?
67 sub CmdrootWarn {
68     my $reply;
69     my $count = &countKeys("rootwarn");
70
71     if ($count == 0) {
72         &performReply("no-one has been warned about root, woohoo");
73         return;
74     }
75
76     # reply #1.
77     $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
78                 &fixPlural("rooter",$count) ." warned about root.";
79
80     if ($param{'DBType'} !~ /^(pg|my)sql$/i) {
81         &FIXME("rootwarn does not yet support non-{my,pg}sql.");
82         return;
83     }
84
85     # reply #2.
86     $found = 0;
87     my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
88     my $sth = $dbh->prepare($query);
89     $sth->execute;
90
91     while (my @row = $sth->fetchrow_array) {
92         $found++;
93     }
94
95     $sth->finish;
96
97     if ($found) {
98         $reply .= " Of which, \002$found\002 ".
99                 &fixPlural("rooter",$found)." ".
100                 &fixPlural("has",$found).
101                 " done it at least 3 times.";
102     }
103
104     &performStrictReply($reply);
105 }
106
107 1;