2024-11-19 20:05:19 -05:00
|
|
|
import * as index from '../index.js' // Not used in the code, but may be used by users of the command
|
2024-10-26 22:10:16 -04:00
|
|
|
import { getMessage } from '../util/lang.js'
|
2024-12-03 00:33:30 -05:00
|
|
|
import { inspect } from 'node:util'
|
|
|
|
import settings from '../settings.js'
|
|
|
|
import chatlog from '../util/chatlog.js'
|
2024-10-26 22:10:16 -04:00
|
|
|
|
|
|
|
const execute = (c) => {
|
2024-12-03 00:33:30 -05:00
|
|
|
const payload = c.args.join(' ')
|
|
|
|
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog(`eval`, `${c.host}:${c.port} ${c.username} (${c.uuid}) Payload: ${payload}`)
|
|
|
|
try {
|
|
|
|
const result = inspect(eval(payload))
|
|
|
|
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog(`eval`, `${c.host}:${c.port} ${c.username} (${c.uuid}) Result: ${result}`)
|
|
|
|
} catch (e){
|
|
|
|
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog(`eval`, `${c.host}:${c.port} ${c.username} (${c.uuid}) Error: ${inspect(e)}`)
|
|
|
|
}
|
2024-10-26 22:10:16 -04:00
|
|
|
if (c.type === 'console') {
|
2024-12-03 00:33:30 -05:00
|
|
|
console.log(result)
|
2024-10-26 22:10:16 -04:00
|
|
|
} else {
|
|
|
|
c.reply({
|
|
|
|
translate: '%s: %s',
|
|
|
|
color: c.colors.primary,
|
|
|
|
with: [
|
|
|
|
{
|
|
|
|
text: getMessage(c.lang, 'command.eval.output'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
},
|
|
|
|
{
|
2024-12-03 00:33:30 -05:00
|
|
|
text: result + '',
|
2024-10-26 22:10:16 -04:00
|
|
|
color: c.colors.primary,
|
|
|
|
clickEvent: {
|
|
|
|
action: 'copy_to_clipboard',
|
2024-12-03 00:33:30 -05:00
|
|
|
value: result + ''
|
2024-10-26 22:10:16 -04:00
|
|
|
},
|
|
|
|
hoverEvent: {
|
|
|
|
action: 'show_text',
|
|
|
|
contents: {
|
|
|
|
text: getMessage(c.lang, 'copyText'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
},
|
|
|
|
value: { // Added twice for backwards compatibility
|
|
|
|
text: getMessage(c.lang, 'copyText'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const level = 2
|
|
|
|
export { execute, level }
|