Skip to content

Commit

Permalink
feat: Add OWL button to whois command
Browse files Browse the repository at this point in the history
This commit adds an OWL button to the whois command. The OWL button is created in the `whois.js` file and added to the action row component. When the OWL button is clicked, it triggers the `Owl` function in the `ButtonEvent.js` file. The `Owl` function fetches the domain data, checks if the user is a staff member, and then decrypts and displays the OWL data in an embed.

Co-authored-by: [Author Name]
  • Loading branch information
andrewstech committed Jul 29, 2024
1 parent d4f7bfb commit 611149d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
8 changes: 7 additions & 1 deletion commands/whois.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ module.exports = {
.setEmoji("🐙")
.setURL(fileURL);

const row = new ActionRowBuilder().addComponents(webButton, GitHubButton);
const OwlButton = new ButtonBuilder()
.setStyle(ButtonStyle.Primary)
.setLabel("OWL")
setCustomId(`owl-${domain}`)
.setEmoji("🦉");

const row = new ActionRowBuilder().addComponents(webButton, GitHubButton, OwlButton);

await interaction.editReply({ embeds: [embed], ephemeral: ephemeral, components: [row] });
}
Expand Down
4 changes: 4 additions & 0 deletions events/ButtonEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const RecordType = require("./buttons/RecordType")
const ConfirmRegister = require("./buttons/ConfirmRegister")
const Cancel = require("./buttons/Cancel")
const AproveApeal = require("./buttons/AproveApeal")
const Owl = require("./buttons/Owl")
module.exports = async function (interaction) {
if (interaction.customId === "deleteDomain") {
await ChooseDeleteDomain(interaction);
Expand All @@ -25,6 +26,9 @@ module.exports = async function (interaction) {
if (interaction.customId.startsWith("register-")) {
RecordType(interaction);
}
if (interaction.customId.startsWith("owl-")) {
Owl(interaction);
}
if (interaction.customId.startsWith("confirm-d")) {
ConfirmRegister(interaction);
}
Expand Down
69 changes: 69 additions & 0 deletions events/buttons/Owl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { SlashCommandBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require("discord.js");
const Loading = require('../../components/loading');
const staff = require('../../models/staff');
const { EncryptPayload, DecryptPayload } = require("../../components/owl");

async function fetchDomainData(domain) {
const response = await fetch(
`https://raw.githubusercontent.com/is-a-dev/register/main/domains/${domain}.json`,
{
headers: {
"User-Agent": "is-a-dev-bot",
},
},
);

if (response.status === 404) {
return null;
}
return await response.json();
}

async function sendEmbed(interaction, description, color = "#0096ff", ephemeral = false) {
const embed = new EmbedBuilder().setDescription(description).setColor(color);
await interaction.editReply({ embeds: [embed], ephemeral: ephemeral });
}

module.exports = async function (interaction) {
await Loading(interaction, true);
const inputString = interaction.customId;
const regex = /owl-(.*?)/;
const match = regex.exec(inputString);

if (!match) {
return sendEmbed(interaction, "Invalid domain identifier.", "#ff0000", true);
}

const domain = match[1];
console.log(domain);

const staffData = await staff.findOne({ _id: interaction.user.id });
if (!staffData) {
return sendEmbed(interaction, "You are not staff!");
}

const domainData = await fetchDomainData(domain);
if (!domainData) {
return sendEmbed(interaction, "That domain doesn't exist in the register.", true);
}

if (!domainData.owner.OWL) {
return sendEmbed(interaction, "That domain doesn't have an OWL field.", true);
}

try {
const decoded = await DecryptPayload(domainData.owner.OWL);
const userd = JSON.parse(decoded);
const username = userd.username;
const email = userd.email;
const user_id = userd.user_id;
const embed = new EmbedBuilder()
.setTitle("User Information")
.setColor("#0096ff")
.setDescription(`\n**Decoded:** \n\nUsername: ${username}\nEmail: ${email}\nUser ID: ${user_id}`);
await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error("Error decrypting payload:", error);
return sendEmbed(interaction, "Failed to decrypt OWL data.", "#ff0000", true);
}
}

0 comments on commit 611149d

Please sign in to comment.