X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;ds=sidebyside;f=Commands%2FUsermgm.pm;fp=Commands%2FUsermgm.pm;h=101ea06910d949b30a974c67a24c4ec2e62bf5e4;hb=2cc4a8683c21bee13c36eb4c24954d7f57f4e967;hp=3563b84fc12b7754b6dfb41330adff97ea6ed8cb;hpb=51ff7a3cc079e17dd0c11eb90a6b28a0ef51d409;p=NDIRC.git
diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm
index 3563b84..101ea06 100644
--- a/Commands/Usermgm.pm
+++ b/Commands/Usermgm.pm
@@ -247,4 +247,48 @@ WHERE username ILIKE $1 ORDER BY lower(username)
$c->reply("$i Users(days): $text");
}
+sub getships
+ : Help(Usage: .getships ship | % can be used as wildcard, e.g. beet%, shipshome shows the number of ships currently home)
+ : Alias(shipshome)
+ : ACL(irc_getships)
+{
+ my ($self,$c,$msg) = @_;
+ my ($ship) = $msg =~ /^(\S+)$/ or die 'ARGS';
+ my $dbh = $c->model;
+
+ my $f = $dbh->prepare(q{
+SELECT username,SUM(fs.amount) AS amount
+FROM users u
+ JOIN (SELECT DISTINCT ON (planet) planet,fid FROM fleets
+ WHERE mission = 'Full fleet' AND name <> 'Unit'
+ ORDER BY planet,tick DESC,fid DESC
+ ) f USING (planet)
+ JOIN fleet_ships fs USING (fid)
+WHERE ship ILIKE $1 AND uid IN (SELECT uid FROM groupmembers WHERE gid = 2)
+GROUP BY username ORDER BY amount DESC
+ });
+ if ($self->name eq 'shipshome'){
+ $f = $dbh->prepare(q{
+SELECT username,SUM(amount) AS amount
+FROM available_ships
+WHERE ship ILIKE ? AND uid IN (SELECT uid FROM groupmembers WHERE gid = 2)
+GROUP BY username ORDER BY amount DESC
+ });
+ }
+ $f->execute($ship);
+ my $text;
+ my $i = 0;
+ my $total = 0;
+ while (my $user = $f->fetchrow_hashref){
+ $text .= "$user->{username}: $user->{amount} ";
+ $i++;
+ $total += $user->{amount};
+ }
+ if ($text){
+ $c->reply("$i Users with $total $ship: $text");
+ }else{
+ $c->reply("Couldn't find any user with $ship");
+ }
+}
+
1;