From d4c740206d568d09f4180f66cb364f438135433b Mon Sep 17 00:00:00 2001 From: Hiroyuki Date: Sun, 12 Sep 2021 21:52:03 -0400 Subject: [PATCH] refactor: usermod account lock logic --- src/commands/usermod.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/commands/usermod.ts b/src/commands/usermod.ts index 06eebfa..d8e6c0d 100644 --- a/src/commands/usermod.ts +++ b/src/commands/usermod.ts @@ -45,7 +45,10 @@ export default class Usermod extends Command { try { await this.client.commands.get('notify') .run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`. DN/C`.split(' ')]); - await this.client.util.exec(`lock ${account.username}`); + if (!account.locked) { + await account.updateOne({ locked: true }); + await this.client.util.exec(`lock ${account.username}`); + } await this.client.util.exec(`usermod -l ${value} ${account.username}`); await this.client.util.exec(`usermod -d /home/${value} ${value}`); @@ -59,10 +62,13 @@ export default class Usermod extends Command { } catch (error) { await this.client.commands.get('notify') .run(message, [account.username, ...'Your username change was unsuccessful. Please contact a Technician for more details.'.split(' ')]); - this.error(message.channel, 'Failed to modify username.'); - return this.client.util.handleError(error); + await this.client.util.handleError(error); + return this.error(message.channel, 'Failed to modify username. Please check <#595788220764127272> for more information.'); } finally { - await this.client.util.exec(`unlock ${account.username}`); + if (account.locked) { + await this.client.util.exec(`unlock ${account.username}`); + await account.updateOne({ locked: false }); + } } modifyingPropertyResponse.delete();