diff --git a/src/commands/cloudflare.ts b/src/commands/cloudflare.ts new file mode 100644 index 0000000..9be5417 --- /dev/null +++ b/src/commands/cloudflare.ts @@ -0,0 +1,40 @@ +import { Message } from 'eris'; +import axios from 'axios'; +import { Client } from '..'; +import { Command } from '../class'; + +export default class Cloudflare extends Command { + constructor(client: Client) { + super(client); + this.name = 'cloudflare'; + this.description = 'Remove an entry from Cloudflare DNS records'; + this.permissions = { + roles: ['525441307037007902'], + }; + this.aliases = ['cf']; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Locating entry...***`); + const { data } = await axios({ + method: 'get', + url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records?name=${args[0]}`, + headers: { Authorization: `Bearer ${this.client.config.cloudflare}` }, + }); + if (!data.result.length) return msg.edit(`${this.client.stores.emojis.error} ***Entry not found***`); + msg.edit(`${this.client.stores.emojis.success} ***Located entry***\n${this.client.stores.emojis.loading} ***Deleting entry...***`); + const { id }: { id: string } = data.result[0]; + await axios({ + method: 'delete', + url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records/${id}`, + headers: { Authorization: `Bearer ${this.client.config.cloudflare}` }, + }); + this.client.commands.get('cwg').subcommands.get('create').enabled = true; + return msg.edit(`${this.client.stores.emojis.success} ***Located entry***\n${this.client.stores.emojis.success} ***Deleted entry***`); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index 0abb76d..eb05106 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,5 +1,6 @@ export { default as announce } from './announce'; export { default as bearer } from './bearer'; +export { default as cloudflare } from './cloudflare'; export { default as createaccount } from './createaccount'; export { default as cwg } from './cwg'; export { default as deleteaccount } from './deleteaccount';