From fe9fe90fb0d7989b22c95caec202b56c02e15407 Mon Sep 17 00:00:00 2001 From: bmonish Date: Sun, 21 Jan 2024 11:36:26 +0530 Subject: [PATCH] feat: Added Command to Generate Secrets --- src/commands/generate.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/commands/generate.ts b/src/commands/generate.ts index c45aa99..1cbdf01 100644 --- a/src/commands/generate.ts +++ b/src/commands/generate.ts @@ -1,7 +1,9 @@ import { CacheType, Interaction } from "discord.js"; import { v4 as uuidV4 } from "uuid"; +import crypto from "crypto"; const RANDOM_UUID = "RANDOM_UUID"; +const SECRET_STRING = "SECRET_STRING"; export const generateCommand = { name: "generate", @@ -12,7 +14,16 @@ export const generateCommand = { description: "The type of value to generate", required: true, type: 3, - choices: [{ name: "Random UUID", value: RANDOM_UUID }], + choices: [ + { name: "Random UUID", value: RANDOM_UUID }, + { name: "Secret String", value: SECRET_STRING }, + ], + }, + { + name: "length", + description: "The length of the secret string (default: 32)", + required: false, + type: 4, }, ], @@ -30,6 +41,11 @@ export const generateCommand = { await interaction.reply(uuidV4()); break; } + case SECRET_STRING: { + const len = (options.get("length")?.value as number) || 32; + await interaction.reply(crypto.randomBytes(len).toString("hex")); + break; + } } } },