X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FPA.pm;h=633d2fee5d9a41ea94a584843be521f56fe8df82;hb=035b1523b2136f620f1aa161b04c011a30fbc174;hp=87e229049bd37347511db9b703f12034bbad9c8d;hpb=c6964887c87acd5769ec90ce8734407f74433fc7;p=NDIRC.git
diff --git a/Commands/PA.pm b/Commands/PA.pm
index 87e2290..633d2fe 100644
--- a/Commands/PA.pm
+++ b/Commands/PA.pm
@@ -21,6 +21,7 @@ package NDIRC::Commands::PA;
use strict;
use warnings;
+use feature ':5.10';
use Moose;
use MooseX::MethodAttributes;
@@ -63,4 +64,45 @@ FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4
}
}
+sub g
+ : Help(usage: .g X:Y)
+{
+ my ($self, $c, $msg) = @_;
+
+ my ($x,$y) = ($msg =~ /(\d+)\D+(\d+)/) or die 'ARGS';
+
+ my $f = $c->model->prepare(q{
+SELECT score,scorerank,size,sizerank,value,valuerank,planets
+FROM galaxies WHERE x = ? AND y = ? AND tick = (SELECT max(tick) from galaxies)
+ });
+ $f->execute($x,$y);
+ while (my @row = $f->fetchrow()){
+ @row = map (valuecolor(1),@row);
+ $c->reply("$x:$y Score=$row[0] ($row[1]), Size=$row[2] ($row[3]), Value=$row[4] ($row[5]), Planets=$row[6]");
+ }
+}
+
+sub time
+ : Help(syntax: .time [tick] [timezone] | Gives the time at the specied tick. Assumes GMT if no timezone is given and current tick if no tick is given.)
+{
+ my ($self, $c, $msg) = @_;
+ my ($tick,$timezone) = $msg =~ /^(\d+)?\s*(\S+)?$/ or die 'ARGS';
+
+ eval {
+ $tick //= $c->model->selectrow_array(q{SELECT tick()});
+ $timezone //= 'GMT';
+ my $query = $c->model->prepare(q{
+SELECT date_trunc('seconds',now() + (($1 - tick()) || ' hr')::interval) AT TIME ZONE $2
+ });
+ $query->execute($tick,$timezone);
+ my $time = $query->fetchrow_array;
+ $c->reply("Time at tick $tick, timezone $timezone: $time");
+ };
+ given ($@){
+ when(/time zone "(.+?)" not recognized/){
+ $c->reply("$1 is not a valid timezone.");
+ }
+ die $@ if $@;
+ }
+}
1;