From 578aa0db8c81b7fcb5b4f3d57b35cbf0acb6873b Mon Sep 17 00:00:00 2001 From: Hiroyuki Date: Sun, 12 Sep 2021 23:06:02 -0400 Subject: [PATCH] fix(usermod): misc --- src/commands/usermod.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/commands/usermod.ts b/src/commands/usermod.ts index 5572355..246f276 100644 --- a/src/commands/usermod.ts +++ b/src/commands/usermod.ts @@ -44,7 +44,7 @@ export default class Usermod extends Command { const modifyingPropertyResponse = await this.loading(message.channel, `Modifying \`${property}\` of \`${account.username}\`'s account...`); try { await this.client.commands.get('notify') - .run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`. DN/C`.split(' ')]); + .run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`.`.split(' ')]); if (!account.locked) { await account.updateOne({ locked: true }); await this.client.util.exec(`lock ${account.username}`); @@ -57,7 +57,13 @@ export default class Usermod extends Command { username: value, homepath: `/home/${value}`, }); - await this.client.db.Moderation.updateMany({ username: account.username }, { username: value }); + await this.client.db.Moderation.updateMany( + { + username: account.username, + date: { $gt: account.createdAt }, + }, + { username: value }, + ); await this.client.commands.get('notify') .run(message, [value, ...`Your username has been successfully changed. Remember to use \`ssh ${value}@cloud.libraryofcode.org\` when logging in.`.split(' ')]); } catch (error) { @@ -66,8 +72,10 @@ export default class Usermod extends Command { 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}`); - await account.updateOne({ locked: false }); + if (!account.locked) { + await this.client.util.exec(`unlock ${account.username}`); + await account.updateOne({ locked: false }); + } } modifyingPropertyResponse.delete();