]> ruin.nu Git - NDIRC.git/commitdiff
Handle scan requests
authorMichael Andreen <harv@ruin.nu>
Wed, 20 Mar 2019 22:05:06 +0000 (23:05 +0100)
committerMichael Andreen <harv@ruin.nu>
Thu, 21 Mar 2019 15:47:50 +0000 (16:47 +0100)
Commands/Scans.pm
Context.pm
Delling.pm
DiscordContext.pm
IrcContext.pm

index 8ea51ffc4b1fa89a775157f0ee775c8642db0f90..319e38cfef6eded49488b59bd855bff36f3414f9 100644 (file)
@@ -83,14 +83,14 @@ WHERE uid = $1
 UPDATE scan_requests SET nick = $1, tick = tick(), time = NOW()
 WHERE id = $2
                                        });
-                               $req->execute($c->nick,$scan->{id});
+                               $req->execute($c->replyId,$scan->{id});
                                $id = $scan->{id};
                        }else{
                                $req = $c->model->prepare(q{
 INSERT INTO scan_requests (uid,nick,pid,type)
 VALUES($1,$2,$3,$4) RETURNING (id)
                                        });
-                               $req->execute($c->uid,$c->nick,$planet,$type);
+                               $req->execute($c->uid,$c->replyId,$planet,$type);
                                $id = $req->fetchrow;
                        }
 
@@ -100,9 +100,9 @@ VALUES($1,$2,$3,$4) RETURNING (id)
                                }else{
                                        $dists = "DISTS UNKNOWN, ADD DEVSCAN"
                                }
-                               $c->message(privmsg => $c->disp->targets->{scan}
-                                       ,"<b>$id</b> http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
-                                       . " ($x:$y:$z $type - $dists) | <".$c->nick."> $msg"
+                               $c->bot->toTarget( scan =>
+                                       "<b>$id</b> http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
+                                       . " ($x:$y:$z $type - $dists) | <".$c->username."> $msg"
                                );
                                $c->reply("sent request ($x:$y:$z $type)");
                        }else{
@@ -121,6 +121,7 @@ my %scantypes;
 command scanreqs => {
        help => q(syntax: .scanreqs [-pdunja] | Lists scan requests that haven't been handled. The argument can be used to omit types you don't have, like .scanreqs -ja to list all requests except jumpgates and advanced unit scans.),
        acl => q(irc_scanreqs),
+       type => q{scan},
 }, class extends NDIRC::Command {
        method execute($c,$msg) {
                my @notype;
index 36290089a995a87d376b35eeda3ea6e520a46050..7f1d2cc58e9654c71c3208c527486bd91615a737 100644 (file)
@@ -45,6 +45,12 @@ has uid => (
        lazy_build => 1
 );
 
+has username => (
+       is => 'ro',
+       isa => 'Str',
+       lazy_build => 1
+);
+
 has disp => (
        is => 'ro',
        isa => 'Object',
@@ -89,6 +95,9 @@ sub reply {
 sub message {
 }
 
+sub replyId {
+}
+
 sub intel_log {
        my ($c,$planet, $message) = @_;
        my $log = $c->model->prepare_cached(q{
@@ -130,6 +139,22 @@ sub _build_uid {
        return -4;
 }
 
+sub _build_username {
+       my ($self) = @_;
+
+       my $query = $self->model->prepare(q{
+SELECT username FROM users
+WHERE uid = $1
+               });
+       $query->execute($self->uid);
+
+       if (my ($username) = $query->fetchrow_array){
+               $query->finish;
+               return $username;
+       }
+       return "Anonymous";
+}
+
 sub valuecolor {
        shift @_;
        my $s = $_;
index 01097f2b318e54b9e2472bf34311e4efca472464..fe35fe131562ee1fecbb8d3f25b3cc82ad0a5ce2 100644 (file)
@@ -162,8 +162,9 @@ sub refresh {
                });
        $scans->execute;
        while (my $scan = $scans->fetchrow_hashref){
-               $heap->{irc}->yield(notice => $scan->{nick}, "($scan->{coords} $scan->{type})"
-                       ." http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}");
+               $self->message("($scan->{coords} $scan->{type})"
+                       ." http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}"
+                       , @{$scan->{nick}});
                $sentscan->execute($scan->{id});
        }
 
index 8de77c09c17cc2ff37052d3959c3b2686dbf6802..c6e4959a2343c2e700661dc33c8f5096da0f142e 100644 (file)
@@ -57,6 +57,11 @@ sub message {
        $self->bot->discordMessage($target, $msg ); # Send the response.
 }
 
+sub replyId {
+       my $self = shift;
+       return "D-".$self->channel_id;
+}
+
 sub _build_uid {
        my ($self) = @_;
 
index 209f25eab8f56340563dcd958d2f276de03a2885..b8eae0d003889a52869d3fe53efd16333343025b 100644 (file)
@@ -91,6 +91,11 @@ sub message {
        $self->command($command, $target, $msg);
 }
 
+sub replyId {
+       my $self = shift;
+       return $self->nick;
+}
+
 sub command {
        my ($self,@command) = @_;