Skip to content

Commit

Permalink
switchs and record types
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstech committed Oct 22, 2023
1 parent ede779d commit 5e5abeb
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 1 deletion.
4 changes: 4 additions & 0 deletions events/ButtonEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const ChooseDeleteDomain = require("./buttons/ChooseDeleteDomain")
const CancelDeleteDomain = require("./buttons/CancelDelete")
const ConfirmDelete = require("./buttons/ConfirmDelete")
const registerDomain = require("./buttons/registerDomain")
const RecordType = require("./buttons/RecordType")
module.exports = async function (interaction) {
if (interaction.customId === "deleteDomain") {
await ChooseDeleteDomain(interaction);
Expand All @@ -18,4 +19,7 @@ module.exports = async function (interaction) {
if (interaction.customId === "tryagain") {
await registerDomain(interaction);
}
if (interaction.customId.startsWith("register-")) {
RecordType(interaction);
}
}
4 changes: 4 additions & 0 deletions events/SelectEvent.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const ChooseEmail = require("./select/ChooseEmail");
const deleteDomain = require("./select/delete");
const RecordContent = require("./select/RecordContent");
module.exports = async function (interaction) {
if (interaction.customId === "email") {
await ChooseEmail(interaction);
}
if (interaction.customId === "delete") {
await deleteDomain(interaction);
}
if (interaction.customId.startsWith("Type-")) {
await RecordContent(interaction);
}

};
51 changes: 51 additions & 0 deletions events/buttons/RecordType.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, StringSelectMenuBuilder } = require('discord.js');
module.exports = async function (interaction) {
const Domain = interaction.customId.slice(9);
console.log(Domain)
await Loading(interaction, true);

const embed = new EmbedBuilder()
.setTitle("Choose a Record Type")
.setDescription("Please choose a record type for your domain.")
.setColor("#0096ff")
.setFooter({
text: "If using github pages, choose CNAME.",
iconURL: "https://raw.githubusercontent.com/is-a-dev/register/main/media/logo.png"
});

const select = new StringSelectMenuBuilder()
.setCustomId(`Type-${Domain}`)
.setPlaceholder("Choose a record type")
.addOptions([
{
label: "A",
value: "A",
},
{
label: "AAAA",
value: "AAAA",
},
{
label: "CNAME",
value: "CNAME",
},
{
label: "MX",
value: "MX",
},
{
label: "TXT",
value: "TXT",
}
]);

const row = new ActionRowBuilder().addComponents(select);
await interaction.editReply({
embeds: [embed],
components: [row]
});
}



2 changes: 1 addition & 1 deletion events/buttons/registerDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = async function (interaction) {
.setCustomId('DomainCheck')
.setPlaceholder('Enter a subdomain')
.setMinLength(3)
.setMaxLength(100)
.setMaxLength(17)
.setRequired(true)
.setLabel('Enter the subdomain you want to register')
.setStyle("Short");
Expand Down
4 changes: 4 additions & 0 deletions events/modal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const RegisterDomain = require('./modals/RegisterDomain');
const Confirm = require('./modals/Confirm');
module.exports = async function (interaction) {
if (interaction.customId === "regiserDomain") {
await RegisterDomain(interaction);
}
if (interaction.customId.startsWith("Content-")) {
await Confirm(interaction);
}
}
52 changes: 52 additions & 0 deletions events/modals/Confirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 rawdomain = interaction.customId.slice(8)
const domain = rawdomain.slice(0, -3);
const dtype = rawdomain.substr(-1);
let type = ""
switch (dtype) {
//A Record
case '1':
type = "A"
break;
//AAAA Record
case '2':
type = "AAAA"
break;
//CNAME Record
case '3':
type = "CNAME"
break;
//MX Record
case '4':
type = "MX"
break;
//TXT Record
case '5':
type = "TXT"
break;
}
const content = interaction.fields.getTextInputValue(`Content`)
const embed = new EmbedBuilder()
.setTitle('Confirm Domain')
.setDescription('This is the information you have entered. Please confirm that it is correct. \n\n' + `**Domain:** ${domain}.is-a.dev \n**Type:** ${type} \n**Content:** ${content}`)
.setColor('#0096ff')
const confirm = new ButtonBuilder()
.setCustomId(`confirm-${domain}`)
.setLabel("Confirm")
.setStyle(ButtonStyle.Primary);
const cancel = new ButtonBuilder()
.setCustomId(`cancel-${domain}`)
.setLabel("Cancel")
.setStyle(ButtonStyle.Primary);
const row = new ActionRowBuilder().addComponents(confirm, cancel);
await interaction.editReply({
components: [row],
ephemeral: true,
embeds: [embed]
});
}


4 changes: 4 additions & 0 deletions events/modals/RegisterDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const { EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowB
module.exports = async function (interaction) {
await Loading(interaction, true);
const subdomain = interaction.fields.getTextInputValue("DomainCheck");
// remove .is-a.dev if it exists
if (subdomain.endsWith(".is-a.dev")) {
subdomain = subdomain.slice(0, -8);
}
const response = await fetch(
`https://api.github.com/repos/is-a-dev/register/contents/domains/${subdomain}.json`,
{
Expand Down
44 changes: 44 additions & 0 deletions events/select/RecordContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const Loading = require('../../components/loading');
const { EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require('discord.js');
module.exports = async function (interaction) {
const type = interaction.values[0];
let typeNum = 0;
switch (type) {
//A Record
case 'A':
typeNum = 1;
break;
//AAAA Record
case 'AAAA':
typeNum = 2;
break;
//CNAME Record
case 'CNAME':
typeNum = 3;
break;
//MX Record
case 'MX':
typeNum = 4;
break;
//TXT Record
case 'TXT':
typeNum = 5;
break;
}

const domain = interaction.customId.slice(5);
const register = new ModalBuilder().setTitle('Register a Domain').setCustomId(`Content-${domain}-t${typeNum}`)
const content = new TextInputBuilder()
.setCustomId(`Content`)
.setPlaceholder('Enter the content')
.setMinLength(1)
.setMaxLength(100)
.setRequired(true)
.setLabel('Enter the content for the record. ')
.setStyle("Short");

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

}

0 comments on commit 5e5abeb

Please sign in to comment.