]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Usermgm.pm
Converted the .-user command
[NDIRC.git] / Commands / Usermgm.pm
index d7d86b0c007e79e480db07f9048d02a3d739609e..5ec8a2727c8eba3ff8cb286353283da4d2082bf5 100644 (file)
@@ -53,4 +53,37 @@ INSERT INTO users (username,hostmask,pnick,password) VALUES(?,?,?,'')
        }
 }
 
+sub deactivateuser
+       : Help(syntax: .-user nick | nick must be alphanum characters, if no pnick is given then it will be set to nick)
+       : Alias(-user)
+       : ACL(irc_deactivateuser)
+{
+       my ($self,$c,$msg) = @_;
+
+       my ($nick) = $msg =~ /^(\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 ($uid,$username) = $f->fetchrow();
+
+       if ($f->rows == 1){
+               my $updated = $dbh->do(q{
+UPDATE users SET hostmask = ?, password = '' WHERE uid = ?
+               },undef,$username,$uid);
+               if ($updated > 0){
+                       my $groups = $dbh->do(q{DELETE FROM groupmembers WHERE uid = ?},undef,$uid);
+                       $groups += 0;
+                       $c->reply("<b>$username</b> has been deactivated. Removed from $groups groups.");
+               }else{
+                       $c->reply("Something went wrong when trying to modify <b>$username</b>");
+               }
+       }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;