chomens-bot-js/plugins/proxy/custom_chat.js

59 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

const minecraftVersionToNumber = require('../../util/minecraftVersionToNumber')
function inject (bot, client, target, config, clientPacketBlacklist) {
2022-11-30 06:01:46 -05:00
const { MessageBuilder } = require('prismarine-chat')(bot.version)
clientPacketBlacklist.push('chat')
clientPacketBlacklist.push('chat_message')
client.on(minecraftVersionToNumber(target.version) >= 1.19 ? 'chat_message' : 'chat', (data) => {
// not the best place to put command handler thing here but ok
if (data.message?.startsWith('.')) {
return bot.command_handler.run(
client.username,
2023-03-15 04:06:49 -04:00
config.prefixes[0] + data.message.substring(1),
client.uuid,
null,
2022-12-10 01:31:19 -05:00
'h', // real hash hardcode
'o',
client.username,
true,
client,
target
)
}
if (!data.message?.startsWith('/')) {
2022-12-06 04:40:11 -05:00
const codeParsedMessage = data.message.replace(/%[^%]+%/g, (code) => {
2022-12-05 09:05:26 -05:00
try {
// eslint-disable-next-line no-eval
return eval(code.substring(1).slice(0, -1))
} catch (e) {
return code
}
})
2022-11-30 06:01:46 -05:00
bot.tellraw('@a', {
color: 'dark_gray',
translate: '[%s] [%s] %s \u203a %s',
with: [
{
text: 'Chat',
color: 'gray'
},
{
text: 'Proxy',
color: 'gray'
},
{
2022-12-26 07:11:47 -05:00
selector: client.username,
2022-11-30 06:01:46 -05:00
color: 'green'
},
2022-12-05 09:05:26 -05:00
MessageBuilder.fromString('&7' + codeParsedMessage)
2022-11-30 06:01:46 -05:00
]
})
} else {
target.sendMessage(data)
2022-11-30 06:01:46 -05:00
}
})
};
module.exports = { inject }