2019-12-09 05:07:59 -05:00
|
|
|
import { Message, PrivateChannel, GroupChannel } from 'eris';
|
2019-10-28 17:29:06 -04:00
|
|
|
import { Client } from '..';
|
2019-10-26 21:08:42 -04:00
|
|
|
import { Command, RichEmbed } 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';
|
2019-10-28 17:29:06 -04:00
|
|
|
this.usage = `${this.client.config.prefix}createaccount [User ID] [Email] [Account name]`;
|
2019-10-27 11:18:18 -04:00
|
|
|
this.aliases = ['createacc', 'cacc', 'caccount', 'create'];
|
2020-03-28 12:10:09 -04:00
|
|
|
this.permissions = { roles: ['662163685439045632', '455972169449734144'] };
|
2019-10-26 21:08:42 -04:00
|
|
|
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 {
|
2019-12-09 05:07:59 -05:00
|
|
|
if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) return message; // Stop TS being gay
|
2019-10-26 21:08:42 -04:00
|
|
|
if (!args[2]) return this.client.commands.get('help').run(message, [this.name]);
|
2020-03-29 04:32:17 -04:00
|
|
|
if (!message.channel.guild.members.has(args[0])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***User not found.***`);
|
|
|
|
if (message.channel.guild.members.get(args[0]).bot) return message.channel.createMessage(`${this.client.stores.emojis.error} ***I cannot create accounts for bots.***`);
|
2019-10-26 21:08:42 -04:00
|
|
|
const checkUser = await this.client.db.Account.findOne({ userID: args[0] });
|
2020-03-29 04:32:17 -04:00
|
|
|
if (checkUser) return message.channel.createMessage(`${this.client.stores.emojis.error} ***<@${args[0]}> already has an account.***`);
|
2019-10-26 21:08:42 -04:00
|
|
|
const checkEmail = await this.client.db.Account.findOne({ emailAddress: args[1] });
|
2020-03-29 04:32:17 -04:00
|
|
|
if (checkEmail) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account already exists with this email address.***`);
|
2019-10-26 21:08:42 -04:00
|
|
|
const checkAccount = await this.client.db.Account.findOne({ username: args[2] });
|
2020-03-29 04:32:17 -04:00
|
|
|
if (checkAccount) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account already exists with this username.***`);
|
2019-10-26 21:08:42 -04:00
|
|
|
|
2020-03-29 04:32:17 -04:00
|
|
|
if (!this.client.util.isValidEmail(args[1])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid email address supplied.***`);
|
|
|
|
if (!/^[a-z][-a-z0-9]*$/.test(args[2])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid username supplied.***`);
|
2019-10-26 21:08:42 -04:00
|
|
|
|
|
|
|
const confirmation = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Creating account...***`);
|
2020-03-28 04:57:24 -04:00
|
|
|
const data = await this.client.util.accounts.createAccount({ userID: args[0], username: args[2], emailAddress: args[1] }, message.author.id);
|
2019-10-26 21:08:42 -04:00
|
|
|
|
2020-03-28 04:57:24 -04:00
|
|
|
return confirmation.edit(`${this.client.stores.emojis.success} ***Account successfully created***\n**Username:** \`${args[2]}\`\n**Temporary Password:** \`${data.tempPass}\``);
|
2019-10-26 21:08:42 -04:00
|
|
|
} catch (error) {
|
|
|
|
return this.client.util.handleError(error, message, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|