import axios from 'axios'; import { Message } from 'discord.js'; import { Client, 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: ['662163685439045632'], }; this.aliases = ['cf']; this.enabled = true; } public async run(message: Message, args: string[]) { try { if (!args.length) return this.client.commands.get('help').run(message, ['cloudflare']); const msg = await this.loading(message.channel, '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); } } }