Skip to content

Commit

Permalink
Start Register command
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstech committed Oct 22, 2023
1 parent 4578adc commit ede779d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
11 changes: 11 additions & 0 deletions commands/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { SlashCommandBuilder } = require("discord.js");
const regiserDomain = require("../events/buttons/registerDomain");

module.exports = {
data: new SlashCommandBuilder()
.setName("register")
.setDescription("Register a domain."),
async execute(interaction) {
await regiserDomain(interaction);
},
};
7 changes: 7 additions & 0 deletions events/ButtonEvent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const ChooseDeleteDomain = require("./buttons/ChooseDeleteDomain")
const CancelDeleteDomain = require("./buttons/CancelDelete")
const ConfirmDelete = require("./buttons/ConfirmDelete")
const registerDomain = require("./buttons/registerDomain")
module.exports = async function (interaction) {
if (interaction.customId === "deleteDomain") {
await ChooseDeleteDomain(interaction);
Expand All @@ -11,4 +12,10 @@ module.exports = async function (interaction) {
if (interaction.customId.startsWith("del-")) {
ConfirmDelete(interaction);
}
if (interaction.customId === "registerDomain") {
await registerDomain(interaction);
}
if (interaction.customId === "tryagain") {
await registerDomain(interaction);
}
}
22 changes: 22 additions & 0 deletions events/buttons/registerDomain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Loading = require('../../components/loading');
const { EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require('discord.js');
module.exports = async function (interaction) {
const register = new ModalBuilder().setTitle('Register a Domain').setCustomId('regiserDomain')

const domainCheck = new TextInputBuilder()
.setCustomId('DomainCheck')
.setPlaceholder('Enter a subdomain')
.setMinLength(3)
.setMaxLength(100)
.setRequired(true)
.setLabel('Enter the subdomain you want to register')
.setStyle("Short");


const row = new ActionRowBuilder().addComponents(domainCheck);
register.addComponents(row);
await interaction.showModal(register);



}
6 changes: 6 additions & 0 deletions events/modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const RegisterDomain = require('./modals/RegisterDomain');
module.exports = async function (interaction) {
if (interaction.customId === "regiserDomain") {
await RegisterDomain(interaction);
}
}
51 changes: 51 additions & 0 deletions events/modals/RegisterDomain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const Loading = require('../../components/loading');
const { EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
module.exports = async function (interaction) {
await Loading(interaction, true);
const subdomain = interaction.fields.getTextInputValue("DomainCheck");
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 embed = new EmbedBuilder()
// domain is available
.setDescription(`Congratulations, ${subdomain}.is-a.dev is available!`)
.setColor("#0096ff");
const button = new ButtonBuilder()
.setCustomId(`register-${subdomain}`)
.setLabel("Register IT")
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder().addComponents(button);
await interaction.editReply({
components: [row],
ephemeral: true,
embeds: [embed]
});
} else {
const sadEmbed = new EmbedBuilder()
// domain is taken
.setDescription(`Sorry, ${subdomain}.is-a.dev is taken!`)
.setColor("#0096ff");

const tryagin = new ButtonBuilder()
.setCustomId(`tryagain`)
.setLabel("Try Again")
.setStyle(ButtonStyle.Primary);

const sadrow = new ActionRowBuilder().addComponents(tryagin);
await interaction.editReply({
components: [sadrow],
ephemeral: true,
embeds: [sadEmbed]
});

}
}
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Sentry = require("@sentry/node");
const keepAlive = require("./components/webServer.js");
const HandleSelectMenu = require("./events/SelectEvent.js");
const HandleButtonEvent = require("./events/ButtonEvent.js");
const HandleModalEvent = require("./events/modal.js");
require("dotenv").config();

Sentry.init({
Expand Down Expand Up @@ -64,6 +65,10 @@ client.on(Events.InteractionCreate, async (interaction) => {
HandleButtonEvent(interaction);
return;
}
if (interaction.isModalSubmit()) {
HandleModalEvent(interaction);
return;
}

if (!command) {
console.error(
Expand Down

0 comments on commit ede779d

Please sign in to comment.