]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/RootWarn.pl
- irctextcounters: add percentage to top3
[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 $n       = lc $nick;
13     my $attempt = &dbGet("rootwarn", "attempt", "nick=".&dbQuote($n) ) || 0;
14     my $warnmode        = &getChanConf("rootWarnMode");
15
16     if ($attempt == 0) {        # first timer.
17         if (defined $warnmode and $warnmode =~ /quiet/i) {
18             &status("rootwarn: Detected root user; notifying user");
19         } else {
20             &status("rootwarn: Detected root user; notifying nick and channel.");
21             rawout("PRIVMSG $chan :ROO".("O" x int(rand 68))."T has landed!");
22         }
23
24         if ($_ = &getFactoid("root")) {
25             &msg($nick, "root is $_");
26         } else {
27             &status("root needs to be defined in database.");
28         }
29
30     } elsif ($attempt < 2) {    # 2nd/3rd time occurrance.
31         &status("RootWarn: not first time root user; msg'ing $nick.");
32         if ($_ = &getFactoid("root again")) {
33             &msg($nick, $_);
34         } else {
35             &status("root again needs to be defined in database.");
36         }
37
38     } else {                    # >3rd time occurrance.
39
40         # disable this for the time being.
41         if (0 and $warnmode =~ /aggressive/i) {
42             if ($channels{$chan}{'o'}{$ident}) {
43                 &status("RootWarn: $nick... sigh... bye bye.");
44                 rawout("MODE $chan +b *!root\@$host");  # ban
45                 &kick($chan,$nick,"bye bye");
46             }
47         }
48     }
49
50     $attempt++;
51     ### TODO: OPTIMIZE THIS.
52     # ok... don't record the attempt if nick==root.
53     if (1 and $nick ne "root") {        # old
54         &dbSet("rootwarn", { nick => lc($nick) }, { attempt => $attempt });
55         &dbSet("rootwarn", { nick => lc($nick) }, { time => time() });
56         &dbSet("rootwarn", { nick => lc($nick) }, { host => $user."\@".$host });
57         &dbSet("rootwarn", { nick => lc($nick) }, { channel => $chan });
58     } else {    # new. replace. TODO
59         &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
60         &dbSet("rootwarn", "nick", lc($nick), "time", time());
61         &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
62         &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
63     }
64
65     return;
66 }
67
68 # Extras function.
69 # todo: support arguments to get info on a particular nick?
70 sub CmdrootWarn {
71     my $reply;
72     my $count = &countKeys("rootwarn");
73
74     if ($count == 0) {
75         &performReply("no-one has been warned about root, woohoo");
76         return;
77     }
78
79     # reply #1.
80     $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
81                 &fixPlural("rooter",$count) ." warned about root.";
82
83     if ($param{'DBType'} !~ /^mysql$/i) {
84         &FIXME("rootwarn does not yet support non-mysql.");
85         return;
86     }
87
88     # reply #2.
89     $found = 0;
90     my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
91     my $sth = $dbh->prepare($query);
92     $sth->execute;
93
94     while (my @row = $sth->fetchrow_array) {
95         $found++;
96     }
97
98     $sth->finish;
99
100     if ($found) {
101         $reply .= " Of which, \002$found\002 ".
102                 &fixPlural("rooter",$found)." ".
103                 &fixPlural("has",$found).
104                 " done it at least 3 times.";
105     }
106
107     &performStrictReply($reply);
108 }
109
110 1;