custom chat code parsing thingy

This commit is contained in:
ChomeNS 2022-12-05 21:05:26 +07:00
parent 666cc2491f
commit 894f4a16ca

View file

@ -6,6 +6,14 @@ function inject (bot, client, target) {
!data.message?.startsWith('/') && !data.message?.startsWith('/') &&
!data.message?.startsWith('.') !data.message?.startsWith('.')
) { ) {
const codeParsedMessage = data.message.replace(/%.*%/g, (code) => {
try {
// eslint-disable-next-line no-eval
return eval(code.substring(1).slice(0, -1))
} catch (e) {
return code
}
})
bot.tellraw('@a', { bot.tellraw('@a', {
color: 'dark_gray', color: 'dark_gray',
translate: '[%s] [%s] %s \u203a %s', translate: '[%s] [%s] %s \u203a %s',
@ -22,7 +30,7 @@ function inject (bot, client, target) {
text: client.username, text: client.username,
color: 'green' color: 'green'
}, },
MessageBuilder.fromString('&7' + data.message) MessageBuilder.fromString('&7' + codeParsedMessage)
] ]
}) })
} }