From 894f4a16ca5de11f26d6cdcf831c5861d37f2fc1 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Mon, 5 Dec 2022 21:05:26 +0700 Subject: [PATCH] custom chat code parsing thingy --- plugins/proxy/custom_chat.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/proxy/custom_chat.js b/plugins/proxy/custom_chat.js index c3079c5..b1af9dd 100644 --- a/plugins/proxy/custom_chat.js +++ b/plugins/proxy/custom_chat.js @@ -6,6 +6,14 @@ function inject (bot, client, target) { !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', { color: 'dark_gray', translate: '[%s] [%s] %s \u203a %s', @@ -22,7 +30,7 @@ function inject (bot, client, target) { text: client.username, color: 'green' }, - MessageBuilder.fromString('&7' + data.message) + MessageBuilder.fromString('&7' + codeParsedMessage) ] }) }