]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Intel.pm
Implemented allycoords command
[NDIRC.git] / Commands / Intel.pm
index b52d694eddaef305da830f7a1bd96c40435fbd29..54e7e3bdc0acbb072532444a8a82aa95c1a66b1f 100644 (file)
@@ -228,4 +228,33 @@ DELETE FROM planet_tags WHERE uid = $1 AND pid = planetid($2,$3,$4,tick()) AND t
        $c->reply("Removed <b>$rows</b> matching $tag from $x:$y:$z");
 }
 
+sub allycoords
+       : Help(Usage: .allycoords ally | % can be used for wildcards \%-crew\% will match [F-Crew])
+       : ACL(irc_allycoords)
+{
+       my ($self,$c,$msg) = @_;
+       my ($ally) = $msg =~ /^(\S+)$/ or die 'ARGS';
+       my $dbh = $c->model;
+
+       my ($a, $members) = $dbh->selectrow_array(q{
+SELECT alliance, members
+FROM alliances JOIN alliance_stats USING (aid)
+WHERE tick = (SELECT max(tick) FROM alliance_stats)
+       AND alliance ILIKE $1
+               },undef,$ally);
+       unless ($a){
+               $c->reply("No alliance matching '$ally'");
+               return;
+       }
+       my $query = $dbh->prepare(q{
+SELECT coords(x,y,z) FROM current_planet_stats WHERE alliance = $1 ORDER BY x,y,z
+               });
+       $query->execute($a);
+       my @planets;
+       while (my $p = $query->fetchrow_hashref){
+               push @planets,$p->{coords};
+       }
+       my $kmem = scalar @planets;
+       $c->reply("$a ($kmem/$members) : ". join " ", @planets);
+}
 1;