|
| 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