}
}
+sub newtag
+ : Help(Usage: .newtag tag | Creates a new tag that can be used with addtag, tags can only contain a-z, A-Z, 0-9 and _)
+ : ACL(irc_newtag)
+ : Type(member)
+{
+ my ($self,$c,$msg) = @_;
+ my ($tag) = $msg =~ /^(\w+)$/ or die 'ARGS';
+
+ my $dbh = $c->model;
+ my $query = $dbh->prepare(q{
+INSERT INTO available_planet_tags (tag) VALUES($1)
+ });
+ eval {
+ $query->execute($tag);
+ };
+ if ($@ =~ /duplicate key value/){
+ $c->reply("<b>$tag</b> already exists");
+ return;
+ }elsif ($@){
+ die $@;
+ }
+ $c->reply("Added tag <b>$tag</b>");
+}
+
+sub addtag
+ : Help(Usage: .addtag X:Y:Z tag | Adds the tag to planet X:Y:Z)
+ : ACL(irc_addtag)
+ : Type(member)
+{
+ my ($self,$c,$msg) = @_;
+ my ($x,$y,$z,$tag) = $msg =~ /^(\d+)\D+(\d+)\D+(\d+)\s+(\S+)$/ or die 'ARGS';
+ my $dbh = $c->model;
+
+ my $query = $dbh->prepare(q{
+INSERT INTO planet_tags (uid,pid,tag) VALUES($1,planetid($2,$3,$4,tick()),$5)
+ });
+ eval {
+ $query->execute($c->uid,$x,$y,$z,$tag);
+ };
+ given ($@){
+ when(''){
+ $c->reply("Added tag <b>$tag</b> to $x:$y:$z");
+ }when (/duplicate key value/){
+ $c->reply("$x:$y:$z already has tag <b>$tag</b>");
+ }when (/null value in column "pid"/){
+ $c->reply("No planet with coords $x:$y:$z");
+ }when ($@ =~ /foreign key constraint "planet_tags_tag_fkey"/){
+ $query = $dbh->prepare(q{
+SELECT array_to_string(array_agg(tag),' ')
+FROM (SELECT tag FROM available_planet_tags
+ WHERE tag % $1 ORDER BY similarity(tag,$1) DESC) t
+ });
+ my ($tags) = $dbh->selectrow_array($query,undef,$tag);
+ $c->reply("<b>$tag</b> is not a valid tag. Either you need to add it with .newtag,"
+ ." or you want one of: $tags");
+ }
+ default {
+ die $@;
+ }
+ }
+}
+
+sub deltag
+ : Help(Usage: .deltag X:Y:Z tag | Removes the tag from planet X:Y:Z)
+ : ACL(irc_addtag)
+ : Type(member)
+{
+ my ($self,$c,$msg) = @_;
+ my ($x,$y,$z,$tag) = $msg =~ /^(\d+)\D+(\d+)\D+(\d+)\s+(\S+)$/ or die 'ARGS';
+ my $dbh = $c->model;
+
+ my $query = $dbh->prepare(q{
+DELETE FROM planet_tags WHERE uid = $1 AND pid = planetid($2,$3,$4,tick()) AND tag LIKE $5
+ });
+ $query->execute($c->uid,$x,$y,$z,$tag);
+ my $rows = $query->rows;
+ $c->reply("Removed <b>$rows</b> matching $tag from $x:$y:$z");
+}
+
1;
}
my $f = $c->model->prepare(q{
-SELECT coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
- valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
-FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
+WITH p AS (SELECT coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
+ valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
+ FROM current_planet_stats
+ WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
+), t AS (SELECT tag,bool_or(uid = $5) AS own,max(time) AS time
+ FROM planet_tags
+ WHERE pid = (SELECT pid FROM p)
+ AND ($6 OR uid = $5)
+ GROUP BY tag
+ ORDER BY time DESC
+), tags AS (SELECT array_to_string(array_agg(tag || CASE WHEN own THEN '*' ELSE '' END),' ') AS tags
+ FROM t
+)
+SELECT * FROM p, tags;
});
- $f->execute($x,$y,$z,$nick);
+ $f->execute($x,$y,$z,$nick,$c->uid,$c->check_user_roles(qw/irc_p_intel/));
if (my $planet = $f->fetchrow_hashref()){
for (keys %{$planet}){
$planet->{$_} = valuecolor(1,$planet->{$_});
if ($c->check_user_roles(qw/irc_p_intel/)){
$ally = "Alliance=$planet->{alliance} ($planet->{relationship}), Nick=$planet->{nick} ($planet->{planet_status}), Channel: $planet->{channel}, Hostile Count: $planet->{hit_us},";
}
- $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})");
+ $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}) TAGS: $planet->{tags}");
}else{
$c->reply("Couldn't find planet: $msg");
}
INSERT INTO roles VALUES('irc_sendsms');
INSERT INTO roles VALUES('irc_smsstatus');
INSERT INTO roles VALUES('irc_forum_others');
+INSERT INTO roles VALUES('irc_newtag');
+INSERT INTO roles VALUES('irc_addtag');
+INSERT INTO roles VALUES('irc_deltag');
INSERT INTO group_roles (gid,role) VALUES('T','irc_p_nick');
INSERT INTO group_roles (gid,role) VALUES('T','irc_p_intel');
INSERT INTO group_roles (gid,role) VALUES('M','irc_gs');
INSERT INTO group_roles (gid,role) VALUES('M','irc_scan');
+INSERT INTO group_roles (gid,role) VALUES('M','irc_newtag');
+INSERT INTO group_roles (gid,role) VALUES('M','irc_addtag');
+INSERT INTO group_roles (gid,role) VALUES('M','irc_deltag');
INSERT INTO group_roles (gid,role) VALUES('H','irc_p_nick');
INSERT INTO group_roles (gid,role) VALUES('H','irc_masterop');