]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Scans.pm
Converted addscans
[NDIRC.git] / Commands / Scans.pm
index 2747acbb2abc5700770692bbe35c42f3acba48a3..70420e9a33d100492b24f029bafe1cb71bf37052 100644 (file)
@@ -197,5 +197,49 @@ sub anon
        $c->message("msg $target", "<b>$mess</b> <c04>(reply with /msg $ND::scanchan)</c>");
        $c->message("msg $ND::scanchan", "<c03>$target << $mess</c>");
 }
+sub addscan
+       : Help(syntax: .addscan list of scans)
+{
+       my ($self, $c, $msg) = @_;
+       my $dbh = $c->model;
+
+       my $oldscan = $dbh->prepare(q{
+SELECT scan_id FROM scans
+WHERE groupscan = $1 AND scan_id = LOWER($2) AND tick >= tick() - 168
+               });
+       my $addscan = $dbh->prepare(q{
+INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER($1),tick(),$2,COALESCE($3,-1))
+               });
+       my $user = $dbh->selectrow_hashref(q{SELECT uid,username, scan_points, tick()
+               FROM users WHERE hostmask ILIKE ? },undef,$c->host);
+       my $groupscans = 0;
+       my $scans = 0;
+       eval {
+               $dbh->begin_work;
+               while ($msg =~ m{/.+?scan(_id|_grp)?=(\w+)}g){
+                       my $id = $2;
+                       my $group = ($1 ~~ /_grp/ || 0);
+                       unless($dbh->selectrow_array($oldscan,undef,$group,$id)){
+                               $addscan->execute($id,$group,$user->{uid});
+                               if ($group){
+                                       $groupscans++;
+                               }else{
+                                       $scans++;
+                               }
+                       }
+               }
+               if ($user->{uid} && ($scans || $groupscans)){
+                       $dbh->do(q{UPDATE users SET scan_points = scan_points + $2 WHERE uid = $1}
+                               ,undef,$user->{uid},$scans);
+                       my $points = $user->{scan_points} + $scans;
+                       $c->reply("Added $scans scans and $groupscans groupscans, $points in total.");
+               }
+               $dbh->commit;
+       };
+       if ($@){
+               $dbh->rollback;
+               die $@;
+       }
+}
 
 1;