X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FScans.pm;h=70420e9a33d100492b24f029bafe1cb71bf37052;hb=b87b6e87c3959096739e54bdf95c23d9e8212145;hp=2747acbb2abc5700770692bbe35c42f3acba48a3;hpb=df43148278c85c28726accbec2421688260661b7;p=NDIRC.git diff --git a/Commands/Scans.pm b/Commands/Scans.pm index 2747acb..70420e9 100644 --- a/Commands/Scans.pm +++ b/Commands/Scans.pm @@ -197,5 +197,49 @@ sub anon $c->message("msg $target", "$mess (reply with /msg $ND::scanchan)"); $c->message("msg $ND::scanchan", "$target << $mess"); } +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;