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 rawout("PRIVMSG $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 if (1 and $nick ne "root") { # old
54 &dbSet("rootwarn", { nick => lc($nick) }, { attempt => $attempt });
55 &dbSet("rootwarn", { nick => lc($nick) }, { time => time() });
56 &dbSet("rootwarn", { nick => lc($nick) }, { host => $user."\@".$host });
57 &dbSet("rootwarn", { nick => lc($nick) }, { channel => $chan });
58 } else { # new. replace. TODO
59 &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
60 &dbSet("rootwarn", "nick", lc($nick), "time", time());
61 &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
62 &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
69 # todo: support arguments to get info on a particular nick?
72 my $count = &countKeys("rootwarn");
75 &performReply("no-one has been warned about root, woohoo");
80 $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
81 &fixPlural("rooter",$count) ." warned about root.";
83 if ($param{'DBType'} !~ /^mysql$/i) {
84 &FIXME("rootwarn does not yet support non-mysql.");
90 my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
91 my $sth = $dbh->prepare($query);
94 while (my @row = $sth->fetchrow_array) {
101 $reply .= " Of which, \002$found\002 ".
102 &fixPlural("rooter",$found)." ".
103 &fixPlural("has",$found).
104 " done it at least 3 times.";
107 &performStrictReply($reply);