]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/RootWarn.pl
- added support of ircTextCounters - works! thanks to #perl@OPN.
[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 ($warnmode =~ /aggressive/i) {
17             &status(">>> 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(">>> 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         if ($warnmode =~ /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     $attempt++;
48     ### TODO: OPTIMIZE THIS.
49     &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
50     &dbSet("rootwarn", "nick", lc($nick), "time", time());
51     &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
52     &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
53
54     return;
55 }
56
57 # Extras function.
58 sub CmdrootWarn {
59     my $reply;
60     my $count = &countKeys("rootwarn");
61
62     if ($count == 0) {
63         &performReply("no-one has been warned about root, woohoo");
64         return;
65     }
66
67     # reply #1.
68     $reply = "there ".&fixPlural("has",$count) ." been \002$i\002 ".
69                 &fixPlural("rooter",$count) ." warned about root.";
70
71     if ($param{'DBType'} !~ /^mysql$/i) {
72         &FIXME("rootwarn does not yet support non-mysql.");
73         return;
74     }
75
76     # reply #2.
77     $found = 0;
78     my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
79     my $sth = $dbh->prepare($query);
80     $sth->execute;
81
82     while (my @row = $sth->fetchrow_array) {
83         $found++;
84     }
85
86     $sth->finish;
87
88     if ($found) {
89         $reply .= " Of which, \002$found\002 ".
90                 &fixPlural("rooter",$found)." ".
91                 &fixPlural("has",$found).
92                 " done it at least 3 times.";
93     }
94
95     &performStrictReply($reply);
96 }
97
98 1;