2023-12-17 14:55:27 -05:00
|
|
|
const { VM } = require('vm2')
|
|
|
|
const util = require('util')
|
|
|
|
const { stylize } = require('../util/eval_colors')
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
timeout: 1000
|
|
|
|
}
|
|
|
|
let vm = new VM(options)
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'evaljsvm2',
|
2023-12-20 11:54:03 -05:00
|
|
|
trustLevel: 1,
|
2023-12-17 14:55:27 -05:00
|
|
|
description:['old evaljs code'],
|
|
|
|
aliases:['evaljsold', 'evalvm2', 'evalold'],
|
|
|
|
execute (context) {
|
|
|
|
const source = context.source
|
|
|
|
const args = context.arguments
|
2024-01-26 21:24:08 -05:00
|
|
|
const bot = context.bot
|
|
|
|
const ChatMessage = require('prismarine-chat')(bot.options.version)
|
|
|
|
|
2023-12-17 14:55:27 -05:00
|
|
|
const cmd = {
|
|
|
|
translate: '[%s] ',
|
|
|
|
bold: false,
|
|
|
|
color: 'white',
|
|
|
|
with: [
|
|
|
|
{ color: 'dark_green', text: 'EvalJS Cmd'},
|
|
|
|
]
|
|
|
|
}
|
2024-01-26 21:24:08 -05:00
|
|
|
|
2023-12-17 14:55:27 -05:00
|
|
|
// throw new CommandError('temp disabled')
|
|
|
|
if (!args && !args[0] && !args[1] && !args[2] && !args[3]) return
|
|
|
|
switch (args[1]) {
|
|
|
|
case 'run':
|
|
|
|
try {
|
|
|
|
const output = vm.run(args.slice(2).join(' '))
|
2024-01-27 09:57:08 -05:00
|
|
|
if (bot.options.Core.CorelessMode){
|
2024-01-26 21:24:08 -05:00
|
|
|
bot.chat(ChatMessage.fromNotch([cmd, { text: util.inspect(output, { stylize }) }]).toMotd().replaceAll('§', '&'))
|
|
|
|
}else
|
2023-12-17 14:55:27 -05:00
|
|
|
source.sendFeedback([cmd, { text: util.inspect(output, { stylize }) }])
|
|
|
|
} catch (e) {
|
2024-01-26 21:24:08 -05:00
|
|
|
if(!bot.options.Core.CorelessMode){
|
|
|
|
bot.chat(ChatMessage.fromNotch([cmd, { text: e.stack, color: 'black' }]).toMotd().replaceAll('§', '&'))
|
|
|
|
}else{
|
|
|
|
source.sendFeedback([cmd, { text: e.stack, color: 'black' }])
|
|
|
|
}
|
2023-12-17 14:55:27 -05:00
|
|
|
}
|
|
|
|
break
|
|
|
|
case 'reset':
|
|
|
|
vm = new VM(options)
|
2024-01-27 09:57:08 -05:00
|
|
|
if(bot.options.Core.CorelessMode){
|
2024-01-26 21:24:08 -05:00
|
|
|
bot.chat(ChatMessage.fromNotch([cmd, { text: 'Successfully reset the eval context', color: 'green' }]).toMotd().replaceAll('§', '&'))
|
|
|
|
}else{
|
2023-12-17 14:55:27 -05:00
|
|
|
source.sendFeedback([cmd, { text: 'Successfully reset the eval context', color: 'green' }])
|
2024-01-26 21:24:08 -05:00
|
|
|
}
|
2023-12-17 14:55:27 -05:00
|
|
|
break
|
|
|
|
default:
|
2024-01-27 09:57:08 -05:00
|
|
|
if(bot.options.Core.CorelessMode){
|
2024-01-26 21:24:08 -05:00
|
|
|
bot.chat(ChatMessage.fromNotch([cmd, { text: 'Invalid option!', color: 'dark_red' }]).toMotd().replaceAll('§', '&'))
|
|
|
|
}else{
|
2023-12-17 14:55:27 -05:00
|
|
|
source.sendFeedback([cmd, { text: 'Invalid option!', color: 'dark_red' }])
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2024-01-26 21:24:08 -05:00
|
|
|
}
|
|
|
|
}
|