Init
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { cd } from "..";
|
||||
import { ConsoleCommandData } from "../types/Command";
|
||||
|
||||
export const metadata: ConsoleCommandData = {
|
||||
name: "eval",
|
||||
description: "Evaluates JavaScript code.",
|
||||
usage: `eval ${'<code>'['bold']}`,
|
||||
aliases: ["do"]
|
||||
}
|
||||
|
||||
export function Main(args: string[]) {
|
||||
let result = ""
|
||||
result = args.join(" ")
|
||||
|
||||
const showRawOutput = result.includes("--raw") || result.includes("-r")
|
||||
result = result.replace('--raw', '').replace('-r', '')
|
||||
let evaled = eval(result)
|
||||
|
||||
if (!showRawOutput) {
|
||||
result = result.replaceAll(process.env.token, "\"[token\"").replaceAll('client.token', '\"[token]\"').replaceAll('process.env.token', '\"[token]\"');
|
||||
|
||||
//Convert evaled into a JSON String if it is an Object
|
||||
if (typeof evaled === "object") evaled = JSON.stringify(evaled);
|
||||
|
||||
//Do this if evaled is anything else other than a number, text, or true/false
|
||||
if (typeof evaled !== "number" && typeof evaled !== "string" && typeof evaled !== "boolean") evaled = `Output could not be converted to text (output was of type: ${typeof evaled}).`;
|
||||
evaled = evaled.toString().replaceAll(process.env.token.toString(), "[token]")
|
||||
result = result.toString().replaceAll(process.env.token, "[token]").replaceAll('client.token', '[token]').replaceAll('process.env.token', '[token]');
|
||||
}
|
||||
cd.log(`Evaled ${evaled}`)
|
||||
return `${showRawOutput ? "Raw e" : "E"}valuation result:\n${evaled}`
|
||||
}
|
||||
Reference in New Issue
Block a user