1
0
Fork 0

if is cloud domain, delete dns record

refactor/models
Matthew 2019-10-29 19:37:27 -04:00
parent 20337f7215
commit 506e080394
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 7 additions and 3 deletions

View File

@ -53,6 +53,7 @@ export default class CWG extends Command {
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp(new Date(message.timestamp)); embed.setTimestamp(new Date(message.timestamp));
message.delete(); message.delete();
await this.client.util.exec('systemctl reload nginx');
edit.edit(`***${this.client.stores.emojis.success} Successfully binded ${domain.domain} to port ${domain.port} for ${account.userID}.***`); edit.edit(`***${this.client.stores.emojis.success} Successfully binded ${domain.domain} to port ${domain.port} for ${account.userID}.***`);
// @ts-ignore // @ts-ignore
this.client.createMessage('580950455581147146', { embed }); this.client.createMessage('580950455581147146', { embed });
@ -102,11 +103,10 @@ export default class CWG extends Command {
// @ts-ignore // @ts-ignore
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
} else if (args[0] === 'delete') { } else if (args[0] === 'delete') {
const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Deleting domain...`);
if (!args[1]) return this.client.commands.get('help').run(message, [this.name]); 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]) || '' }] }); 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.***`); 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(); const embed = new RichEmbed();
embed.setTitle('Domain Deletion'); embed.setTitle('Domain Deletion');
embed.addField('Account Username', domain.account.username, true); embed.addField('Account Username', domain.account.username, true);
@ -128,9 +128,13 @@ export default class CWG extends Command {
headers: { Authorization: `Bearer ${this.client.config.cloudflare}` }, headers: { Authorization: `Bearer ${this.client.config.cloudflare}` },
}); });
} }
await fs.unlink(`/etc/nginx/sites-available/${domain.domain}`);
await fs.unlink(`/etc/nginx/sites-enabled/${domain}`);
await this.client.db.Domain.deleteOne({ domain: domain.domain });
await this.client.util.exec('systemctl reload nginx');
edit.edit(`***${this.client.stores.emojis.success} Domain ${domain.domain} with port ${domain.port} has been successfully deleted.***`);
// @ts-ignore // @ts-ignore
message.channel.createMessage({ embed }); 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.`); } } else { message.channel.createMessage(`${this.client.stores.emojis.error} Not a valid subcommand.`); }
return true; return true;
} catch (error) { } catch (error) {