-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 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,73 @@ | ||
const TextCommand = require("../../../structures/base/BaseTextCommand"); | ||
const { EmbedBuilder } = require("discord.js"); | ||
const { inspect } = require("util"); | ||
|
||
class EvalCommand extends TextCommand { | ||
/** | ||
* @param {import("../../index.js")} client MentorQ's Discord Client. | ||
*/ | ||
constructor(client) { | ||
super(client, { | ||
name: "eval", | ||
category: "dev", | ||
description: "Evaluate code.", | ||
args: true, | ||
}); | ||
} | ||
|
||
/** | ||
* @param {import("discord.js").Message} message | ||
* @param {Array<string>} args | ||
* @returns | ||
*/ | ||
async run(message, args) { | ||
|
||
const code = args.join(" "); | ||
|
||
const hrStart = process.hrtime(); | ||
|
||
try { | ||
|
||
let evaled = eval(`(async () => {${code}})()`); | ||
const hrDiff = process.hrtime(hrStart); | ||
|
||
if (evaled.then && evaled.catch) evaled = await evaled; | ||
if (typeof evaled !== "string") evaled = inspect(evaled, { depth: 0 }); | ||
|
||
const result = evaled.length > 4000 ? evaled.substring(0, 4000) : evaled; | ||
|
||
const resultEmbed = new EmbedBuilder() | ||
.setAuthor({ name: "Eval | " + message.author.username, iconURL: message.author.displayAvatarURL() }) | ||
.setTitle("**``EVAL RESULT``**") | ||
.setDescription("```js\n" + result + "```") | ||
.setColor("Blurple") | ||
.setFooter({ text: `Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ""}${hrDiff[1] / 1000000}ms` }) | ||
.setTimestamp(); | ||
|
||
message.channel.send({ embeds: [resultEmbed] }); | ||
|
||
} catch (err) { | ||
|
||
const hrDiff = process.hrtime(hrStart); | ||
|
||
const result = err.stack.length > 4000 ? err.stack.substring(0, 4000) : err.stack; | ||
|
||
const resultEmbed = new EmbedBuilder() | ||
.setAuthor({ name: "Eval | " + message.author.username, iconURL: message.author.displayAvatarURL() }) | ||
.setTitle("**``EVAL ERROR``**") | ||
.setDescription("```js\n" + result + "```") | ||
.setColor("Red") | ||
.setFooter({ text: `Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ""}${hrDiff[1] / 1000000}ms` }) | ||
.setTimestamp(); | ||
|
||
message.channel.send({ embeds: [resultEmbed] }); | ||
|
||
} | ||
|
||
return; | ||
|
||
} | ||
|
||
} | ||
|
||
module.exports = EvalCommand; |
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,52 @@ | ||
const { ChildProcess } = require("child_process"); | ||
const TextCommand = require("../../../structures/base/BaseTextCommand"); | ||
const { EmbedBuilder } = require("discord.js"); | ||
|
||
class ExecCommand extends TextCommand { | ||
/** | ||
* @param {import("../../index.js")} client MentorQ's Discord Client. | ||
*/ | ||
constructor(client) { | ||
super(client, { | ||
name: "exec", | ||
category: "dev", | ||
description: "Run commands in the terminal.", | ||
args: true, | ||
}); | ||
} | ||
|
||
/** | ||
* @param {import("discord.js").Message} message | ||
* @param {Array<string>} args | ||
* @returns | ||
*/ | ||
async run(message, args) { | ||
|
||
const hrStart = process.hrtime(); | ||
|
||
ChildProcess.exec(args.join(" "), (error, stdout) => { | ||
|
||
const hrDiff = process.hrtime(hrStart); | ||
|
||
let result = error?.toString() ?? stdout.toString(); | ||
result = result.length > 4000 ? result.substring(0, 4000) : result; | ||
|
||
const execEmbed = new EmbedBuilder() | ||
.setAuthor({ name: `Exec | ${message.author.username}`, iconURL: message.author.displayAvatarURL() }) | ||
.setTitle(error ? "**__``EXEC ERROR``__**" : "**__``EXEC RESULT``__**") | ||
.setColor(error ? "Red" : "Blurple") | ||
.setDescription(result) | ||
.setFooter({ text: `Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ""}${hrDiff[1] / 1000000}ms` }) | ||
.setTimestamp(); | ||
|
||
message.channel.send({ embeds: [execEmbed] }); | ||
|
||
}); | ||
|
||
return; | ||
|
||
} | ||
|
||
} | ||
|
||
module.exports = ExecCommand; |