]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Scans.pm
Converted .getscans
[NDIRC.git] / Commands / Scans.pm
index 2cb0c3c12c3db8ab85e55020501cbc1bb5ccaaf5..11f3337308eeaef821ff59383f43764ccb918001 100644 (file)
@@ -26,6 +26,15 @@ use feature ':5.10';
 use Moose;
 use MooseX::MethodAttributes;
 
+sub getscans
+       : Help(syntax: .getscans X:Y:Z)
+       : Type(pm)
+{
+       my ($self,$c,$args) = @_;
+       my ($x,$y,$z) = $args =~ /(\d+)\D+(\d+)\D+(\d+)/ or die 'ARGS';
+       $c->reply("https://nd.ruin.nu/stats/find/$x:$y:$z");
+}
+
 my %scanid = (p => 1, l => 2, d => 3, u => 4, n => 5, j => 7, a => 8);
 
 my @scantypes = ('Planet','Landing', 'Development'
@@ -91,4 +100,48 @@ VALUES((SELECT uid FROM users WHERE hostmask ILIKE $1),$2,$3,$4) RETURNING (id)
        }
 }
 
+my %scantypes;
+{
+       my $i = 1;
+       %scantypes = map {$_ => $i++} @scantypes;
+}
+
+sub scanreqs
+       : Help(syntax: .scanreqs [-pdunja] | Lists scan requests that haven't been handled. The argument can be used to omit types you don't have, like .scanreqs -ja to list all requests except jumpgates and advanced unit scans.)
+       : ACL(irc_scanreqs)
+{
+       my ($self, $c, $msg) = @_;
+
+       my @notype;
+       if ($msg =~ /^-([pdunja]+)$/){
+               for (split //, $1){
+                       push @notype, $scantypes[$scanid{$_}-1];
+               }
+       }elsif($msg){
+               die 'ARGS';
+       }
+
+       my $reqs = $c->model->prepare(q{
+SELECT min(sr.id) AS id, x,y,z,type
+FROM scan_requests sr
+       JOIN current_planet_stats p ON p.id = sr.planet
+WHERE sr.time > NOW() - '30 min'::INTERVAL
+       AND NOT EXISTS (SELECT scan_id FROM scans
+               WHERE planet = sr.planet
+                       AND type = sr.type
+                       AND tick >= sr.tick
+       )
+       AND type <> ALL($1)
+GROUP BY x,y,z,type
+ORDER BY id
+               });
+       $reqs->execute(\@notype);
+       my $text = '';
+       while (my $req = $reqs->fetchrow_hashref){
+               $text .= "<b>$req->{id}</b> http://game.planetarion.com/waves.pl?id=$scantypes{$req->{type}}&x=$req->{x}&y=$req->{y}&z=$req->{z} "
+       }
+
+       $c->reply($text || 'No unhandled requests.');
+}
+
 1;