Add delete subcommand on CWG

merge-requests/1/merge
Matthew 2019-10-29 19:12:36 -04:00
parent ef05fc5891
commit a017bf6a2e
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 17 additions and 0 deletions

View File

@ -101,6 +101,23 @@ export default class CWG extends Command {
embed.setTimestamp();
// @ts-ignore
message.channel.createMessage({ embed });
} else if (args[0] === 'delete') {
if (!args[1]) return this.client.commands.get('help').run(message, [this.name]);
const domain = await this.client.db.Domain.findOne({ $or: [{ domain: args[1] }, { port: Number(args[1]) || '' }] });
if (!domain) return message.channel.createMessage(`***${this.client.stores.emojis.error} The domain or port you provided could not be found.***`);
await fs.unlink(`/etc/nginx/sites-available/${domain.domain}`);
await fs.unlink(`/etc/nginx/sites-enabled/${domain}`);
const embed = new RichEmbed();
embed.setTitle('Domain Deletion');
embed.addField('Account Username', domain.account.username, true);
embed.addField('Account ID', domain.account.userID, true);
embed.addField('Domain', domain.domain, true);
embed.addField('Port', String(domain.port), true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
// @ts-ignore
message.channel.createMessage({ embed });
await this.client.db.Domain.deleteOne({ domain: domain.domain });
} else { message.channel.createMessage(`${this.client.stores.emojis.error} Not a valid subcommand.`); }
return true;
} catch (error) {