fix(usermod): misc

pull/15/head
Hiroyuki 2021-09-12 23:06:02 -04:00
parent 669d9d0fef
commit 578aa0db8c
No known key found for this signature in database
GPG Key ID: AF65958B7B7362E6
1 changed files with 12 additions and 4 deletions

View File

@ -44,7 +44,7 @@ export default class Usermod extends Command {
const modifyingPropertyResponse = await this.loading(message.channel, `Modifying \`${property}\` of \`${account.username}\`'s account...`); const modifyingPropertyResponse = await this.loading(message.channel, `Modifying \`${property}\` of \`${account.username}\`'s account...`);
try { try {
await this.client.commands.get('notify') 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) { if (!account.locked) {
await account.updateOne({ locked: true }); await account.updateOne({ locked: true });
await this.client.util.exec(`lock ${account.username}`); await this.client.util.exec(`lock ${account.username}`);
@ -57,7 +57,13 @@ export default class Usermod extends Command {
username: value, username: value,
homepath: `/home/${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') 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(' ')]); .run(message, [value, ...`Your username has been successfully changed. Remember to use \`ssh ${value}@cloud.libraryofcode.org\` when logging in.`.split(' ')]);
} catch (error) { } catch (error) {
@ -66,8 +72,10 @@ export default class Usermod extends Command {
await 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.'); return this.error(message.channel, 'Failed to modify username. Please check <#595788220764127272> for more information.');
} finally { } finally {
await this.client.util.exec(`unlock ${account.username}`); if (!account.locked) {
await account.updateOne({ locked: false }); await this.client.util.exec(`unlock ${account.username}`);
await account.updateOne({ locked: false });
}
} }
modifyingPropertyResponse.delete(); modifyingPropertyResponse.delete();