From dcb7d5ee3791ae43e7fcaf3639ce5b70f6c659ab Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Wed, 20 Mar 2019 23:05:06 +0100 Subject: [PATCH] Handle scan requests --- Commands/Scans.pm | 11 ++++++----- Context.pm | 25 +++++++++++++++++++++++++ Delling.pm | 5 +++-- DiscordContext.pm | 5 +++++ IrcContext.pm | 5 +++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Commands/Scans.pm b/Commands/Scans.pm index 8ea51ff..319e38c 100644 --- a/Commands/Scans.pm +++ b/Commands/Scans.pm @@ -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} - ,"$id 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 => + "$id 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; diff --git a/Context.pm b/Context.pm index 3629008..7f1d2cc 100644 --- a/Context.pm +++ b/Context.pm @@ -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 = $_; diff --git a/Delling.pm b/Delling.pm index 01097f2..fe35fe1 100644 --- a/Delling.pm +++ b/Delling.pm @@ -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}); } diff --git a/DiscordContext.pm b/DiscordContext.pm index 8de77c0..c6e4959 100644 --- a/DiscordContext.pm +++ b/DiscordContext.pm @@ -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) = @_; diff --git a/IrcContext.pm b/IrcContext.pm index 209f25e..b8eae0d 100644 --- a/IrcContext.pm +++ b/IrcContext.pm @@ -91,6 +91,11 @@ sub message { $self->command($command, $target, $msg); } +sub replyId { + my $self = shift; + return $self->nick; +} + sub command { my ($self,@command) = @_; -- 2.39.2