]> ruin.nu Git - ndwebbie.git/blob - scripts/ndreport.pl
Use new race infrastructure for members stats
[ndwebbie.git] / scripts / ndreport.pl
1 #!/usr/bin/perl
2 q{
3 /***************************************************************************
4  *   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
20  ***************************************************************************/
21 };
22
23 use strict;
24 use warnings;
25 use local::lib;
26 use DBI;
27 use DBD::Pg qw(:pg_types);
28 use CGI qw/:standard/;
29
30 use Email::Simple;
31 use Encode::Encoder qw(encoder);
32 use MIME::QuotedPrint;
33
34 use FindBin;
35 use lib "$FindBin::Bin/../lib";
36 use ND::DB;
37
38 my $dbh = ND::DB::DB();
39
40 my @text = <>;
41 my $text = join '',@text;
42
43 $text =~ /ndreport\+(.+?)\@ruin\.nu/;
44
45 my $user = $1;
46
47 my $email = Email::Simple->new($text);
48
49 my $body =  encoder($email->body,'ISO-8859-15')->utf8;
50
51 my $c = $dbh->prepare(q{
52 SELECT coords(x,y,z) FROM current_planet_stats WHERE pid = (SELECT pid FROM users WHERE username = $1
53         AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M'))
54 });
55
56 my $a = $dbh->prepare(q{
57 SELECT race, $1 - tick() FROM current_planet_stats WHERE x = $2 AND y = $3 AND z = $4
58 });
59
60 my $report = $dbh->prepare(q{INSERT INTO irc_requests (channel,uid,message) VALUES('def',$1,$2)});
61
62 while($body =~ /jumpgate from (.+?), located at (\d+):(\d+):(\d+).+?our system in tick (\d+) and appears to have (\d+)/sg){
63         my ($fleet, $x,$y,$z,$tick, $amount) = ($1,$2,$3,$4,$5,$6);
64
65         my ($coords) = $dbh->selectrow_array($c, undef, $user);
66
67         $coords //= '(no coords entered)';
68
69         my ($race,$eta) = $dbh->selectrow_array($a,undef, $tick,$x,$y,$z);
70
71         $report->execute(-5,"$user has incs: $coords $x:$y:$z $fleet $race $amount $eta");
72 }
73
74 $dbh->disconnect;
75
76 system 'killall','-USR1', 'ndbot.pl';