]> ruin.nu Git - NDIRC.git/commitdiff
Converted .defcall
authorMichael Andreen <harv@ruin.nu>
Sun, 17 May 2009 11:49:33 +0000 (13:49 +0200)
committerMichael Andreen <harv@ruin.nu>
Mon, 18 May 2009 12:02:04 +0000 (14:02 +0200)
Commands/Def.pm
Def.pm
database/roles.sql

index 7931033e2f6ddd1ba1cf1b04372dff5bb5fbaef0..74d0aa8dd85de111414620e2510cbb2d2483e983 100644 (file)
@@ -39,5 +39,45 @@ sub anon
        $c->message("msg ".$c->channel, "<c03>$target << $mess</c>");
 }
 
+sub defcall
+       : Help(syntax: .defcall [callid] | if a call id is given, then shiptypes and eta will be fetched from the database and added to the message)
+       : Type(def)
+       : ACL(irc_defcall)
+{
+       my ($self,$c,$msg) = @_;
+       my ($callnr,$mess) = $msg =~ /^(\d+)?(.*)$/ or die 'ARGS';
+       my $dbh = $c->model;
+
+       my $callinfo = "";
+       if ($callnr){
+               my $st = $dbh->prepare(q{
+SELECT covered
+       ,c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK') AS eta
+       ,concat(i.shiptype||'/') AS shiptype
+FROM calls c
+       JOIN incomings i ON i.call = c.id
+       LEFT OUTER JOIN users dc ON dc.uid = c.dc
+       JOIN users u ON u.uid = c.member
+WHERE c.id = ?
+GROUP BY c.id,c.landing_tick,c.covered
+ORDER BY c.landing_tick;
+               });
+               my $call = $dbh->selectrow_hashref($st,undef,$callnr);
+               unless (defined $call->{covered}){
+                       $c->reply("No call with id: $callnr");
+                       return;
+               }
+               chop($call->{shiptype});
+               $callinfo = "(Anti $call->{shiptype} ETA: $call->{eta})";
+               if($call->{covered}){
+                       $c->reply("Call <b>$callnr</b> $callinfo is covered.");
+                       return;
+               }
+       }
+       $c->message("notice $ND::memchan", "DEFENSE REQUIRED!! WAKE UP!!");
+       $c->message("msg $ND::memchan", "DEFENSE REQUIRED $mess $callinfo MSG "
+               .$c->nick." TO RESPOND");
+}
+
 1;
 
diff --git a/Def.pm b/Def.pm
index 7dbec8b1f761906ddc9b83ab80622d596b76524e..d8115012c5c179f2975935e5ac46dc455ea62cc7 100644 (file)
--- a/Def.pm
+++ b/Def.pm
@@ -29,7 +29,7 @@ require Exporter;
 our @ISA = qw/Exporter/;
 
 our @EXPORT = qw/showCall setType takeCall covCall ignoreCall
-       defcall setDefPrio setCalc getCalc/;
+       setDefPrio setCalc getCalc/;
 
 sub showCall {
        my ($msg,$command) = @_;
@@ -176,39 +176,6 @@ sub ignoreCall {
        }
 }
 
-sub defcall {
-       my ($msg,$command) = @_;
-       my ($mess,$nick,$callnr) = @_;
-       if (defined $msg && $msg =~ /^(\d+)?(.*)$/){
-               $callnr = $1;
-               $mess = $2;
-       }else{
-               $ND::server->command("notice $ND::nick Usage: $command [callid] message | if a call id is given, then shiptypes and eta will be fetched from the database and added to the message");
-               return;
-       }
-       if (dc()){
-               my $call = "";
-               if ($callnr){
-                       my $st = $ND::DBH->prepare(q{
-       SELECT c.landing_tick - (SELECT value::integer FROM misc WHERE id = 'TICK'), concat(i.shiptype||'/') AS shiptype
-       FROM calls c 
-               JOIN incomings i ON i.call = c.id
-               LEFT OUTER JOIN users dc ON dc.uid = c.dc
-               JOIN users u ON u.uid = c.member
-       WHERE not covered AND c.id = ?
-       GROUP BY c.id,c.landing_tick
-       ORDER BY c.landing_tick;
-                       });
-                       if (my @row = $ND::DBH->selectrow_array($st,undef,$callnr)){
-                               chop($row[1]);
-                               $call = "(Anti $row[1] ETA: $row[0])"
-                       }
-               }
-               $ND::server->command("notice $ND::memchan DEFENSE REQUIRED!! WAKE UP!!");
-               $ND::server->command("msg $ND::memchan DEFENSE REQUIRED $mess $call MSG $ND::nick TO RESPOND");
-       }
-}
-
 sub setCalc {
        my ($msg,$command) = @_;
        my ($id, $calc);
index 9024d30d895a16c01e617455b0c5b6b7029138df..09cc700b137a78c6fc9879b7fd8653ad8e862b8c 100644 (file)
@@ -29,6 +29,7 @@ INSERT INTO roles VALUES('irc_setnick');
 INSERT INTO roles VALUES('irc_setally');
 INSERT INTO roles VALUES('irc_setchannel');
 INSERT INTO roles VALUES('irc_anondef');
+INSERT INTO roles VALUES('irc_defcall');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
@@ -59,6 +60,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_setnick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_setally');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_setchannel');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_anondef');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_defcall');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan');
@@ -91,6 +93,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_setnick');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_setally');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_setchannel');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_anondef');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_defcall');
 
 INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others');
 INSERT INTO group_roles (gid,role) VALUES(4,'irc_a');
@@ -110,6 +113,7 @@ INSERT INTO group_roles (gid,role) VALUES(6,'irc_getfleet');
 INSERT INTO group_roles (gid,role) VALUES(6,'irc_d');
 INSERT INTO group_roles (gid,role) VALUES(6,'irc_sethostile');
 INSERT INTO group_roles (gid,role) VALUES(6,'irc_anondef');
+INSERT INTO group_roles (gid,role) VALUES(6,'irc_defcall');
 
 INSERT INTO group_roles (gid,role) VALUES(8,'irc_scanreqs');
 INSERT INTO group_roles (gid,role) VALUES(8,'irc_anonscan');