-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheval.js
More file actions
36 lines (29 loc) · 1.13 KB
/
eval.js
File metadata and controls
36 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const util = require('util');
module.exports = {
name: 'eval',
description: 'Executes JavaScript code (Owner only).',
async execute(context) {
// Making all context variables available to eval
const { args, reply, hasRole, sock, msg, from, sender, player, commandName, ...restOfContext } = context;
if (!hasRole('owner')) {
return reply('❌ You are not authorized to use this command.');
}
const code = args.join(' ');
if (!code) {
return reply('Please provide code to execute.');
}
try {
// The eval'd code will have access to all the variables destructured above
let result = await eval(code);
if (typeof result !== 'string') {
// Using depth 0 to keep the output clean for large objects
result = util.inspect(result, { depth: 0 });
}
// Slice the result to avoid hitting message length limits
const output = result.slice(0, 4000); // Increased limit slightly for more detailed output
await reply(`✅ Result:\n\`\`\`\n${output}\`\`\``);
} catch (err) {
await reply(`❌ Error:\n\`\`\`\n${err.message}\`\`\``);
}
},
};