cloudservices/src/commands/unlock.ts

32 lines
1.6 KiB
TypeScript

import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Unlock extends Command {
constructor(client: Client) {
super(client);
this.name = 'unlock';
this.description = 'Unlocks an account.';
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
this.enabled = true;
}
public async run(message: Message, args: string[]) { // eslint-disable-line
try {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userId: args[0].replace(/[<@!>]/gi, '') }] });
if (!account) return this.error(message.channel, 'Cannot find user.');
if (!account.locked) return this.error(message.channel, 'This account is already unlocked.');
const edit = await this.loading(message.channel, 'Unlocking account...');
if (account.username === 'matthew' || account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`);
await this.client.util.exec(`unlock ${account.username}`);
await account.updateOne({ locked: false });
await this.client.util.createModerationLog(account.userId, message.author, 3, args.slice(1).join(' '));
message.delete();
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been unlocked by Technician ${message.author.username}#${message.author.discriminator}.***`);
} catch (error) {
await this.client.util.handleError(error, message, this);
}
}
}