1
0
Fork 0
mirror of https://github.com/ChomeNS/chomens-bot-mc.git synced 2025-07-25 21:28:50 -04:00
chomens-bot-js/commands/eval.js

72 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-08-14 16:51:45 +07:00
/* eslint-disable max-len */
2022-11-27 14:35:28 +07:00
const { MessageEmbed } = 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')
2022-08-14 16:51:45 +07:00
module.exports = {
name: 'eval',
alias: [],
description: 'Safe eval 100% secure!!!',
trusted: 0,
usage: [
'<run> <code>',
'<reset>',
2022-11-27 14:35:28 +07:00
'<server (eval server)> <code>'
],
execute (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
2022-11-07 19:26:38 +07:00
if (args[0] === 'run') {
2022-08-14 16:51:45 +07:00
try {
2022-11-27 14:35:28 +07:00
bot.tellraw(selector, { text: `${util.inspect(bot.vm.run(args.slice(1).join(' ')), { stylize })}`.substring(0, 32000) })
2022-08-14 16:51:45 +07:00
} catch (err) {
2022-11-27 14:35:28 +07:00
bot.tellraw(selector, { text: `${util.inspect(err).replaceAll('runner', 'chayapak1')}`, color: 'red' })
2022-08-14 16:51:45 +07:00
}
}
2022-11-07 19:26:38 +07:00
if (args[0] === 'reset') {
2022-11-27 14:35:28 +07:00
bot.vm = new VM(bot.vmoptions)
2022-08-14 16:51:45 +07:00
}
2022-11-07 19:26:38 +07:00
if (args[0] === 'server') {
2022-08-14 16:51:45 +07:00
axios
2022-11-27 14:35:28 +07:00
.post(config.eval.serverUrl, querystring.stringify({
html: false,
showErrorMsg: false,
colors: 'minecraft',
code: args[1]
})).then((res) => {
bot.tellraw(selector, { text: `${res.data}` })
}).catch((err) => {
bot.tellraw(selector, { text: `${err}`, color: 'red' })
})
2022-08-14 16:51:45 +07:00
}
},
discordExecute (bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
2022-11-07 19:26:38 +07:00
if (args[0] === 'run') {
2022-11-27 14:35:28 +07:00
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(`\`\`\`${util.inspect(bot.vm.run(args.slice(1).join(' '))).substring(0, 1950)}\`\`\``)
channeldc.send({ embeds: [Embed] })
2022-11-07 20:08:29 +07:00
} else if (args[0] === 'reset') {
2022-11-27 14:35:28 +07:00
bot.vm = new VM(bot.vmoptions)
2022-11-07 20:08:29 +07:00
} else if (args[0] === 'server') {
2022-10-14 15:46:41 +07:00
axios
2022-11-27 14:35:28 +07:00
.post(config.eval.serverUrl, querystring.stringify({
html: false,
showErrorMsg: false,
code: args[1]
})).then((res) => {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(`\`\`\`${res.data}\`\`\``)
channeldc.send({ embeds: [Embed] })
}).catch((err) => {
throw err
})
2022-11-07 20:08:29 +07:00
} else {
2022-11-27 14:35:28 +07:00
throw new SyntaxError('Invalid argument')
2022-10-14 15:46:41 +07:00
}
2022-11-27 14:35:28 +07:00
}
}