X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FUsermgm.pm;fp=Commands%2FUsermgm.pm;h=a8683c8c211c57e30c5012e098fe7aacea12e38e;hb=46d32b072c0eb2c390a981616bdec029eb179d1d;hp=27864b94955dfca62de7bba9bad86f7982f4d58c;hpb=e053b73d5ae0ca68e4f40463450fe2fae0ae737a;p=NDIRC.git diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm index 27864b9..a8683c8 100644 --- a/Commands/Usermgm.pm +++ b/Commands/Usermgm.pm @@ -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 $user->{username}'s pnick to: $pnick and hostname to $hostname"); + }; + 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("Problem, $username already uses host $hostname and pnick $pnick."); + }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;