Skip to content

Commit

Permalink
activate command
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstech committed Oct 28, 2023
1 parent 72033b2 commit 2644b2d
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions commands/activate.js
Original file line number Diff line number Diff line change
@@ -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,
});
}
},
};

0 comments on commit 2644b2d

Please sign in to comment.