Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 611149d

Browse files
author
andrewstech
committed
feat: Add OWL button to whois command
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]
1 parent d4f7bfb commit 611149d

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

commands/whois.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ module.exports = {
141141
.setEmoji("🐙")
142142
.setURL(fileURL);
143143

144-
const row = new ActionRowBuilder().addComponents(webButton, GitHubButton);
144+
const OwlButton = new ButtonBuilder()
145+
.setStyle(ButtonStyle.Primary)
146+
.setLabel("OWL")
147+
setCustomId(`owl-${domain}`)
148+
.setEmoji("🦉");
149+
150+
const row = new ActionRowBuilder().addComponents(webButton, GitHubButton, OwlButton);
145151

146152
await interaction.editReply({ embeds: [embed], ephemeral: ephemeral, components: [row] });
147153
}

events/ButtonEvent.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const RecordType = require("./buttons/RecordType")
66
const ConfirmRegister = require("./buttons/ConfirmRegister")
77
const Cancel = require("./buttons/Cancel")
88
const AproveApeal = require("./buttons/AproveApeal")
9+
const Owl = require("./buttons/Owl")
910
module.exports = async function (interaction) {
1011
if (interaction.customId === "deleteDomain") {
1112
await ChooseDeleteDomain(interaction);
@@ -25,6 +26,9 @@ module.exports = async function (interaction) {
2526
if (interaction.customId.startsWith("register-")) {
2627
RecordType(interaction);
2728
}
29+
if (interaction.customId.startsWith("owl-")) {
30+
Owl(interaction);
31+
}
2832
if (interaction.customId.startsWith("confirm-d")) {
2933
ConfirmRegister(interaction);
3034
}

events/buttons/Owl.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const { SlashCommandBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require("discord.js");
2+
const Loading = require('../../components/loading');
3+
const staff = require('../../models/staff');
4+
const { EncryptPayload, DecryptPayload } = require("../../components/owl");
5+
6+
async function fetchDomainData(domain) {
7+
const response = await fetch(
8+
`https://raw.githubusercontent.com/is-a-dev/register/main/domains/${domain}.json`,
9+
{
10+
headers: {
11+
"User-Agent": "is-a-dev-bot",
12+
},
13+
},
14+
);
15+
16+
if (response.status === 404) {
17+
return null;
18+
}
19+
return await response.json();
20+
}
21+
22+
async function sendEmbed(interaction, description, color = "#0096ff", ephemeral = false) {
23+
const embed = new EmbedBuilder().setDescription(description).setColor(color);
24+
await interaction.editReply({ embeds: [embed], ephemeral: ephemeral });
25+
}
26+
27+
module.exports = async function (interaction) {
28+
await Loading(interaction, true);
29+
const inputString = interaction.customId;
30+
const regex = /owl-(.*?)/;
31+
const match = regex.exec(inputString);
32+
33+
if (!match) {
34+
return sendEmbed(interaction, "Invalid domain identifier.", "#ff0000", true);
35+
}
36+
37+
const domain = match[1];
38+
console.log(domain);
39+
40+
const staffData = await staff.findOne({ _id: interaction.user.id });
41+
if (!staffData) {
42+
return sendEmbed(interaction, "You are not staff!");
43+
}
44+
45+
const domainData = await fetchDomainData(domain);
46+
if (!domainData) {
47+
return sendEmbed(interaction, "That domain doesn't exist in the register.", true);
48+
}
49+
50+
if (!domainData.owner.OWL) {
51+
return sendEmbed(interaction, "That domain doesn't have an OWL field.", true);
52+
}
53+
54+
try {
55+
const decoded = await DecryptPayload(domainData.owner.OWL);
56+
const userd = JSON.parse(decoded);
57+
const username = userd.username;
58+
const email = userd.email;
59+
const user_id = userd.user_id;
60+
const embed = new EmbedBuilder()
61+
.setTitle("User Information")
62+
.setColor("#0096ff")
63+
.setDescription(`\n**Decoded:** \n\nUsername: ${username}\nEmail: ${email}\nUser ID: ${user_id}`);
64+
await interaction.editReply({ embeds: [embed] });
65+
} catch (error) {
66+
console.error("Error decrypting payload:", error);
67+
return sendEmbed(interaction, "Failed to decrypt OWL data.", "#ff0000", true);
68+
}
69+
}

0 commit comments

Comments
 (0)