]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/RootWarn.pl
non-mysql stub
[infobot.git] / src / Modules / RootWarn.pl
1 #
2 # RootWarn.pl: Warn people about usage of root on IRC.
3 #      Author: dms
4 #     Version: v0.3 (20000923)
5 #     Created: 19991008
6 #
7
8 use strict;
9
10 sub rootWarn {
11     my ($nick,$user,$host,$chan) = @_;
12     my $attempt = &dbGet("rootwarn", "nick", lc($nick), "attempt") || 0;
13
14     if ($attempt == 0) {        # first timer.
15         if (&IsParam("rootWarnMode") && $param{'rootWarnMode'} =~ /aggressive/i) {
16             &status(">>> Detected root user; notifying nick and channel.");
17             rawout("PRIVMSG $chan :R".("O" x int(rand 80 + 2))."T has landed!");
18         } else {
19             &status(">>> Detected root user; notifying user");
20         }
21
22         if ($_ = &getFactoid("root")) {
23             &msg($nick, "root is $_");
24         } else {
25             &status("root needs to be defined in database.");
26         }
27
28     } elsif ($attempt < 2) {    # 2nd/3rd time occurrance.
29         &status("RootWarn: not first time root user; msg'ing $nick.");
30         if ($_ = &getFactoid("root again")) {
31             &msg($nick, $_);
32         } else {
33             &status("root again needs to be defined in database.");
34         }
35
36     } else {                    # >3rd time occurrance.
37         if (&IsParam("rootWarnMode")) {
38             if ($param{'rootWarnMode'} =~ /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");
43                 }
44             }
45         }
46     }
47
48     $attempt++;
49     ### TODO: OPTIMIZE THIS.
50     &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
51     &dbSet("rootwarn", "nick", lc($nick), "time", time());
52     &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
53     &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
54
55     return;
56 }
57
58 # Extras function.
59 sub CmdrootWarn {
60     my $reply;
61     my $count = &countKeys("rootwarn");
62
63     if ($count == 0) {
64         &performReply("no-one has been warned about root, woohoo");
65         return;
66     }
67
68     # reply #1.
69     $reply = "there ".&fixPlural("has",$count) ." been \002$i\002 ".
70                 &fixPlural("rooter",$count) ." warned about root.";
71
72     if ($param{'DBType'} !~ /^mysql$/i) {
73         &FIXME("rootwarn does not yet support non-mysql.");
74         return;
75     }
76
77     # reply #2.
78     $found = 0;
79     my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
80     my $sth = $dbh->prepare($query);
81     $sth->execute;
82
83     while (my @row = $sth->fetchrow_array) {
84         $found++;
85     }
86
87     $sth->finish;
88
89     if ($found) {
90         $reply .= " Of which, \002$found\002 ".
91                 &fixPlural("rooter",$found)." ".
92                 &fixPlural("has",$found).
93                 " done it at least 3 times.";
94     }
95
96     &performStrictReply($reply);
97 }
98
99 1;