1.19.1/2 support (not 1.19.3)

not 1.19.3 because formattedMessage doesn't exist
on kaboom so prefixes like [OP] doesn't appear
This commit is contained in:
ChomeNS 2023-02-26 16:50:15 +07:00
parent 90cdfe6cd0
commit 5d2a06b424
5 changed files with 71 additions and 73 deletions

View file

@ -1,9 +1,9 @@
module.exports = {
version: '1.19',
version: '1.19.2',
prefixes: [
'*',
'cbot ',
'/cbot '
'd*',
'devcbot ',
'/devcbot '
],
commandsDir: '../commands', // this will be used by the commands.js in the plugins folder so it needs ../
keys: {
@ -12,7 +12,7 @@ module.exports = {
},
proxy: {
enabled: true,
version: '1.19'
version: '1.19.2'
},
console: true,
chat: {
@ -61,7 +61,7 @@ module.exports = {
'192.168.1.103': '1002806756885413978',
'kitsune.icu': '1004006678460637315',
'fallback.kitsune.icu': '1050764247518412850',
'chayapak.chipmunk.land': '1010734897796763758',
'chayapak.chipmunk.land': '1079331774783574116',
'play.chipmunk.land': '1042590315464364032',
'mcslot.eu': '1057090538404323338'
},
@ -73,30 +73,30 @@ module.exports = {
},
servers: [
// logging means log to console
{
host: 'play.kaboom.pw',
port: 25565,
kaboom: true,
logging: true
},
{
host: 'sus.shhnowisnottheti.me',
port: 25565,
kaboom: true,
logging: true
},
{
host: 'kitsune.icu',
port: 25565,
kaboom: true,
logging: false
},
{
host: 'play.chipmunk.land',
port: 25565,
kaboom: true,
logging: true
},
// {
// host: 'play.kaboom.pw',
// port: 25565,
// kaboom: true,
// logging: true
// },
// {
// host: 'sus.shhnowisnottheti.me',
// port: 25565,
// kaboom: true,
// logging: true
// },
// {
// host: 'kitsune.icu',
// port: 25565,
// kaboom: true,
// logging: false
// },
// {
// host: 'play.chipmunk.land',
// port: 25565,
// kaboom: true,
// logging: true
// },
{
host: 'chayapak.chipmunk.land',
port: 25565,

View file

@ -27,27 +27,25 @@ function inject (bot, dcclient, config) {
const chatQueueInterval = setInterval(function () {
if (bot._chatQueue.length !== 0) {
if (minecraftVersionToNumber(bot.version) >= 1.19) {
// totallynotskidded™ from mineflayer/lib/plugins/chat.js
if (bot._chatQueue[0].startsWith('/')) {
bot.write('chat_command', {
command: bot._chatQueue[0].substring(1), // removes / from the command
timestamp: BigInt(Date.now()),
if (bot._chatQueue[0].startsWith('/') && minecraftVersionToNumber(bot.version) >= 1.19) {
// totallynotskidded™ from mineflayer
const command = bot._chatQueue[0].slice(1)
const timestamp = BigInt(Date.now())
bot._client.write('chat_command', {
command,
timestamp,
salt: 0n,
argumentSignatures: [],
signedPreview: false
signedPreview: false,
messageCount: 0,
acknowledged: Buffer.alloc(3),
// 1.19.2 Chat Command packet also includes an array of last seen messages
previousMessages: []
})
} else {
bot.write('chat_message', {
message: bot._chatQueue[0],
timestamp: BigInt(Date.now()),
salt: 0,
signature: Buffer.alloc(0) // the bot will never go online mode i guess so i will just use this
})
}
} else {
bot.write('chat', { message: bot._chatQueue[0] })
bot._client.chat(bot._chatQueue[0])
}
bot._chatQueue.shift()
}
}, 450)
@ -68,7 +66,9 @@ function inject (bot, dcclient, config) {
minecraftVersionToNumber(bot.version) >= 1.19
)
}
bot._client.on('system_chat', listener)
// TODO: support playerChat (formattedMessage doesn't exist on kaboom so prefixes like [OP] doesn't appear)
// bot._client.on('playerChat', listener)
bot._client.on('systemChat', listener)
bot._client.on('chat', listener)
bot.on('message', (message, packet) => parsePlayerMessages(message, packet, bot))

View file

@ -39,27 +39,25 @@ function inject (bot, dcclient, config) {
const clientPacketBlacklist = []
const targetPacketBlacklist = []
// target.chat exist so yeah..
// should this be here or in the chat plugin?
target.sendMessage = function (message) {
if (minecraftVersionToNumber(target.version) >= 1.19) {
if (message.startsWith('/')) {
if (message.startsWith('/') && minecraftVersionToNumber(target.version) >= 1.19) {
// totallynotskidded™ from mineflayer
const command = message.slice(1)
const timestamp = BigInt(Date.now())
target.write('chat_command', {
command: message.substring(1), // removes / from the command
timestamp: BigInt(Date.now()),
command,
timestamp,
salt: 0n,
argumentSignatures: [],
signedPreview: false
signedPreview: false,
messageCount: 0,
acknowledged: Buffer.alloc(3),
// 1.19.2 Chat Command packet also includes an array of last seen messages
previousMessages: []
})
} else {
target.write('chat_message', {
message,
timestamp: BigInt(Date.now()),
salt: 0,
signature: Buffer.alloc(0) // the bot will never go online mode i guess so i will just use this
})
}
} else {
target.write('chat', { message })
target.chat(message)
}
}

View file

@ -5,8 +5,8 @@ function inject (bot, client, target) {
function listener (packet) {
chatPacketListener(packet, target, minecraftVersionToNumber(target.version) >= 1.19)
}
target.on('systemChat', listener)
target.on('chat', listener)
target.on('system_chat', listener)
target.on('message', (message, packet) => {
parsePlayerMessages(message, packet, target)

View file

@ -5,11 +5,11 @@
* @param {boolean} mc119 minecraft 1.19 or newer
*/
function chatPacketListener (packet, bot, mc119) {
// try catch prevents json parse error (which prob never happens but still..)
// try catch prevents json parse error (happens with a custom server that sends an invalid json component for example)
try {
const ChatMessage = require('prismarine-chat')(bot.version)
const parsedMessage = JSON.parse(mc119 ? packet.content : packet.message)
const parsedMessage = JSON.parse(mc119 ? packet.formattedMessage : packet.message)
// down here it prevents command set message
// for ayunboom cuz its 1.17.1
@ -21,7 +21,7 @@ function chatPacketListener (packet, bot, mc119) {
// VVVVVVVVVVVVVVVVVVVVV
if (parsedMessage.translate === 'advMode.setCommand.success') return
const message = ChatMessage.fromNotch(mc119 ? packet.content : packet.message)
const message = ChatMessage.fromNotch(mc119 ? packet.formattedMessage : packet.message)
bot.emit('message', message, packet)
} catch (e) {