Skip to content

Commit

Permalink
Merge pull request #14 from andrewstech/main
Browse files Browse the repository at this point in the history
chore: Add decode command for staff to lookup user information
  • Loading branch information
andrewstech authored Jul 19, 2024
2 parents b9825f9 + df325d0 commit d001000
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
61 changes: 61 additions & 0 deletions commands/decode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { SlashCommandBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require("discord.js");
const fetch = require("node-fetch");
const staff = require("../models/staff");
const Loading = require("../components/loading");
const jwt = require("jsonwebtoken");



module.exports = {
data: new SlashCommandBuilder()
.setName("decode")
.setDescription("[MAINTAINER] Lookup a user's information.")
.addStringOption((option) =>
option
.setName("key")
.setDescription("The key to lookup.")
.setRequired(true),
)
.addStringOption((option) =>
option
.setName("id")
.setDescription("The Github Id")
.setRequired(true),
),


async execute(interaction) {


await Loading(interaction, ephemeral);

if (!(await staff.findOne({ _id: interaction.user.id }))) {
const embed = new EmbedBuilder()
.setDescription("Only staff can use this command!")
.setColor("#0096ff");
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}


try {
const key = interaction.options.getString("key");
const id = interaction.options.getString("id");
const secretKey = process.env.ENCRYPTION_KEY;
const decodeKey = secretKey + id;
const decoded = jwt.verify(key, decodeKey);
const embed = new EmbedBuilder()
.setTitle("Decoded Key")
.setColor("#0096ff")
.addField("Decoded Key", JSON.stringify(decoded, null, 2));
await interaction.editReply({ embeds: [embed] });

} catch (error) {
console.error("Error performing lookup:", error);
await interaction.editReply({
content:
"An error occurred while performing the lookup. Please try again later.",
ephemeral: true,
});
}
},
};
105 changes: 105 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.2",
"mailcow-api": "^1.2.7",
"mongodb": "^6.2.0",
"mongoose": "^7.2.1",
Expand Down

0 comments on commit d001000

Please sign in to comment.