]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Def.pm
Update report_incs
[NDIRC.git] / Commands / Def.pm
index 5aec9314ef42690f12d6a2f3013433b1d2ebc7c7..ba077f75ca7f7b971682d936d1ef27586aab8976 100644 (file)
@@ -58,9 +58,8 @@ ORDER BY c.landing_tick;
                                return;
                        }
                }
-               $c->message(notice => $c->disp->targets->{members}, "DEFENSE REQUIRED!! WAKE UP!!");
-               $c->message(privmsg => $c->disp->targets->{members}, "DEFENSE REQUIRED "
-                       ."$mess $callinfo MSG ".$c->nick." TO RESPOND");
+               $c->bot->toTarget(members => "DEFENSE REQUIRED "
+                       ."$mess $callinfo RESPOND TO ".$c->username);
        }
 };
 
@@ -219,9 +218,10 @@ command report_incs => {
        help => q(Used to report incs, same as pasting in pm. Use ~ prefix to send output to channel),
        type => q(def),
 }, class extends NDIRC::Command {
+       use Try::Tiny;
        method execute($c,$msg) {
 
-               $msg =~ /(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\s+([^:]*\S+)\s+(?:Ter|Cat|Xan|Zik|Etd)\s+([\d,]+)\s+Attack\s+(\d+)/
+               $msg =~ /(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\s+([^:]*\S+)\s+(?:Ter|Cat|Xan|Zik|Etd)\s+([\d,]+)\s+(?:Attack\s+)?(\d+)/
                || $msg =~ /(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((?:Ter|Cat|Xan|Zik|Etd)\)\s+([^,]*\S+)\s+([\d,]+)\s+(\d+)\s+\(\d+\)/
                        or return;
                my $dbh = $c->model;
@@ -243,27 +243,27 @@ SELECT nick,alliance,pid,planet_status,relationship
 FROM current_planet_stats WHERE x = ? AND y = ? AND z = ?
                        });
                        if (my @attacker = $dbh->selectrow_array($st,undef,$4,$5,$6)){
-                               $dbh->begin_work;
-                               my $landing_tick = $dbh->selectrow_array(q{SELECT tick() + ?},undef,$9);
-                               my @call = $dbh->selectrow_array(q{
+                               try {
+                                       $dbh->begin_work;
+                                       my $landing_tick = $dbh->selectrow_array(q{SELECT tick() + ?},undef,$9);
+                                       my @call = $dbh->selectrow_array(q{
 SELECT call,status,calc
 FROM calls WHERE uid = ? AND landing_tick = ?
-                               },undef,$user->{uid},$landing_tick);
-                               my $threefleeter = $dbh->selectrow_array(q{
+                                               },undef,$user->{uid},$landing_tick);
+                                       my $threefleeter = $dbh->selectrow_array(q{
 SELECT COALESCE(gid = 'X',false)
 FROM groupmembers WHERE uid = ? AND gid = 'X'
-                               },undef,$user->{uid});
-                               unless (@call){ #call doesn't exists, create a new one
-                                       @call = $dbh->selectrow_array(q{
+                                               },undef,$user->{uid});
+                                       unless (@call){ #call doesn't exists, create a new one
+                                               @call = $dbh->selectrow_array(q{
 INSERT INTO calls (uid,landing_tick,info) VALUES(?,?,'') RETURNING call,status,calc
-                                       },undef,$user->{uid},$landing_tick);
-                                       if ($threefleeter){
-                                               $dbh->do(q{UPDATE calls SET status = 'Ignored' WHERE call = $1},undef,$call[0]);
-                                               $c->def_log($call[0], 'This member has been marked as [B]NoDef[/B], do [B]not cover[/B] unless you have a good reaon.');
-                                               $call[1] = 'Ignored';
+                                                       },undef,$user->{uid},$landing_tick);
+                                               if ($threefleeter){
+                                                       $dbh->do(q{UPDATE calls SET status = 'Ignored' WHERE call = $1},undef,$call[0]);
+                                                       $c->def_log($call[0], 'This member has been marked as [B]NoDef[/B], do [B]not cover[/B] unless you have a good reaon.');
+                                                       $call[1] = 'Ignored';
+                                               }
                                        }
-                               }
-                               if (@call){
                                        my $pointlimits = $dbh->prepare(q{SELECT value :: float FROM misc WHERE id = ?});
                                        my ($minpoints) = $dbh->selectrow_array($pointlimits,undef,'DEFMINPRIO');
                                        my ($maxpoints) = $dbh->selectrow_array($pointlimits,undef,'DEFMAXPRIO');
@@ -281,33 +281,36 @@ INSERT INTO incomings (call,pid,eta,amount,fleet) VALUES(?,?,?,?,?) RETURNING in
                                                },undef,$call[0],$attacker[2],$9,$amount,$7);
                                                @attacker = map ($c->valuecolor(0),@attacker);
                                                if (! $threefleeter || $call[1] ne 'Ignored'){
-                                                       $c->reply("<b>New incoming: CallId: $call[0], IncId: $incid $1:$2:$3 ($user->{defprio}) is under Attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]) https://nd.ruin.nu/calls/edit/$call[0]</b>");
+                                                       $c->bot->toTarget(def => "<b>New incoming: CallId: $call[0], IncId: $incid $1:$2:$3 ($user->{defprio}) is under Attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]) https://nd.ruin.nu/calls/edit/$call[0]</b>");
                                                }else{
-                                                       $c->reply("<b>Do not cover</b>, NoDef member is under attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4])  https://nd.ruin.nu/calls/edit/$call[0]");
+                                                       $c->bot->toTarget(def => "<b>Do not cover</b>, NoDef member is under attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4])  https://nd.ruin.nu/calls/edit/$call[0]");
                                                }
                                                $dbh->do(q{UPDATE planets SET hit_us = hit_us + 1 WHERE pid = ?},undef,$attacker[2]);
                                                if ($call[1] eq 'Covered'){
                                                        $dbh->do(q{UPDATE calls SET status = 'Open' WHERE call = ?},undef,$call[0]);
-                                                       $c->reply("<b>Call is likely not covered anymore, please recalc! calc: $call[2]</b>");
+                                                       $c->bot->toTarget(def => "<b>Call is likely not covered anymore, please recalc! calc: $call[2]</b>");
                                                }
                                        }else{
                                                @attacker = map ($c->valuecolor(0),@attacker);
-                                               $c->reply("Duplicate call: Callid: $call[0], Status: $call[1] $1:$2:$3 ($user->{defprio}) is under Attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]), landing tick: $landing_tick");
+                                               $c->bot->toTarget(def => "Duplicate call: Callid: $call[0], Status: $call[1] $1:$2:$3 ($user->{defprio}) is under Attack by $4:$5:$6, ($attacker[3]), $attacker[1]($attacker[4]), landing tick: $landing_tick");
                                        }
 
                                        my ($fleetcatch) = $dbh->selectrow_array(q{
 SELECT count(*) FROM launch_confirmations WHERE uid = ? AND back = ?
                                        },undef,$user->{uid},$landing_tick);
                                        if ($fleetcatch > 0){
-                                               $c->reply("<c04>THIS IS A POSSIBLE FLEETCATCH!</c>");
+                                               $c->bot->toTarget(def => "<c04>THIS IS A POSSIBLE FLEETCATCH!</c>");
                                        }
-                               }
-                               $dbh->commit;
+                                       $dbh->commit;
+                               } catch {
+                                       $dbh->rollback;
+                                       die $_;
+                               };
                        }else{
-                               $c->reply("<c04>Didn't find any planet with coordinates $4:$5:$6 at this tick</c>");
+                               $c->bot->toTarget(def => "<c04>Didn't find any planet with coordinates $4:$5:$6 at this tick</c>");
                        }
                }else{
-                       $c->reply("<c04>No member registered with coordinates $1:$2:$3</c>");
+                       $c->bot->toTarget(def => "<c04>No member registered with coordinates $1:$2:$3</c>");
                }
        }
 };