-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
andrewstech
committed
Oct 28, 2023
1 parent
72033b2
commit 2644b2d
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
}, | ||
}; |