From 2644b2deea589f942fbcba8efd38bded603208fc Mon Sep 17 00:00:00 2001 From: andrewstech Date: Sat, 28 Oct 2023 10:16:15 +0000 Subject: [PATCH] activate command --- commands/activate.js | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 commands/activate.js diff --git a/commands/activate.js b/commands/activate.js new file mode 100644 index 0000000..4c35607 --- /dev/null +++ b/commands/activate.js @@ -0,0 +1,66 @@ +const fetch = require("node-fetch"); +const { SlashCommandBuilder } = require("discord.js"); +const staff = require("../models/staff"); +const Loading = require("../components/loading"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("activate") + .setDescription("Activate a hosts by is-a.dev domain.") + .addStringOption((option) => + option + .setName("subdomain") + .setDescription("The subdomain to activate.") + .setRequired(true), + ), + async execute(interaction) { + const subdomain = interaction.options + .getString("subdomain") + .toLowerCase(); + + await Loading(interaction, false); + + if (!(await staff.findOne({ _id: interaction.user.id }))) { + const embed = new EmbedBuilder() + .setDescription("Only staff can use this command!") + .setColor("#0096ff"); + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } + + if (subdomain.length < 2 || subdomain.length > 64) + return await interaction.reply( + "The subdomain length must be between 2 and 64 characters.", + ); + + try { + const response = await fetch( + `https://hosts.is-a.dev/api/activate?domain=${subdomain}&NOTIFY_TOKEN=${process.env.WEBHOST_TOKEN}`, + { + headers: { + "User-Agent": "is-a-dev-bot", + }, + }, + ); + + if (response.status === 200) { + await interaction.reply( + `${subdomain}.is-a.dev has been activated!`, + ); + } else { + await interaction.reply( + `Dam something went wrong. The server responded with ${response.status} speak to andrew or Danny`, + ); + } + } catch (error) { + console.error( + "Error occurred while checking domain availability:", + error, + ); + await interaction.reply({ + content: + "An error occurred while checking the domain activation. Please try again later.", + ephemeral: true, + }); + } + }, +};