]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/RootWarn.pl
1a3d6c6df8536da241856226e82ce52c6c003d06
[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 =~ /quiet/i) {
17             &status("rootwarn: Detected root user; notifying user");
18         } else {
19             &status("rootwarn: Detected root user; notifying nick and channel.");
20             rawout("PRIVMSG $chan :R".("O" x int(rand 70 + 2))."T has landed!");
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 # todo: support arguments to get info on a particular nick?
69 sub CmdrootWarn {
70     my $reply;
71     my $count = &countKeys("rootwarn");
72
73     if ($count == 0) {
74         &performReply("no-one has been warned about root, woohoo");
75         return;
76     }
77
78     # reply #1.
79     $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
80                 &fixPlural("rooter",$count) ." warned about root.";
81
82     if ($param{'DBType'} !~ /^mysql$/i) {
83         &FIXME("rootwarn does not yet support non-mysql.");
84         return;
85     }
86
87     # reply #2.
88     $found = 0;
89     my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
90     my $sth = $dbh->prepare($query);
91     $sth->execute;
92
93     while (my @row = $sth->fetchrow_array) {
94         $found++;
95     }
96
97     $sth->finish;
98
99     if ($found) {
100         $reply .= " Of which, \002$found\002 ".
101                 &fixPlural("rooter",$found)." ".
102                 &fixPlural("has",$found).
103                 " done it at least 3 times.";
104     }
105
106     &performStrictReply($reply);
107 }
108
109 1;