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", "nick", lc($nick), "attempt") || 0;
13 my $warnmode = &getChanConf("rootWarnMode");
15 if ($attempt == 0) { # first timer.
16 if ($warnmode =~ /aggressive/i) {
17 &status(">>> Detected root user; notifying nick and channel.");
18 rawout("PRIVMSG $chan :R".("O" x int(rand 80 + 2))."T has landed!");
20 &status(">>> 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.
38 if ($warnmode =~ /aggressive/i) {
39 if ($channels{$chan}{'o'}{$ident}) {
40 &status("RootWarn: $nick... sigh... bye bye.");
41 rawout("MODE $chan +b *!root\@$host"); # ban
42 &kick($chan,$nick,"bye bye");
48 ### TODO: OPTIMIZE THIS.
49 &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
50 &dbSet("rootwarn", "nick", lc($nick), "time", time());
51 &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
52 &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
60 my $count = &countKeys("rootwarn");
63 &performReply("no-one has been warned about root, woohoo");
68 $reply = "there ".&fixPlural("has",$count) ." been \002$i\002 ".
69 &fixPlural("rooter",$count) ." warned about root.";
71 if ($param{'DBType'} !~ /^mysql$/i) {
72 &FIXME("rootwarn does not yet support non-mysql.");
78 my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
79 my $sth = $dbh->prepare($query);
82 while (my @row = $sth->fetchrow_array) {
89 $reply .= " Of which, \002$found\002 ".
90 &fixPlural("rooter",$found)." ".
91 &fixPlural("has",$found).
92 " done it at least 3 times.";
95 &performStrictReply($reply);