]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/RootWarn.pl
root[wW]arn -> RootWarn
[infobot.git] / src / Modules / RootWarn.pl
index 1a3d6c6df8536da241856226e82ce52c6c003d06..fc3055069c750479a25a726ecca934a173d41bce 100644 (file)
@@ -5,70 +5,75 @@
 #     Created: 19991008
 #
 
-### use strict;
+use strict;
+
+use vars qw(%channels %param);
+use vars qw($dbh $found $ident);
 
 sub rootWarn {
     my ($nick,$user,$host,$chan) = @_;
-    my $attempt = &dbGet("rootwarn", "attempt", "nick='".lc($nick)."'") || 0;
-    my $warnmode       = &getChanConf("rootWarnMode");
+    my $n      = lc $nick;
+    my $attempt = &sqlSelect('rootwarn', 'attempt', { nick => $n } ) || 0;
+    my $warnmode       = &getChanConf('rootWarnMode');
 
     if ($attempt == 0) {       # first timer.
        if (defined $warnmode and $warnmode =~ /quiet/i) {
-           &status("rootwarn: Detected root user; notifying user");
+           &status('RootWarn: Detected root user; notifying user');
        } else {
-           &status("rootwarn: Detected root user; notifying nick and channel.");
-           rawout("PRIVMSG $chan :R".("O" x int(rand 70 + 2))."T has landed!");
+           &status('RootWarn: Detected root user; notifying nick and channel.');
+           &msg($chan, "ROO".("O" x int(rand 8))."T has landed!");
        }
 
-       if ($_ = &getFactoid("root")) {
-           &msg($nick, "root is $_");
+       if ($_ = &getFactoid('root')) {
+           &msg($nick, "RootWarn: $attempt : $_");
        } else {
-           &status("root needs to be defined in database.");
+           &status('"root" needs to be defined in database.');
        }
 
     } elsif ($attempt < 2) {   # 2nd/3rd time occurrance.
-       &status("RootWarn: not first time root user; msg'ing $nick.");
-       if ($_ = &getFactoid("root again")) {
-           &msg($nick, $_);
+       if ($_ = &getFactoid('root again')) {
+           &status("RootWarn: not first time root user; msg'ing $nick.");
+           &msg($nick, "RootWarn: $attempt : $_");
        } else {
-           &status("root again needs to be defined in database.");
+           &status('"root again" needs to be defined in database.');
        }
 
     } else {                   # >3rd time occurrance.
-
        # disable this for the time being.
        if (0 and $warnmode =~ /aggressive/i) {
            if ($channels{$chan}{'o'}{$ident}) {
                &status("RootWarn: $nick... sigh... bye bye.");
                rawout("MODE $chan +b *!root\@$host");  # ban
-               &kick($chan,$nick,"bye bye");
+               &kick($chan,$nick,'bye bye');
            }
+       } elsif ($_ = &getFactoid('root again')) {
+           &status("RootWarn: $attempt times; msg'ing $nick.");
+           &msg($nick, "RootWarn: $attempt : $_");
+       } else {
+           &status("root again needs to be defined in database.");
        }
     }
 
     $attempt++;
     ### TODO: OPTIMIZE THIS.
     # ok... don't record the attempt if nick==root.
-    if (1 and $nick ne "root") {       # old
-       &dbSet("rootwarn", { nick => lc($nick) }, { attempt => $attempt });
-       &dbSet("rootwarn", { nick => lc($nick) }, { time => time() });
-       &dbSet("rootwarn", { nick => lc($nick) }, { host => $user."\@".$host });
-       &dbSet("rootwarn", { nick => lc($nick) }, { channel => $chan });
-    } else {   # new. replace. TODO
-       &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
-       &dbSet("rootwarn", "nick", lc($nick), "time", time());
-       &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
-       &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
-    }
+    return if ($nick eq "root");
+
+    &sqlSet('rootwarn', { nick => lc($nick) }, {
+       attempt => $attempt,
+       time    => time(),
+       host    => $user."\@".$host,
+       channel => $chan,
+    } );
 
     return;
 }
 
 # Extras function.
-# todo: support arguments to get info on a particular nick?
+# TODO: support arguments to get info on a particular nick?
 sub CmdrootWarn {
     my $reply;
-    my $count = &countKeys("rootwarn");
+    my $count = &countKeys('rootwarn');
 
     if ($count == 0) {
        &performReply("no-one has been warned about root, woohoo");
@@ -79,8 +84,8 @@ sub CmdrootWarn {
     $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
                &fixPlural("rooter",$count) ." warned about root.";
 
-    if ($param{'DBType'} !~ /^mysql$/i) {
-       &FIXME("rootwarn does not yet support non-mysql.");
+    if ($param{'DBType'} !~ /^(pg|my)sql$/i) {
+       &FIXME("rootwarn does not yet support non-{my,pg}sql.");
        return;
     }