2022-12-10 01:31:01 -05:00
|
|
|
const minecraftVersionToNumber = require('../../util/minecraftVersionToNumber')
|
2022-12-05 03:16:48 -05:00
|
|
|
|
2022-12-10 01:31:01 -05:00
|
|
|
function inject (bot, client, target, config, clientPacketBlacklist) {
|
2022-11-30 06:01:46 -05:00
|
|
|
const { MessageBuilder } = require('prismarine-chat')(bot.version)
|
2022-12-10 01:31:01 -05:00
|
|
|
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,
|
|
|
|
'*' + data.message.substring(1),
|
|
|
|
client.uuid,
|
|
|
|
null,
|
2022-12-10 01:31:19 -05:00
|
|
|
'h', // real hash hardcode
|
2022-12-10 01:31:01 -05:00
|
|
|
'o',
|
2022-12-10 23:52:00 -05:00
|
|
|
client.username,
|
2022-12-12 06:37:29 -05:00
|
|
|
true,
|
|
|
|
client,
|
|
|
|
target
|
2022-12-10 01:31:01 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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-16 08:25:07 -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
|
|
|
]
|
|
|
|
})
|
2022-12-10 01:31:01 -05:00
|
|
|
} else {
|
|
|
|
target.chat(data)
|
2022-11-30 06:01:46 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = { inject }
|