]> ruin.nu Git - NDIRC.git/blob - Commands/PA.pm
Converted the .g command
[NDIRC.git] / Commands / PA.pm
1 #**************************************************************************
2 #   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 package NDIRC::Commands::PA;
21
22 use strict;
23 use warnings;
24
25 use Moose;
26 use MooseX::MethodAttributes;
27
28 use NDIRC::Misc;
29
30 sub p
31         : Help(usage: .p X:Y:Z | or .p nick with high enough access)
32 {
33         my ($self, $c, $msg) = @_;
34
35         my ($x,$y,$z,$nick);
36         if ($msg =~ /(\d+)\D+(\d+)\D+(\d+)/){
37                 $x = $1;
38                 $y = $2;
39                 $z = $3;
40         }elsif ($msg && $c->check_user_roles(qw/irc_p_nick/)){
41                 $nick = $msg;
42         }else{
43                 die "ARGS";
44         }
45
46         my $f = $c->model->prepare(q{
47 SELECT coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
48         valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
49 FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
50         });
51         $f->execute($x,$y,$z,$nick);
52         if (my $planet = $f->fetchrow_hashref()){
53                 for (keys %{$planet}){
54                         $planet->{$_} = valuecolor(1,$planet->{$_});
55                 }
56                 my $ally = "";
57                 if ($c->check_user_roles(qw/irc_p_intel/)){
58                         $ally = "Alliance=$planet->{alliance} ($planet->{relationship}), Nick=$planet->{nick} ($planet->{planet_status}), Channel: $planet->{channel}, Hostile Count: $planet->{hit_us},";
59                 }
60                 $c->reply("$planet->{coords} $planet->{ruler} OF $planet->{planet},$ally Race=$planet->{race}, Score=$planet->{score} ($planet->{scorerank}), Size=$planet->{size} ($planet->{sizerank}), Value=$planet->{value} ($planet->{valuerank}), XP=$planet->{xp} ($planet->{xprank})");
61         }else{
62                 $c->reply("Couldn't find planet: $msg");
63         }
64 }
65
66 sub g
67         : Help(usage: .g X:Y)
68 {
69         my ($self, $c, $msg) = @_;
70
71         my ($x,$y) = ($msg =~ /(\d+)\D+(\d+)/) or die 'ARGS';
72
73         my $f = $c->model->prepare(q{
74 SELECT score,scorerank,size,sizerank,value,valuerank,planets
75 FROM galaxies WHERE x = ? AND y = ? AND tick = (SELECT max(tick) from galaxies)
76         });
77         $f->execute($x,$y);
78         while (my @row = $f->fetchrow()){
79                 @row = map (valuecolor(1),@row);
80                 $c->reply("$x:$y  Score=$row[0] ($row[1]), Size=$row[2] ($row[3]), Value=$row[4] ($row[5]), Planets=$row[6]");
81         }
82 }
83
84 1;