]> ruin.nu Git - NDIRC.git/commitdiff
Converted the .setpnick command
authorMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 19:29:14 +0000 (21:29 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 16 May 2009 19:29:14 +0000 (21:29 +0200)
Commands/Usermgm.pm
Usermgm.pm
database/roles.sql

index 27864b94955dfca62de7bba9bad86f7982f4d58c..a8683c8c211c57e30c5012e098fe7aacea12e38e 100644 (file)
@@ -367,4 +367,40 @@ SELECT username,hostmask FROM users WHERE hostmask ILIKE $1
        $f->finish;
 }
 
+sub setpnick
+       : Help(Usage: .setpnick username pnick | Changes a user's pnick)
+       : ACL(irc_setpnick)
+{
+       my ($self,$c,$msg) = @_;
+       my ($nick,$pnick) = $msg =~ /^(\S+) (\S+)$/ or die 'ARGS';
+       my $dbh = $c->model;
+
+       my $f = $dbh->prepare(q{SELECT uid,username FROM users WHERE username ILIKE ?});
+       $f->execute($nick);
+       my $user = $f->fetchrow_hashref;
+       if ($f->rows == 1){
+               my $hostname = "$pnick.users.netgamers.org";
+               eval{
+                       $dbh->do(q{UPDATE users SET pnick = ?, hostmask = ? WHERE uid = ?}
+                               ,undef,$pnick,$hostname,$user->{uid});
+                       $c->reply("Updated <b>$user->{username}</b>'s pnick to: <b>$pnick</b> and hostname to <b>$hostname</b>");
+               };
+               if($@){
+                       if ($@ =~ /duplicate key value violates unique constraint/){
+                               my ($username, $hostname, $pnick) = $dbh->selectrow_array(q{
+SELECT username,hostmask,pnick FROM users WHERE hostmask ILIKE $1 OR pnick ILIKE $2
+                               },undef,$hostname, $pnick);
+                               $c->reply("<c04>Problem</c>, <b>$username</b> already uses host <b>$hostname</b> and pnick <b>$pnick</b>.");
+                       }else{
+                               die $@;
+                       }
+               }
+       }elsif ($f->rows == 0){
+               $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
+       }else{
+               $c->reply("More than 1 user matched, please refine the search");
+       }
+       $f->finish;
+}
+
 1;
index a38e595b77fba09411b5811b82c9f27112b3426a..dc798110bbb366ac795747d6338a27664fb4a4b3 100644 (file)
@@ -25,7 +25,7 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/addPoints setPNick/;
+our @EXPORT = qw/addPoints/;
 
 sub addPoints {
        my ($msg, $t) = @_;
@@ -75,38 +75,4 @@ sub addPoints {
        }
 }
 
-sub setPNick {
-       my ($msg, $command) = @_;
-
-       my ($nick, $pnick);
-       if(defined $msg && $msg =~ /^(\S+) ([^.\s]+)$/){
-               $nick = $1;
-               $pnick = $2;
-       }else{
-               $ND::server->command("notice $ND::nick syntax: .$command nick pnick | % can be used for wildcards \%arro% will match barrow");
-               return;
-       }
-       if (hc()){
-               my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
-               $f->execute($nick);
-               my ($uid,$nick) = $f->fetchrow();
-               if ($f->rows == 1){
-                       my ($username,$p_nick) = $ND::DBH->selectrow_array("SELECT username, pnick FROM users WHERE pnick ILIKE ? AND NOT (username ILIKE ?)",undef,$pnick,$nick);
-                       my $hostname = "$pnick.users.netgamers.org";
-                       if ((not defined $username) && $ND::DBH->do("UPDATE users SET pnick = ?, hostmask = ? WHERE uid = ?",undef,$pnick,$hostname,$uid) > 0){
-                               $ND::server->command("msg $ND::target Updated $ND::B$nick${ND::B}'s pnick to: $ND::B$pnick$ND::B and hostname to $ND::B$hostname$ND::B");
-                       }elsif(defined $username){
-                               $ND::server->command("msg $ND::target $ND::B$username$ND::B already exists with pnick $ND::B$p_nick$ND::B.");
-                       }else{
-                               $ND::server->command("msg $ND::target Couldn't update $ND::B$username${ND::B}'s host");
-                       }
-               }elsif ($f->rows == 0){
-                       $ND::server->command("msg $ND::target No hit, maybe spelling mistake, or add % as wildcard");
-               }else{
-                       $ND::server->command("msg $ND::target More than 1 user matched, please refine the search");
-               }
-               $f->finish;
-       }
-}
-
 1;
index 1c6232d85269229d6b304c849ed1ec1f94c83d59..465d0ae5e042fd003fd120bd4fe6cae8f34a3cbc 100644 (file)
@@ -19,6 +19,7 @@ INSERT INTO roles VALUES('irc_lastseen');
 INSERT INTO roles VALUES('irc_getships');
 INSERT INTO roles VALUES('irc_getfleet');
 INSERT INTO roles VALUES('irc_sethost');
+INSERT INTO roles VALUES('irc_setpnick');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
@@ -39,6 +40,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_lastseen');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_getships');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_getfleet');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_sethost');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_setpnick');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan');
@@ -61,6 +63,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_lastseen');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_getships');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_getfleet');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_sethost');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_setpnick');
 
 INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others');