2 # RootWarn.pl: Warn people about usage of root on IRC.
4 # Version: v0.3 (20000923)
11 my ($nick,$user,$host,$chan) = @_;
13 my $attempt = &dbGet("rootwarn", "attempt", "nick=".&dbQuote($n) ) || 0;
14 my $warnmode = &getChanConf("rootWarnMode");
16 if ($attempt == 0) { # first timer.
17 if (defined $warnmode and $warnmode =~ /quiet/i) {
18 &status("rootwarn: Detected root user; notifying user");
20 &status("rootwarn: Detected root user; notifying nick and channel.");
21 &msg($chan, "ROO".("O" x int(rand 68))."T has landed!");
24 if ($_ = &getFactoid("root")) {
25 &msg($nick, "root is $_");
27 &status("root needs to be defined in database.");
30 } elsif ($attempt < 2) { # 2nd/3rd time occurrance.
31 &status("RootWarn: not first time root user; msg'ing $nick.");
32 if ($_ = &getFactoid("root again")) {
35 &status("root again needs to be defined in database.");
38 } else { # >3rd time occurrance.
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");
51 ### TODO: OPTIMIZE THIS.
52 # ok... don't record the attempt if nick==root.
53 return if ($nick eq "root");
55 &dbSet("rootwarn", { nick => lc($nick) }, {
58 host => $user."\@".$host,
66 # todo: support arguments to get info on a particular nick?
69 my $count = &countKeys("rootwarn");
72 &performReply("no-one has been warned about root, woohoo");
77 $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
78 &fixPlural("rooter",$count) ." warned about root.";
80 if ($param{'DBType'} !~ /^(pg|my)sql$/i) {
81 &FIXME("rootwarn does not yet support non-{my,pg}sql.");
87 my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
88 my $sth = $dbh->prepare($query);
91 while (my @row = $sth->fetchrow_array) {
98 $reply .= " Of which, \002$found\002 ".
99 &fixPlural("rooter",$found)." ".
100 &fixPlural("has",$found).
101 " done it at least 3 times.";
104 &performStrictReply($reply);