-
-
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.
Merge pull request #14 from andrewstech/main
chore: Add decode command for staff to lookup user information
- Loading branch information
Showing
3 changed files
with
167 additions
and
0 deletions.
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
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, | ||
}); | ||
} | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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