+ });
+ $req->execute($c->replyId,$scan->{id});
+ $id = $scan->{id};
+ }else{
+ $req = $c->model->prepare(q{
+INSERT INTO scan_requests (uid,nick,pid,type)
+VALUES($1,$2,$3,$4) RETURNING (id)
+ });
+ $req->execute($c->uid,$c->replyId,$planet,$type);
+ $id = $req->fetchrow;
+ }
+
+ if ($id){
+ if (defined $dists){
+ $dists = "$dists dists PT$tick"
+ }else{
+ $dists = "DISTS UNKNOWN, ADD DEVSCAN"
+ }
+ $c->bot->toTarget( scan =>
+ "<b>$id</b> http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
+ . " ($x:$y:$z $type - $dists) | <".$c->username."> $msg"
+ );
+ $c->reply("sent request ($x:$y:$z $type)");
+ }else{
+ $c->reply("something went wrong..");
+ }
+ }
+ }
+};
+
+my %scantypes;
+{
+ my $i = 1;
+ %scantypes = map {$_ => $i++} @scantypes;
+}
+
+command scanreqs => {
+ help => q(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 => q(irc_scanreqs),
+ type => q{scan},
+}, class extends NDIRC::Command {
+ method execute($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 USING (pid)
+WHERE sr.time > NOW() - '30 min'::INTERVAL
+ AND NOT EXISTS (SELECT scan_id FROM scans
+ WHERE pid = sr.pid
+ AND type = sr.type
+ AND tick >= sr.tick
+ )
+ AND type <> ALL($1)
+GROUP BY x,y,z,type
+ORDER BY id