]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/RootWarn.pl
changed email address
[infobot.git] / src / Modules / RootWarn.pl
1 #
2 # RootWarn.pl: Warn people about usage of root on IRC.
3 #      Author: dms
4 #     Version: v0.2c (19991125)
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         return "no-one has been warned about root, woohoo";
65     }
66
67     # reply #1.
68     $reply = "there ".&fixPlural("has",$count) ." been \002$i\002 ".
69                 &fixPlural("rooter",$count) ." warned about root.";
70
71     # reply #2.
72     $found = 0;
73     my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
74     my $sth = $dbh->prepare($query);
75     $sth->execute;
76
77     while (my @row = $sth->fetchrow_array) {
78         $found++;
79     }
80
81     $sth->finish;
82
83     if ($found) {
84         $reply .= " Of which, \002$found\002 ".
85                 &fixPlural("rooter",$found)." ".
86                 &fixPlural("has",$found).
87                 " done it at least 3 times.";
88     }
89
90     return $reply;
91 }
92
93 1;