]> ruin.nu Git - NDIRC.git/blob - Delling.pm
Added the Delling specific code
[NDIRC.git] / Delling.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19 package NDIRC::Delling;
20
21 use strict;
22 use warnings;
23 use feature ':5.10';
24
25 use POE::Session;
26 use NDIRC::Misc;
27 use ND::DB;
28
29 sub irc_public {
30         my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
31         my ($nick,$username,$address) = ( split /[!@]/, $who );
32         my $channel = $where->[0];
33
34         my $irc = $sender->get_heap();
35
36         #$irc->yield(privmsg => $channel, "Authed? " . $irc->is_nick_authed($nick));
37         my $dbh = DB();
38         my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
39         $seen->execute($address);
40
41         if ($msg =~ /^(\S+): (.+)$/ && $heap->{disp}->has_command('anon',$channel)){
42                 my $_ = $1;
43                 my $text = $2;
44                 unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
45                         $msg = ".anon $_ $text";
46                 }
47
48         }
49         if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},$dbh)){
50                 #Command parsed and run successfully
51         }
52 }
53
54
55 sub irc_msg {
56         my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
57         my ($nick,$username,$address) = ( split /[!@]/, $who );
58         my $irc = $sender->get_heap();
59
60         my $dbh = DB();
61         my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
62         $seen->execute($address);
63
64         if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},$dbh)){
65                 #Command parsed and run successfully
66         }else{
67                 $irc->yield(notice => $nick, "unknown command");
68         }
69 }
70
71 sub irc_join {
72         my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
73         my ($nick,$username,$address) = ( split /[!@]/, $who );
74         my $irc = $sender->get_heap();
75
76         my $dbh = DB();
77         my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
78         $seen->execute($address);
79
80         if($heap->{disp}->has_command('voice',$channel)){
81                 my $flags = $dbh->prepare_cached(q{
82 SELECT DISTINCT flag
83 FROM users u
84         JOIN groupmembers g USING (uid)
85         JOIN channel_group_flags gf USING (gid)
86 WHERE u.hostmask = $1 AND channel = $2 AND flag IN ('o','v');
87                 });
88                 $flags->execute($address, $channel);
89                 my $mode = '';
90                 my @who;
91                 while (my ($flag) = $flags->fetchrow()){
92                         $mode .= $flag;
93                         push @who, $nick;
94                 }
95                 say "$mode - @who";
96                 $irc->yield(mode => $channel, $mode, @who) if $mode;
97         }
98 }
99
100 sub refresh {
101         my ($kernel,$heap) = @_[KERNEL,HEAP];
102         $kernel->delay( refresh => 60 );
103         print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
104
105         my $dbh = DB();
106         my $scans = $dbh->prepare(q{SELECT s.scan_id
107                         ,array_agg(sr.nick) AS nick
108                         ,array_agg(sr.id) AS id
109                 FROM scan_requests sr
110                         JOIN scans s USING (pid,type)
111                 WHERE sr.time > NOW() - '30 min'::INTERVAL
112                         AND s.tick >= sr.tick AND NOT sr.sent
113                 GROUP BY scan_id
114                 });
115         my $sentscan = $dbh->prepare(q{UPDATE scan_requests
116                 SET sent = TRUE WHERE id = ANY($1)
117                 });
118         $scans->execute;
119         while (my $scan = $scans->fetchrow_hashref){
120                 $heap->{irc}->yield(notice => $scan->{nick}, "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}");
121                 $sentscan->execute($scan->{id});
122         }
123         return;
124 }
125
126 1;