]> ruin.nu Git - NDIRC.git/commitdiff
Converted addscans
authorMichael Andreen <harv@ruin.nu>
Fri, 15 May 2009 17:07:17 +0000 (19:07 +0200)
committerMichael Andreen <harv@ruin.nu>
Fri, 15 May 2009 17:07:53 +0000 (19:07 +0200)
Commands/Scans.pm
Dispatcher.pm
Misc.pm
Scans.pm [deleted file]
ndawn.pl

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;
index 5da34bdaf5d9ab976419ff8151ceda3275462261..ccfeb1371329689a2608b810101bc7dd7c2cbc11 100644 (file)
@@ -110,7 +110,7 @@ sub has_command {
        my ($self,$command,$channel) = @_;
        $channel = lc $channel;
 
-       return 0 unless exists $self->commands->{$command};
+       return 0 unless defined $command && exists $self->commands->{$command};
 
        my $types = Set::Object->new(@{$self->commands->{$command}->type});
        my @types = qw/pub/;
diff --git a/Misc.pm b/Misc.pm
index 66ef54562b77ff842781bf4b51e233d8d2c37a77..6f923897b3c748edab1c84bd7246e68a2fbc0edc 100644 (file)
--- a/Misc.pm
+++ b/Misc.pm
@@ -46,7 +46,15 @@ sub parseCommand {
        return if $channel !~ /^#/ && $msg =~ /^~/;
        $msg = ".$msg"  if $channel !~ /^#/ && $msg =~ /^[^.!]/;
 
-       my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/) or return 0;
+       my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
+
+       if ($msg =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
+               unless ($command){
+                       ($p,$command,$args) = ('.','addscan',$msg);
+               }elsif($command ne 'addscan'){
+                       parseCommand (".addscan $msg", $server, $nick, $address, $channel, $disp,$model)
+               }
+       }
 
        return 0 unless $disp->has_command($command,$channel);
 
diff --git a/Scans.pm b/Scans.pm
deleted file mode 100644 (file)
index 2bd6795..0000000
--- a/Scans.pm
+++ /dev/null
@@ -1,74 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-package NDIRC::Scans;
-use strict;
-use warnings;
-use ND::DB;
-use NDIRC::Access;
-require Exporter;
-
-our @ISA = qw/Exporter/;
-
-our @EXPORT = qw/addScan addScanGroup/;
-
-sub addScan {
-       my ($id,$verbose) = @_;
-       if (1){
-               unless ($ND::DBH->selectrow_array(q{SELECT scan_id FROM scans WHERE NOT groupscan AND scan_id = LOWER(?) AND tick >= tick() - 168},undef,$id)){
-                       my @user = $ND::DBH->selectrow_array(q{SELECT uid,username, scan_points, tick() 
-                               FROM users WHERE hostmask ILIKE ? },undef,$ND::address);
-                       if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,uid) VALUES (LOWER(?),tick(),COALESCE(?,-1))},
-                                       undef,$id,$user[0]) == 1){
-                               if (@user){
-                                       $ND::DBH->do('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ',undef,$user[0]);
-                                       $user[2] += 1;
-                                       $ND::server->command("notice $ND::nick Added scan, points now $user[2]");
-                               }elsif ($verbose){
-                                       $ND::server->command("msg $ND::target Added scan, but unknown user, no points");
-                               }
-                       }
-               }elsif ($verbose){
-                       $ND::server->command("msg $ND::target a scan with that id has already been added within the last 48 ticks");
-               }
-       }
-}
-sub addScanGroup {
-       my ($id,$verbose) = @_;
-       if (1){
-               unless ($ND::DBH->selectrow_array(q{SELECT scan_id FROM scans WHERE groupscan AND  scan_id = LOWER(?) AND tick >= tick() - 168},undef,$id)){
-                       my @user = $ND::DBH->selectrow_array(q{SELECT uid,username, scan_points, tick() 
-                               FROM users WHERE hostmask ILIKE ? },undef,$ND::address);
-                       if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER(?),tick(),true,COALESCE(?,-1))},
-                                       undef,$id,$user[0]) == 1){
-                               if (@user){
-                                       $ND::server->command("notice $ND::nick Added scan group. Points will be added after parsing.");
-                               }elsif ($verbose){
-                                       $ND::server->command("msg $ND::target Added scan, but unknown user, no points");
-                               }
-                       }
-               }elsif ($verbose){
-                       $ND::server->command("msg $ND::target a scan with that id has already been added within the last 48 ticks");
-               }
-       }
-}
-
-
-
-
-1;
index d805d75fe8685748dc26f6da1aaa253bfc17cc6b..62ec96de979fe3e789d8478e24f59e793edb09b0 100644 (file)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -59,7 +59,7 @@ $disp->load('Basic','PA','Channel','Scans');
 
 $ND::scanchan = '#testarmer';
 $disp->add_channel('#testarlite', ['pub','help','channel']);
-$disp->add_channel('#testarmer', ['pub','help','channel','scan']);
+$disp->add_channel($ND::scanchan, ['pub','help','channel','scan']);
 $disp->add_channel('pm', ['pub','help','pm']);
 
 sub event_pubmsg {