-
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 22, 2023
1 parent
a2fb61e
commit 72033b2
Showing
1 changed file
with
65 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,65 @@ | ||
const fetch = require("node-fetch"); | ||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js"); | ||
|
||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName("check") | ||
.setDescription("Check if a domain is available.") | ||
.addStringOption((option) => | ||
option | ||
.setName("subdomain") | ||
.setDescription("The subdomain to check.") | ||
.setRequired(true), | ||
), | ||
async execute(interaction) { | ||
const subdomain = interaction.options | ||
.getString("subdomain") | ||
.toLowerCase(); | ||
// get the guild id from the interaction | ||
|
||
|
||
if (subdomain.length < 2 || subdomain.length > 64) { | ||
const sadEmbed = new EmbedBuilder() | ||
.setDescription("The subdomain length must be between 2 and 64 characters.") | ||
.setColor("#0096ff"); | ||
return await interaction.reply({ embeds: [sadEmbed] }); | ||
} | ||
|
||
try { | ||
const response = await fetch( | ||
`https://api.github.com/repos/is-a-dev/register/contents/domains/${subdomain}.json`, | ||
{ | ||
headers: { | ||
"User-Agent": "is-a-dev-bot", | ||
}, | ||
cache: "no-cache", | ||
}, | ||
); | ||
|
||
if (response.status === 404) { | ||
const happyEmbed = new EmbedBuilder() | ||
.setDescription(`Congratulations, ${subdomain}.is-a.dev is available!`) | ||
.setColor("#0096ff"); | ||
await interaction.reply({ embeds: [happyEmbed] } | ||
); | ||
} else { | ||
const sadEmbed = new EmbedBuilder() | ||
.setDescription(`Sorry, ${subdomain}.is-a.dev is taken!`) | ||
.setColor("#0096ff"); | ||
await interaction.reply({ embeds: [sadEmbed] } | ||
); | ||
} | ||
} catch (error) { | ||
console.error( | ||
"Error occurred while checking domain availability:", | ||
error, | ||
); | ||
const sadEmbed = new EmbedBuilder() | ||
.setDescription("An error occurred while checking domain availability.") | ||
.setColor("#0096ff"); | ||
await interaction.reply({ embeds: [sadEmbed] | ||
}); | ||
} | ||
}, | ||
}; |