2 # RootWarn.pl: Warn people about usage of root on IRC.
4 # Version: v0.3 (20000923)
11 my ($nick,$user,$host,$chan) = @_;
12 my $attempt = &dbGet("rootwarn", "attempt", "nick='".lc($nick)."'") || 0;
13 my $warnmode = &getChanConf("rootWarnMode");
15 if ($attempt == 0) { # first timer.
16 if (defined $warnmode and $warnmode =~ /aggressive/i) {
17 &status("rootwarn: Detected root user; notifying nick and channel.");
18 rawout("PRIVMSG $chan :R".("O" x int(rand 80 + 2))."T has landed!");
20 &status("rootwarn: Detected root user; notifying user");
23 if ($_ = &getFactoid("root")) {
24 &msg($nick, "root is $_");
26 &status("root needs to be defined in database.");
29 } elsif ($attempt < 2) { # 2nd/3rd time occurrance.
30 &status("RootWarn: not first time root user; msg'ing $nick.");
31 if ($_ = &getFactoid("root again")) {
34 &status("root again needs to be defined in database.");
37 } else { # >3rd time occurrance.
39 # disable this for the time being.
40 if (0 and $warnmode =~ /aggressive/i) {
41 if ($channels{$chan}{'o'}{$ident}) {
42 &status("RootWarn: $nick... sigh... bye bye.");
43 rawout("MODE $chan +b *!root\@$host"); # ban
44 &kick($chan,$nick,"bye bye");
50 ### TODO: OPTIMIZE THIS.
51 # ok... don't record the attempt if nick==root.
52 if (1 and $nick ne "root") { # old
53 &dbSet("rootwarn", { nick => lc($nick) }, { attempt => $attempt });
54 &dbSet("rootwarn", { nick => lc($nick) }, { time => time() });
55 &dbSet("rootwarn", { nick => lc($nick) }, { host => $user."\@".$host });
56 &dbSet("rootwarn", { nick => lc($nick) }, { channel => $chan });
57 } else { # new. replace. TODO
58 &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
59 &dbSet("rootwarn", "nick", lc($nick), "time", time());
60 &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
61 &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
70 my $count = &countKeys("rootwarn");
73 &performReply("no-one has been warned about root, woohoo");
78 $reply = "there ".&fixPlural("has",$count) ." been \002$i\002 ".
79 &fixPlural("rooter",$count) ." warned about root.";
81 if ($param{'DBType'} !~ /^mysql$/i) {
82 &FIXME("rootwarn does not yet support non-mysql.");
88 my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
89 my $sth = $dbh->prepare($query);
92 while (my @row = $sth->fetchrow_array) {
99 $reply .= " Of which, \002$found\002 ".
100 &fixPlural("rooter",$found)." ".
101 &fixPlural("has",$found).
102 " done it at least 3 times.";
105 &performStrictReply($reply);