]> ruin.nu Git - NDIRC.git/commitdiff
Converted the .+user command
authorMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 12:53:54 +0000 (14:53 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 12:58:55 +0000 (14:58 +0200)
Commands/Usermgm.pm [new file with mode: 0644]
Usermgm.pm
database/roles.sql
ndawn.pl

diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm
new file mode 100644 (file)
index 0000000..d7d86b0
--- /dev/null
@@ -0,0 +1,56 @@
+#**************************************************************************
+#   Copyright (C) 2009 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::Commands::Usermgm;
+
+use strict;
+use warnings;
+use feature ':5.10';
+
+use Moose;
+use MooseX::MethodAttributes;
+
+sub adduser
+       : Help(syntax: .+user username [pnick] | username must be alphanum characters, if no pnick is given then it will be set to the same as username)
+       : Alias(+user)
+       : ACL(irc_adduser)
+{
+       my ($self,$c,$msg) = @_;
+       my ($nick,$pnick) = $msg =~ /^(\w+)(?: ([^.\s]+))?$/ or die 'ARGS';
+       $pnick //= $nick;
+
+       my $dbh = $c->model;
+
+       my $host = "$pnick.users.netgamers.org";
+       my ($username,$hostname,$p_nick) = $dbh->selectrow_array(q{
+SELECT username, hostmask,pnick
+FROM users WHERE username ILIKE ? OR hostmask ILIKE ? OR pnick ILIKE ?
+               },undef,$nick,$host,$pnick);
+
+       if (defined $username){
+               $c->reply("<b>$username ($p_nick)</b> already exists with host: <b>$hostname</b>");
+       }else{
+               $dbh->do(q{
+INSERT INTO users (username,hostmask,pnick,password) VALUES(?,?,?,'')
+               },undef,$nick,$host,$pnick);
+               $c->reply("Added <b>$nick(/$pnick)</b> with host: <b>$host</b>");
+       }
+}
+
+1;
index 6771d65cf4dbd00a20912cfdaf5283b76f03f743..d3083f482ce1485a75c98e2b60709e5198b6cb12 100644 (file)
@@ -25,38 +25,8 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/addUser whois flags flag laston addPoints chattrG setHost setPNick deactivateUser getShips getFleet/;
+our @EXPORT = qw/whois flags flag laston addPoints chattrG setHost setPNick deactivateUser getShips getFleet/;
 
-sub addUser {
-       my ($msg, $command) = @_;
-
-       my ($nick,$pnick);
-       if(defined $msg && $msg =~ /^(\w+)(?: ([^.\s]+))?$/){
-               $nick = $1;
-               $pnick = $2;
-       }else{
-               $ND::server->command("notice $ND::nick syntax: .$command nick [pnick] | nick must be alphanum characters, if no pnick is given then it will be set to nick");
-               return;
-       }
-       if (hc()){
-               $pnick = $nick unless $pnick;
-               my $host = "$pnick.users.netgamers.org";
-               my ($username,$hostname,$p_nick) = $ND::DBH->selectrow_array(q{SELECT username, hostmask,pnick
-                       FROM users WHERE username ILIKE ? OR hostmask ILIKE ? OR pnick ILIKE ?}
-                       ,undef,$nick,$host,$pnick);
-               if ((not defined $username) && $ND::DBH->do("INSERT INTO users (username,hostmask,pnick,password) VALUES(?,?,?,'')"
-                               ,undef,$nick,$host,$pnick)){
-                       $ND::server->command("msg $ND::target Added $ND::B$nick(/$pnick)$ND::B with host: $ND::B$host$ND::B");
-               }elsif(defined $username){
-                       $ND::server->command("msg $ND::target $ND::B$username ($p_nick)$ND::B already exists with host: $ND::B$hostname$ND::B.");
-
-               }else{
-                       $ND::server->command("msg $ND::target Something went wrong when trying to add $ND::B$nick ($pnick)$ND::B with host: $ND::B$host$ND::B, ".$ND::DBH->errstr);
-               }
-       }else{
-               $ND::server->command("msg $ND::target Only HCs are allowed to add users");
-       }
-}
 sub whois {
        my ($msg, $command) = @_;
 
index 1a024f8648fac7217be9e94314e4154ba4623fe1..6840ee540d171d2d196bf473c33cf93e833e356a 100644 (file)
@@ -9,6 +9,7 @@ INSERT INTO roles VALUES('irc_anonscan');
 INSERT INTO roles VALUES('irc_delquote');
 INSERT INTO roles VALUES('irc_points_others');
 INSERT INTO roles VALUES('irc_sms');
+INSERT INTO roles VALUES('irc_adduser');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
@@ -19,6 +20,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_anonscan');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_delquote');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_points_others');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_sms');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_adduser');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan');
@@ -31,6 +33,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_anonscan');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_delquote');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_points_others');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_sms');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_adduser');
 
 INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others');
 
index ca09a2002a8484fb2407992687bf1fa917427cfd..79165bd1b1cfb4c330a74aeac82e904fc55cdf0d 100644 (file)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -55,7 +55,7 @@ my $TICK = $DBH->selectrow_array('SELECT tick()');
 
 my $disp = new NDIRC::Dispatcher;
 
-$disp->load('Basic','PA','Channel','Scans','Quotes','Members');
+$disp->load('Basic','PA','Channel','Scans','Quotes','Members','Usermgm');
 
 $ND::scanchan = '#testarmer';
 $disp->add_channel('#testarlite', ['pub','help','channel']);