import { Message, PrivateChannel, GroupChannel } from 'eris'; import { Client, Command } from '../class'; export default class CreateAccount extends Command { constructor(client: Client) { super(client); this.name = 'createaccount'; this.description = 'Create an account on the Cloud VM'; this.usage = `${this.client.config.prefix}createaccount [User ID] [Email] [Account name]`; this.aliases = ['createacc', 'cacc', 'caccount', 'create']; this.permissions = { roles: ['662163685439045632', '701454780828221450'] }; this.enabled = true; } /* args[0] is the user ID args[1] is the email args[2] is the username of the account to be created */ public async run(message: Message, args: string[]) { try { if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) return message; // Stop TS being gay if (!args[2]) return this.client.commands.get('help').run(message, [this.name]); if (!message.channel.guild.members.has(args[0])) return this.error(message.channel, 'User not found.'); if (message.channel.guild.members.get(args[0]).bot) return this.error(message.channel, 'I cannot create accounts for bots.'); const checkUser = await this.client.db.Account.findOne({ userID: args[0] }); if (checkUser) return this.error(message.channel, `<@${args[0]}> already has an account.`); const checkEmail = await this.client.db.Account.findOne({ emailAddress: args[1] }); if (checkEmail) return this.error(message.channel, 'Account already exists with this email address.'); const checkAccount = await this.client.db.Account.findOne({ username: args[2] }); if (checkAccount) return this.error(message.channel, 'Account already exists with this username.'); if (!this.client.util.isValidEmail(args[1])) return this.error(message.channel, 'Invalid email address supplied.'); if (!/^[a-z][-a-z0-9]*$/.test(args[2])) return this.error(message.channel, 'Invalid username supplied.'); const confirmation = await this.loading(message.channel, 'Creating account...'); const data = await this.client.util.accounts.createAccount({ userID: args[0], username: args[2], emailAddress: args[1] }, message.author.id); message.delete(); return confirmation.edit(`${this.client.stores.emojis.success} ***Account successfully created***\n**Username:** \`${args[2]}\`\n**Temporary Password:** \`${data.tempPass}\``); } catch (error) { return this.client.util.handleError(error, message, this); } } }