eval server fix + improve(?)

real
This commit is contained in:
ChomeNS 2023-01-01 21:11:49 +07:00
parent 59a6d573b8
commit c4bd05bb96

View file

@ -2,7 +2,6 @@ const { EmbedBuilder } = require('discord.js')
const { VM } = require('vm2')
const axios = require('axios')
const util = require('util')
const querystring = require('querystring')
const { stylize } = require('../util/colors/minecraft')
module.exports = {
name: 'eval',
@ -14,7 +13,7 @@ module.exports = {
'reset',
'server (eval server) <code>'
],
execute (bot, username, sender, prefix, args, config, hash, ownerhash, selector) {
async execute (bot, username, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0] === 'run') {
try {
bot.tellraw(selector, { text: util.inspect(bot.vm.run(args.slice(1).join(' ')), { stylize }).substring(0, 32000) })
@ -26,20 +25,16 @@ module.exports = {
bot.vm = new VM(bot.vmoptions)
}
if (args[0] === 'server') {
axios
.post(config.eval.serverUrl, querystring.stringify({
const res = await axios.post(config.eval.serverUrl, new URLSearchParams({
html: false,
showErrorMsg: false,
colors: 'minecraft',
code: args[1]
})).then((res) => {
code: args.slice(1).join(' ')
}).toString())
bot.tellraw(selector, { text: res.data })
}).catch((err) => {
bot.tellraw(selector, { text: err, color: 'red' })
})
}
},
discordExecute (bot, username, sender, prefix, args, channeldc, message, config) {
async discordExecute (bot, username, sender, prefix, args, channeldc, message, config) {
if (args[0] === 'run') {
const Embed = new EmbedBuilder()
.setColor(config.discord.embedsColors.normal)
@ -49,20 +44,16 @@ module.exports = {
} else if (args[0] === 'reset') {
bot.vm = new VM(bot.vmoptions)
} else if (args[0] === 'server') {
axios
.post(config.eval.serverUrl, querystring.stringify({
const res = await axios.post(config.eval.serverUrl, new URLSearchParams({
html: false,
showErrorMsg: false,
code: args[1]
})).then((res) => {
code: args.slice(1).join(' ')
}).toString())
const Embed = new EmbedBuilder()
.setColor(config.discord.embedsColors.normal)
.setTitle('Output')
.setDescription(`\`\`\`${res.data}\`\`\``)
channeldc.send({ embeds: [Embed] })
}).catch((err) => {
throw err
})
} else {
throw new SyntaxError('Invalid argument')
}