]> ruin.nu Git - NDIRC.git/commitdiff
Converted .getships and .shipshome
authorMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 17:55:26 +0000 (19:55 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 18:09:33 +0000 (20:09 +0200)
Commands/Usermgm.pm
Usermgm.pm
database/roles.sql

index 3563b84fc12b7754b6dfb41330adff97ea6ed8cb..101ea06910d949b30a974c67a24c4ec2e62bf5e4 100644 (file)
@@ -247,4 +247,48 @@ WHERE username ILIKE $1 ORDER BY lower(username)
        $c->reply("<b>$i</b> 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("<b>$i</b> Users with <b>$total $ship</b>: $text");
+       }else{
+               $c->reply("Couldn't find any user with <b>$ship</b>");
+       }
+}
+
 1;
index b24e3e11ab92e659c9e4cfdc156014bf77425fd1..21fbce815aabdc876d2fe79cfe8095035c617e5e 100644 (file)
@@ -25,50 +25,7 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/addPoints setHost setPNick getShips getFleet/;
-
-sub getShips {
-       my ($ship,$command) = @_;
-
-       unless (defined $ship){
-               $ND::server->command("notice $ND::nick Usage: .$command ship | % can be used as wildcard, e.g. beet%");
-               return;
-       }
-       if (officer() || dc()){
-               my $f = $ND::DBH->prepare(qq{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 ? AND uid IN (SELECT uid FROM groupmembers WHERE gid = 2)
-                       GROUP BY username ORDER BY amount DESC
-                       });
-               if ($command eq 'shipshome'){
-                       $f = $ND::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){
-                       $user->{last} = '?' unless defined $user->{last};
-                       $text .= "$user->{username}: $user->{amount} ";
-                       $i++;
-                       $total += $user->{amount};
-               }
-               if ($text){
-                       $ND::server->command("notice $ND::nick $ND::B$i$ND::B Users with $ND::B$total $ship$ND::B: $text");
-               }else{
-                       $ND::server->command("msg $ND::target $ND::B$i$ND::B Couldn't find any user with $ND::B$ship$ND::B:");
-               }
-       }
-}
+our @EXPORT = qw/addPoints setHost setPNick getFleet/;
 
 sub getFleet {
        my ($nick,$command) = @_;
index 5051286cc05c5c71eb117d8439b1ad579a6ae49b..f618bd0d506554d05afb6228d3bc5cccae964e4b 100644 (file)
@@ -16,6 +16,7 @@ INSERT INTO roles VALUES('irc_whois');
 INSERT INTO roles VALUES('irc_flag');
 INSERT INTO roles VALUES('irc_laston');
 INSERT INTO roles VALUES('irc_lastseen');
+INSERT INTO roles VALUES('irc_getships');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
@@ -33,6 +34,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_whois');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_flag');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_laston');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_lastseen');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_getships');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan');
@@ -52,6 +54,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_whois');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_flag');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_laston');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_lastseen');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_getships');
 
 INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others');
 
@@ -61,6 +64,7 @@ INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_intel');
 INSERT INTO group_roles (gid,role) VALUES(6,'irc_p_intel');
 INSERT INTO group_roles (gid,role) VALUES(6,'irc_points_others');
 INSERT INTO group_roles (gid,role) VALUES(6,'irc_sms');
+INSERT INTO group_roles (gid,role) VALUES(6,'irc_getships');
 
 INSERT INTO group_roles (gid,role) VALUES(8,'irc_scanreqs');
 INSERT INTO group_roles (gid,role) VALUES(8,'irc_anonscan');