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