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