cloudservices/src/commands/deleteaccount.ts

66 lines
3.6 KiB
TypeScript
Raw Normal View History

2019-10-28 16:21:04 -04:00
import { Message, PrivateChannel } from 'eris';
import uuid from 'uuid/v4';
2019-11-11 20:15:46 -05:00
import { Command } from '../class';
2019-10-28 17:29:06 -04:00
import { Client } from '..';
2019-10-28 16:21:04 -04:00
export default class DeleteAccount extends Command {
constructor(client: Client) {
super(client);
this.name = 'deleteaccount';
this.description = 'Delete an account on the Cloud VM';
2019-10-30 22:10:06 -04:00
this.usage = `${this.client.config.prefix}deleteaccount [User Name | User ID | Email Address] [Reason] | ${this.client.config.prefix}deleteaccount [Username] [Reason] | ${this.client.config.prefix}deleteaccount [Email] [Reason]`;
2019-10-28 16:21:04 -04:00
this.aliases = ['deleteacc', 'dacc', 'daccount', 'delete'];
this.permissions = { roles: ['475817826251440128', '525441307037007902'] };
this.guildOnly = true;
2019-10-28 16:21:04 -04:00
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[1]) 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] }, { emailAddress: args[0] }] });
2019-10-30 16:23:37 -04:00
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found.***`);
2019-10-28 16:21:04 -04:00
const { root, username, userID, emailAddress } = account;
2019-10-30 16:23:37 -04:00
if (root) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied.***`);
2019-10-28 16:21:04 -04:00
const pad = (number: number, amount: number): string => '0'.repeat(amount - number.toString().length) + number;
const randomNumber = Math.floor(Math.random() * 9999);
const verify = pad(randomNumber, 4);
try {
await this.client.util.messageCollector(message,
`***Please confirm that you are permanently deleting ${username}'s account by entering ${verify}. This action cannot be reversed.***`,
15000, true, [verify], (msg) => !(message.channel instanceof PrivateChannel && msg.author.id === message.author.id));
} catch (error) {
if (error.message.includes('Did not supply')) return message;
throw error;
}
2019-10-30 20:56:27 -04:00
const deleting = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Deleting account, please wait...***`);
2019-10-28 16:21:04 -04:00
const reason = args.slice(1).join(' ');
const logInput = { username, userID, logID: uuid(), moderatorID: message.author.id, type: 4, date: new Date(), reason: null };
if (reason) logInput.reason = reason;
2019-10-29 14:20:51 -04:00
await this.client.util.createModerationLog(args[0], message.member, 4, reason);
2019-10-30 16:19:13 -04:00
await this.client.util.deleteAccount(username);
2019-10-28 16:21:04 -04:00
this.client.util.transport.sendMail({
to: account.emailAddress,
from: 'Library of Code sp-us | Cloud Services <support@libraryofcode.org>',
subject: 'Your account has been deleted',
html: `
<h1>Library of Code | Cloud Services</h1>
2019-10-28 19:56:00 -04:00
<p>Your Cloud Account has been deleted by our Engineers. There is no way to recover your files and this decision cannot be appealed. We're sorry to see you go.</p>
2019-10-28 16:21:04 -04:00
<p><b>Reason:</b> ${reason}</p>
<p><b>Engineer:</b> ${message.author.username}</p>
<b><i>Library of Code sp-us | Support Team</i></b>
`,
});
this.client.guilds.get('446067825673633794').members.get(account.userID).removeRole('546457886440685578', `Account was deleted by ${message.author.username}.`);
2019-10-28 16:21:04 -04:00
return deleting.edit(`${this.client.stores.emojis.success} ***Account ${username} has been deleted by Engineer ${message.author.username}#${message.author.discriminator}***`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}