+};
+
+command anon => {
+ help => q(syntax: .anon nick message),
+ type => q(scan),
+ acl => q(irc_anonscan),
+}, class extends NDIRC::Command {
+ method execute($c,$msg) {
+ my ($target,$mess) = $msg =~ /^(\S+) (.*)$/ or die 'ARGS';
+
+ $c->message(privmsg => $target, "<b>$mess</b> <c04>(reply with /msg "
+ .$c->channel.")</c>");
+ $c->message(privmsg => $c->channel, "<c03>$target << $mess</c>");
+ }
+};
+
+command addscan => {
+ help => q(syntax: .addscan list of scans),
+}, class extends NDIRC::Command {
+ method execute($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 uid = ? },undef,$c->uid);
+ 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 $@;
+ }
+ }
+};