mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-01 22:55:40 -05:00
v1.3.5 build: 50, ported the bot from 1.21.1 to 1.21.8
This commit is contained in:
+66
-209
@@ -1,4 +1,28 @@
|
||||
const convertNbtComponentToJson = require('../util/nbt_parser')
|
||||
/*
|
||||
please note that the code here for 1.21.8
|
||||
was ported from the FNFBoyfriendBot Reignite 1.21.8 port
|
||||
and had SkiBot's console format added to it
|
||||
*/
|
||||
|
||||
function parse (chatTypes, type, sender, target, message) {
|
||||
const chatType = chatTypes[type]
|
||||
const parsed = convertNbtComponentToJson(null, chatType.value.value.chat)
|
||||
const json = { translate: parsed.translation_key, with: [] }
|
||||
|
||||
for (const parameter of parsed.parameters) {
|
||||
|
||||
switch (parameter) {
|
||||
case "sender": json.with.push(sender)
|
||||
break;
|
||||
case "target": json.with.push(target)
|
||||
case "content": json.with.push(message)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
@@ -11,232 +35,65 @@ module.exports = {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
|
||||
bot.on('packet.player_chat', (data) => {
|
||||
const unsigned = convertNbtComponentToJson(null, data.unsignedChatContent)
|
||||
try {
|
||||
switch (data.type.registryIndex) {
|
||||
case 4:
|
||||
bot.emit('playerChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Player Chat', color: 'dark_purple' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: data.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
{ translate: "commands.message.display.outgoing",
|
||||
with: [
|
||||
data.networkName.insertion,
|
||||
data.plainMessage
|
||||
],
|
||||
color: "gray",
|
||||
italic: true
|
||||
}
|
||||
])
|
||||
break
|
||||
case 3:
|
||||
bot.emit('playerChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Player Chat', color: 'dark_purple' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: data.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
{ translate: "commands.message.display.incoming",
|
||||
with: [
|
||||
data.networkName.insertion,
|
||||
data.plainMessage
|
||||
],
|
||||
color: "gray",
|
||||
italic: true
|
||||
}
|
||||
])
|
||||
break
|
||||
case 5:
|
||||
bot.emit('playerChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Player Chat', color: 'dark_purple' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: data.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
unsigned
|
||||
])
|
||||
break;
|
||||
case 6:
|
||||
bot.emit('playerChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Player Chat', color: 'dark_purple' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: data.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
{ translate: "chat.type.announcement",
|
||||
with: [
|
||||
data.networkName.insertion,
|
||||
data.plainMessage
|
||||
]
|
||||
}
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
console.warn('invalid chat type');
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
bot.on('packet.registry_data', (packet) => {
|
||||
if (packet.id !== 'minecraft:chat_type') return // taken from FNFBoyfriendBot Reignite 1.21.8 port
|
||||
chatTypes = packet.entries
|
||||
})
|
||||
|
||||
bot.on('packet.player_chat', (packet) => {
|
||||
const unsigned = convertNbtComponentToJson(null, packet.unsignedChatContent);
|
||||
bot.emit('message', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Player Chat', color: 'dark_purple' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: packet.type.chatType, color: 'gold' },
|
||||
],
|
||||
},
|
||||
unsigned
|
||||
])
|
||||
});
|
||||
|
||||
bot.on('packet.profileless_chat', (packet) => {
|
||||
const message = convertNbtComponentToJson(null, packet.message)
|
||||
const sender = convertNbtComponentToJson(null, packet.name)
|
||||
try {
|
||||
switch (packet.type.registryIndex) {
|
||||
case 2:
|
||||
bot?.emit('profilelessChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Profileless Chat', color: 'dark_aqua' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: packet.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
{ translate: "chat.type.emote",
|
||||
with: [
|
||||
sender,
|
||||
message
|
||||
]
|
||||
}
|
||||
])
|
||||
break
|
||||
case 3:
|
||||
bot.emit('profilelessChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Profileless Chat', color: 'dark_aqua' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: packet.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
{ translate: "commands.message.display.incoming",
|
||||
with: [
|
||||
sender,
|
||||
message
|
||||
],
|
||||
color: "gray",
|
||||
italic: true
|
||||
}
|
||||
])
|
||||
break
|
||||
case 4:
|
||||
bot.emit('profilelessChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Profileless Chat', color: 'dark_aqua' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: packet.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
{ translate: "commands.message.display.outgoing",
|
||||
with: [
|
||||
sender,
|
||||
message
|
||||
],
|
||||
color: "gray",
|
||||
italic: true
|
||||
}
|
||||
])
|
||||
break
|
||||
case 5:
|
||||
bot.emit('profilelessChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Profileless Chat', color: 'dark_aqua' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: packet.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
message
|
||||
])
|
||||
break
|
||||
case 6:
|
||||
bot.emit('profilelessChat', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Profileless Chat', color: 'dark_aqua' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: packet.type.registryIndex, color: 'gold' },
|
||||
],
|
||||
},
|
||||
{ translate: 'chat.type.announcement',
|
||||
with: [
|
||||
sender,
|
||||
message
|
||||
]
|
||||
}
|
||||
])
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack)
|
||||
}
|
||||
const sender = convertNbtComponentToJson(null, packet.name);
|
||||
const message = convertNbtComponentToJson(null, packet.message);
|
||||
const target = convertNbtComponentToJson(null, packet.target)
|
||||
const type = packet.type.chatType;
|
||||
const parsed = parse(chatTypes, type, sender, target, message)
|
||||
|
||||
bot.emit('message', [
|
||||
{
|
||||
translate: "[%s %s %s%s %s] ",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ text: 'Profileless Chat', color: 'dark_aqua' },
|
||||
{ text: '|' },
|
||||
{ text: 'Packet Type', color: "aqua" },
|
||||
{ text: ':' },
|
||||
{ text: packet.type.chatType, color: 'gold' },
|
||||
],
|
||||
},
|
||||
parsed
|
||||
])
|
||||
});
|
||||
|
||||
bot.on('packet.system_chat', packet => {
|
||||
try {
|
||||
// console.log(packet)
|
||||
const message = convertNbtComponentToJson(null, packet.content)
|
||||
|
||||
if (message.translate === 'advMode.setCommand.success') return // Ignores command set message
|
||||
|
||||
if (message.translate === 'multiplayer.message_not_delivered') return;
|
||||
|
||||
// bot.emit('system_chat', { message, actionbar: packet.isActionBar })
|
||||
|
||||
if (packet.isActionBar) {
|
||||
return
|
||||
}
|
||||
|
||||
bot.emit('systemChat', [
|
||||
bot.emit('message', [
|
||||
{
|
||||
translate: "[%s] ",
|
||||
color: "dark_gray",
|
||||
|
||||
@@ -30,7 +30,7 @@ module.exports = {
|
||||
const { start, end } = bot.core.area
|
||||
|
||||
if (!pos) return
|
||||
const command = `/minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:'${JSON.stringify(config.core.name)}'}`
|
||||
const command = `/minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:${JSON.stringify(config.core.name)}}`
|
||||
bot.chat(`${command}`)
|
||||
},
|
||||
|
||||
|
||||
@@ -58,17 +58,5 @@ module.exports = {
|
||||
refreshLine(`${fromNotch("§8[§4error§8]§r")?.toAnsi()} ${fromNotch(error)?.toAnsi(require('../data/language.json'))}`)
|
||||
}
|
||||
}
|
||||
|
||||
/* bot.on('playerChat', (message) => {
|
||||
bot.console.log(message);
|
||||
});
|
||||
|
||||
bot.on('profilelessChat', (message) => {
|
||||
bot.console.log(message);
|
||||
});
|
||||
|
||||
bot.on('systemChat', (message) => {
|
||||
bot.console.log(message);
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
+3
-21
@@ -7,28 +7,10 @@ module.exports = {
|
||||
},
|
||||
inject (context) {
|
||||
const bot = context.bot;
|
||||
bot.on('playerChat', (message) => {
|
||||
bot.console.log(message);
|
||||
//console.log(message);
|
||||
});
|
||||
|
||||
bot.on('profilelessChat', (message) => {
|
||||
bot.console.log(message);
|
||||
// console.log(message);
|
||||
});
|
||||
|
||||
bot.on('systemChat', (message) => {
|
||||
bot.console.log(message);
|
||||
// console.log(JSON.stringify(message));
|
||||
});
|
||||
|
||||
bot.on('actionBar', (message) => {
|
||||
// console.log(message);
|
||||
});
|
||||
|
||||
/* bot.on('titleBar', (message) => {
|
||||
console.log(message);
|
||||
});*/
|
||||
bot.on('message', (message) => {
|
||||
bot.console.log(message)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-11
@@ -21,8 +21,7 @@ module.exports = {
|
||||
let vanish = false;
|
||||
let nick = false;
|
||||
let username = false;
|
||||
|
||||
|
||||
|
||||
bot.on("system_chat_selfcare", (message) => {
|
||||
try {
|
||||
const parsedMessage = fromNotch(message)?.toMotd();
|
||||
@@ -61,16 +60,14 @@ module.exports = {
|
||||
permission = data.entityStatus - 24
|
||||
});
|
||||
|
||||
bot.on('packet.game_state_change', (data) => {
|
||||
if (data.reason !== 3) return; // Reason 3 = Change Game Mode
|
||||
// if (data.reason !== 4) return;
|
||||
gameMode = data.gameMode;
|
||||
bot.on('packet.game_state_change', (packet) => {
|
||||
if (packet.reason === 3 || packet.reason === "change_game_mode") {
|
||||
gameMode = packet.gameMode;
|
||||
} if (packet.reason === 4 || packet.reason === "win_game") {
|
||||
bot._client.write('client_command', { action: 0 })
|
||||
}
|
||||
});
|
||||
|
||||
bot.on('packet.game_state_change', (data) => {
|
||||
if (data.reason !== 4) return;
|
||||
clientLock = data.gameMode;
|
||||
})
|
||||
|
||||
/* bot.on("packet.position", (packet, position) => {
|
||||
if (!config.selfcare.icu || bot.server.mode === "savageFriends") return;
|
||||
@@ -125,7 +122,7 @@ module.exports = {
|
||||
|
||||
else if (gameMode !== 4) bot._client.write("client_command", { actionId: 0 });
|
||||
}
|
||||
}, 300);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
bot.on('end', () => {
|
||||
|
||||
Reference in New Issue
Block a user