2 # RootWarn.pl: Warn people about usage of root on IRC.
4 # Version: v0.3 (20000923)
10 use vars qw(%channels %param);
11 use vars qw($dbh $found $ident);
14 my ( $nick, $user, $host, $chan ) = @_;
16 my $attempt = &sqlSelect( 'rootwarn', 'attempt', { nick => $n } ) || 0;
17 my $warnmode = &getChanConf('rootWarnMode');
19 if ( $attempt == 0 ) { # first timer.
20 if ( defined $warnmode and $warnmode =~ /quiet/i ) {
21 &status('RootWarn: Detected root user; notifying user');
25 'RootWarn: Detected root user; notifying nick and channel.');
26 &msg( $chan, 'ROO' . ( 'O' x int( rand 8 ) ) . "T has landed!" );
29 if ( $_ = &getFactoid('root') ) {
30 &msg( $nick, "RootWarn: $attempt : $_" );
33 &status('"root" needs to be defined in database.');
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 : $_" );
43 &status('"root again" needs to be defined in database.');
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' );
56 elsif ( $_ = &getFactoid('root again') ) {
57 &status("RootWarn: $attempt times; msg'ing $nick.");
58 &msg( $nick, "RootWarn: $attempt : $_" );
61 &status("root again needs to be defined in database.");
66 ### TODO: OPTIMIZE THIS.
67 # ok... don't record the attempt if nick==root.
68 return if ( $nick eq 'root' );
72 { nick => lc($nick) },
76 host => $user . "\@" . $host,
85 # TODO: support arguments to get info on a particular nick?
88 my $count = &countKeys('rootwarn');
91 &performReply("no-one has been warned about root, woohoo");
97 . &fixPlural( 'has', $count )
98 . " been \002$count\002 "
99 . &fixPlural( 'rooter', $count )
100 . " warned about root.";
102 if ( $param{'DBType'} !~ /^(pg|my)sql$/i ) {
103 &FIXME("rootwarn does not yet support non-{my,pg}sql.");
109 my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
110 my $sth = $dbh->prepare($query);
113 while ( my @row = $sth->fetchrow_array ) {
121 " Of which, \002$found\002 "
122 . &fixPlural( 'rooter', $found ) . ' '
123 . &fixPlural( 'has', $found )
124 . " done it at least 3 times.";
127 &performStrictReply($reply);
132 # vim:ts=4:sw=4:expandtab:tw=80