-
-
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.
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]
- Loading branch information
andrewstech
committed
Jul 29, 2024
1 parent
d4f7bfb
commit 611149d
Showing
3 changed files
with
80 additions
and
1 deletion.
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
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
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,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); | ||
} | ||
} |