added entity uuids to the player list, made a file to output json for components and stuff, and more shit

This commit is contained in:
Parker2991
2025-10-02 11:26:17 -05:00
parent 68e4836359
commit 232546aeab
24 changed files with 7173 additions and 6691 deletions
+17 -15
View File
@@ -6,7 +6,7 @@
"": {
"dependencies": {
"discord.js": "^14.22.1",
"minecraft-data": "^3.98.0",
"minecraft-data": "^3.99.1",
"minecraft-protocol": "^1.62.0",
"prismarine-chat": "^1.12.0",
"prismarine-registry": "^1.11.0",
@@ -374,12 +374,12 @@
}
},
"node_modules/@types/node": {
"version": "24.5.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.5.0.tgz",
"integrity": "sha512-y1dMvuvJspJiPSDZUQ+WMBvF7dpnEqN4x9DDC9ie5Fs/HUZJA3wFp7EhHoVaKX/iI0cRoECV8X2jL8zi0xrHCg==",
"version": "24.6.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.6.2.tgz",
"integrity": "sha512-d2L25Y4j+W3ZlNAeMKcy7yDsK425ibcAOO2t7aPTz6gNMH0z2GThtwENCDc0d/Pw9wgyRqE5Px1wkV7naz8ang==",
"license": "MIT",
"dependencies": {
"undici-types": "~7.12.0"
"undici-types": "~7.13.0"
}
},
"node_modules/@types/node-rsa": {
@@ -625,9 +625,9 @@
"license": "MIT"
},
"node_modules/discord-api-types": {
"version": "0.38.25",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.38.25.tgz",
"integrity": "sha512-3edaLHuCdzzfTL1OCpl98G3mrlf+45FpxY+8f+5dRLnZD8R6QzIhapoCefqz6mhaygD+iqTVLtD4u6j57PRiFw==",
"version": "0.38.26",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.38.26.tgz",
"integrity": "sha512-xpmPviHjIJ6dFu1eNwNDIGQ3N6qmPUUYFVAx/YZ64h7ZgPkTcKjnciD8bZe8Vbeji7yS5uYljyciunpq0J5NSw==",
"license": "MIT",
"workspaces": [
"scripts/actions/documentation"
@@ -1097,10 +1097,11 @@
}
},
"node_modules/minecraft-data": {
"version": "3.98.0",
"resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-3.98.0.tgz",
"integrity": "sha512-JAPqJ/TZoxMUlAPPdWUh1v5wdqvYGFSZ4rW9bUtmaKBkGpomDSjw4V02ocBqbxKJvcTtmc5nM/LfN9/0DDqHrQ==",
"license": "MIT"
"version": "3.99.1",
"resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-3.99.1.tgz",
"integrity": "sha512-mI9SNwlrqY2uTTLOT332Hf/QlaLa+AH3V36qu3Y2i9Z2/PjsZlja2ToTDHjazWqDMBtfch+rDTwPB2mHloArHA==",
"license": "MIT",
"peer": true
},
"node_modules/minecraft-folder-path": {
"version": "1.2.0",
@@ -1292,6 +1293,7 @@
"resolved": "https://registry.npmjs.org/prismarine-registry/-/prismarine-registry-1.11.0.tgz",
"integrity": "sha512-uTvWE+bILxYv4i5MrrlxPQ0KYWINv1DJ3P2570GLC8uCdByDiDLBFfVyk4BrqOZBlDBft9CnaJMeOsC1Ly1iXw==",
"license": "MIT",
"peer": true,
"dependencies": {
"minecraft-data": "^3.70.0",
"prismarine-block": "^1.17.1",
@@ -1471,9 +1473,9 @@
}
},
"node_modules/undici-types": {
"version": "7.12.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.12.0.tgz",
"integrity": "sha512-goOacqME2GYyOZZfb5Lgtu+1IDmAlAEu5xnD3+xTzS10hT0vzpf0SPjkXwAw9Jm+4n/mQGDP3LO8CPbYROeBfQ==",
"version": "7.13.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.13.0.tgz",
"integrity": "sha512-Ov2Rr9Sx+fRgagJ5AX0qvItZG/JKKoBRAVITs1zk7IqZGTJUwgUr7qoYBpWwakpWilTZFM98rG/AFRocu10iIQ==",
"license": "MIT"
},
"node_modules/uri-js": {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"dependencies": {
"discord.js": "^14.22.1",
"minecraft-data": "^3.98.0",
"minecraft-data": "^3.99.1",
"minecraft-protocol": "^1.62.0",
"prismarine-chat": "^1.12.0",
"prismarine-registry": "^1.11.0",
+21 -5
View File
@@ -13,9 +13,24 @@ class Bot {
// Set some default values in options
host: (options.host ??= "localhost"),
username: (options.username ??= usernameGen()),
version: (options.version ??= "1.21.8"),
hideErrors: (options.hideErrors ??= true), // HACK: Hide errors by default as a lazy fix to console being spammed with them
serverName: (options.serverName ??= "localhost"),
private: (options.private ??= false),
reconnectDelay: (options.reconnectDelay ??= 300),
channelId: (options.channelId ??= "0000000000000000000"),
logging: {
file: (options.logging.file ??= false),
console: (options.logging.console ??= false)
},
mode: (options.mode ??= "kaboom"),
selfcareInterval: (options.selfcareInterval ??= 1000),
itemRefill: (options.itemRefill ??= false),
chatGamemodeChange: (options.chatGamemodeChange ??= false)
};
bot.options = options;
// Create our client object, put it on the bot, and register some events
bot.on("init_client", (client) => {
client.on("packet", (data, meta) => {
@@ -27,7 +42,7 @@ class Bot {
bot.uuid = client.uuid;
bot.username = client.username;
bot.loggedIn = true;
disconnectCount = 0;
disconnectCount = 0
bot.reconnectDelay = options.reconnectDelay;
});
@@ -82,12 +97,13 @@ class Bot {
ChatMessage(bot._client.version).fromNotch(data.reason)?.toString(),
);
});
process.on("uncaughtException", (e) => {
console.warn(`${e.stack}`);
});
});
process.on("uncaughtException", (e) => {
console.warn(`${e.stack}`);
});
const client = options.client ?? new mc.createClient(bot.options);
bot._client = client;
bot.emit("init_client", client);
+3 -13
View File
@@ -10,15 +10,7 @@ function kaboom (message, data) {
const prefix = children[0]
let displayName = data.senderName ?? { text: '' }
let contents = { text: '' }
//console.log(data.players.find((e) => e.uuid ==))
/*
player chat:
senderUuid: '85f5b68d-a567-3877-9701-3cd7404bc9d9',
networkName: { extra: [ [Object] ], text: '' },
diguised chat:
senderName: { extra: [ [Object] ], text: '' },
*/
if (isSeparatorAt(children, 1)) { // Missing/blank display name
if (children.length > 3) contents = children[3]
} else if (isSeparatorAt(children, 2)) {
@@ -29,17 +21,15 @@ diguised chat:
}
const playerListDisplayName = { extra: [prefix, displayName], text: '' }
// console.log(JSON.stringify(playerListDisplayName))
//console.log(JSON.stringify())
//console.log(`Player list display name from Chat Parser ${data.getMessageAsPrismarine(playerListDisplayName)?.toMotd()}`)
//console.log(`${data.getMessageAsPrismarine(displayName)?.toMotd()}`)
let sender
//console.log(data)
if (data.senderUuid) {
sender = data.players.find(player => player.uuid === data.senderUuid)
} else {
const playerListDisplayName = { extra: [prefix, displayName], text: '' }
sender = data.players.find(player => util.isDeepStrictEqual(player.displayName, playerListDisplayName))
console.log(sender)
}
if (!sender) return undefined
+2 -2
View File
@@ -1,4 +1,4 @@
function parseMessage(message, data, context) {
function vanila(message, data, context) {
try {
if (message === null || typeof message !== "object") return;
@@ -34,4 +34,4 @@ function parseMessage(message, data, context) {
console.error(`${e.stack}`);
}
}
module.exports = parseMessage;
module.exports = vanila;
+2 -1
View File
@@ -1,11 +1,12 @@
class CommandContext {
constructor(name, aliases, description, trustLevel, usages) {
constructor(name, aliases, description, trustLevel, usages, chatTypes) {
this.data = {};
this.data.name = name;
this.data.aliases = aliases;
this.data.description = description;
this.data.trustLevel = trustLevel;
this.data.usages = usages;
this.data.chatTypes = chatTypes;
}
}
module.exports = CommandContext;
+1 -1
View File
@@ -37,7 +37,7 @@ class info extends CommandContext {
"usages ",
"uptimes",
"server",
"version/",
"version",
],
);
}
+4 -2
View File
@@ -20,7 +20,6 @@ class list extends CommandContext {
const config = context.config;
const source = context.source;
let component = [];
let infoComponent = [];
let playerCount = [];
playerCount.push({
@@ -37,7 +36,7 @@ class list extends CommandContext {
for (const player of bot.players) {
component.push({
translate: "%s \u203a %s [%s: %s]\n",
translate: "%s \u203a %s [%s: %s]",
color: config.colors.commands.tertiary,
with: [
player.displayName ?? player.profile.name,
@@ -46,7 +45,10 @@ class list extends CommandContext {
{ text: `${player.latency}`, color: config.colors.integer }
]
})
component.push("\n");
}
component.pop();
source.sendFeedback(component)
}
}
+4
View File
@@ -9,6 +9,9 @@ class test extends CommandContext {
"testing stuff",
trustLevel.public,
[""],
[
]
);
}
@@ -16,6 +19,7 @@ class test extends CommandContext {
const bot = context.bot;
const args = context.arguments;
const source = context.source;
}
}
+2 -1
View File
@@ -3,6 +3,7 @@
"build": "3000",
"codename": "§4Reignite",
"version": "v8.0.0-alpha",
"url": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot.git"
"url": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot.git",
"branch": "dev"
}
}
+7003 -6609
View File
File diff suppressed because it is too large Load Diff
+7 -1
View File
@@ -111,6 +111,12 @@
"fnfboyfriendbot.command_manager.validation.invalid_trusted_hash": "Invalid Trusted Hash",
"fnfboyfriendbot.command_manager.validation.invalid_role": "Invalid Role",
"fnfboyfriendbot.reconnect.stop_logging": "stopped logging disconnect messages for now"
"fnfboyfriendbot.https_requesting.status.forbidden": "",
"fnfboyfriendbot.https_requesting.": "",
"fnfboyfriendbot.json.parse_invalid": "invalid json component to parse",
"fnfboyfriendbot.json.stringify.invalid": "invalid json component to stringify",
"fnfboyfriendbot.json.stringify.too_long": "stringified json exceeds the max command block character limit",
"fnfboyfriendbot.reconnect.stop_logging": "stopped logging disconnect messages for now"
}
+13 -19
View File
@@ -1,19 +1,13 @@
const loadPrismarineChat = require("prismarine-chat");
const convertNbtComponentToJson = require("../util/convertNbtComponentToJson");
const KaboomChatParser = require("../chatParsers/kaboom");
const CreayunChatParser = require("../chatParsers/creayun");
const ChipmunkModChatParser = require("../chatParsers/chipmunkmod");
const VanilaChatParser = require("../chatParsers/vanilla");
const convertNbtComponentToJson = require("../util/convertNbtComponentToJson");
const { stringify } = require('../util/json');
function tryParse(json) {
try {
return JSON.parse(json);
} catch (error) {
return { text: "" };
}
}
//const VanilaChatParser = require("../chatParsers/vanilla");
function parse (chatTypes, type, sender, target, message) {
function parseNbt (chatTypes, type, sender, target, message) {
const chatType = chatTypes[type]
const parsed = convertNbtComponentToJson(null, chatType.value.value.chat)
let json = { translate: parsed.translation_key, with: [] }
@@ -48,6 +42,7 @@ class chat {
bot.on('packet.registry_data', (packet) => {
if (packet.id !== 'minecraft:chat_type') return // taken from the 1.21.1 build of my bot that chayapak made
chatTypes = packet.entries
})
if (options.mode === "savageFriends") {
@@ -56,7 +51,7 @@ class chat {
bot.chatParsers = [
KaboomChatParser,
ChipmunkModChatParser,
VanilaChatParser,
// VanilaChatParser,
];
}
@@ -65,17 +60,16 @@ class chat {
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)
const parsed = parseNbt(chatTypes, type, sender, target, message)
bot.emit('message', {
type: "minecraft:disguised_chat",
message: parsed
})
tryParsingMessage(parsed, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine, chatType: "minecraft:diguised_chat" })
parseMessage(parsed, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine, chatType: "minecraft:diguised_chat" })
});
bot.on("packet.player_chat", (packet) => {
const unsigned = convertNbtComponentToJson(null, packet.unsignedChatContent);
const networkName = convertNbtComponentToJson(null, packet.networkName)
bot.emit('message', {
@@ -83,7 +77,7 @@ class chat {
message: unsigned
})
tryParsingMessage(unsigned, {
parseMessage(unsigned, {
senderUuid: packet.senderUuid,
players: bot.players,
getMessageAsPrismarine: bot.getMessageAsPrismarine,
@@ -106,21 +100,20 @@ class chat {
if (message.translate === "advMode.notAllowed") return;
// console.log(JSON.stringify(message))
bot.emit("message", {
type: "minecraft:system_chat",
message: message
});
bot.emit("system_chat", message);
tryParsingMessage(message, {
parseMessage(message, {
players: bot.players,
getMessageAsPrismarine: bot.getMessageAsPrismarine,
chatType: "minecraft:system_chat",
});
});
function tryParsingMessage(message, data) {
function parseMessage(message, data) {
try {
let parsed;
@@ -185,7 +178,8 @@ class chat {
};
bot.tellraw = (selector, message) => {
bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(message));
console.log(stringify(message))
bot.core.run(`minecraft:tellraw ${selector} ` + stringify(message));
};
}
}
+1 -2
View File
@@ -31,9 +31,8 @@ class commandHandler {
if (options.mode === "savageFriends") bot.tellraw(`@a`, [
message
])
else bot.tellraw(`@a[name="${source.player.profile.name}"]`, message)
else bot.tellraw(`@p[nbt={UUID:${source.player.entityUuid}}]`, message)
}
ratelimit++;
setTimeout(() => {
ratelimit--;
-3
View File
@@ -17,9 +17,6 @@ class Console {
serverName = `§1${bot.options.host}:§9${bot.options.port}`;
}
/*
process.stdin.on('keypress', (str, key) => {
*/
bot.console = {
readline: null,
server: "all",
-1
View File
@@ -75,7 +75,6 @@ class discord {
if (message.channel.id !== bot.discord.channel.id) return;
if (message.content.startsWith(config.discord.prefix)) {
// TODO: Don't hardcode this
const source = new CommandSource(
{
profile: {
+4 -5
View File
@@ -1,4 +1,6 @@
const convertNbtComponentToJson = require("../util/convertNbtComponentToJson");
const entityUUID = require('../util/entityUUID');
const mc = require('minecraft-protocol')
class playerList {
constructor(context) {
@@ -7,7 +9,7 @@ class playerList {
const options = context.options;
bot.players = [];
bot.on("packet.player_info", async (packet) => {
bot.on("packet.player_info", (packet) => {
const actions = [];
if (packet.action._value & 0b000001) actions.push(addPlayer);
if (packet.action._value & 0b000010) actions.push(initializeChat);
@@ -15,7 +17,6 @@ class playerList {
if (packet.action._value & 0b001000) actions.push(updateListed);
if (packet.action._value & 0b010000) actions.push(updateLatency);
if (packet.action._value & 0b100000) actions.push(updateDisplayName);
for (const entry of packet.data) {
for (const action of actions) {
action(entry);
@@ -36,7 +37,6 @@ class playerList {
);
if (a.length >= 1) {
player.vanished = true;
} else {
bot.players = bot.players.filter((_) => _.uuid != player.uuid);
if (player.vanished === true)
@@ -47,10 +47,9 @@ class playerList {
function addPlayer(entry) {
bot.players = bot.players.filter((_entry) => _entry.uuid !== entry.uuid);
//console.log(convertNbtComponentToJson(null, entry.displayName).extra[0])
bot.players.push({
uuid: entry.uuid,
// mcUUID: "",
entityUuid: entityUUID(entry.uuid),
profile: {
name: entry.player.name,
properties: entry.player.properties,
+1 -7
View File
@@ -4,18 +4,12 @@ class validation {
constructor(context) {
const bot = context.bot;
const config = context.config;
bot.validation = {
discord: {}
}
bot.validation = {}
setInterval(() => {
bot.validation.trusted = crypto.createHash("sha512").update(Math.floor(Date.now() / 2000) + config.keys.trusted).digest("hex").substring(0, 16)
bot.validation.admin = crypto.createHash("sha512").update(Math.floor(Date.now() / 2000) + config.keys.admin).digest("hex").substring(0, 16)
bot.validation.owner = crypto.createHash("sha512").update(Math.floor(Date.now() / 2000) + config.keys.owner).digest("hex").substring(0, 16)
}, 100)
setInterval(() => {
bot.validation.discord = {} // to clear discord hashes if they were sent and not used
}, 10000)
}
}
module.exports = validation;
-2
View File
@@ -5,8 +5,6 @@ class login {
const config = context.config
const stringMessage = context.stringMessage
//if (options.mode !== "savageFriends") return
if (stringMessage === "Please, login with the command: /login <password>") bot.selfcare.login = true;
else if (stringMessage === "Successful login!") bot.selfcare.logged = false;
else if (stringMessage === "You're already logged in!") bot.selfcare.login = false;
-1
View File
@@ -5,7 +5,6 @@ class register {
const config = context.config
const stringMessage = context.stringMessage
//if (options.mode !== "savageFriends") return
if (stringMessage === "Please, register to the server with the command: /register <password> <ConfirmPassword>") bot.selfcare.register = true;
else if (stringMessage === "This user isn't registered!") bot.selfcare.register = true;
else if (stringMessage === "Successfully registered!") bot.selfcare.register = false;
+4
View File
@@ -6,6 +6,7 @@ class prefix {
if (bot.options.mode === "savageFriends") return
bot.on('packet.player_info', (packet) => {
try {
const uuid = packet.data[0].uuid
if (uuid === bot.uuid) {
const player = bot.players.find((player) => player.uuid === uuid)
@@ -14,6 +15,9 @@ class prefix {
if (prefix !== forcedPrefix) bot.selfcare.prefix = false
else bot.selfcare.prefix = true
}
} catch (e) {
}
})
}
}
+5
View File
@@ -0,0 +1,5 @@
function entityUUID (uuid) {
// taken from https://gist.github.com/storycraft/7813dd0186e85daa393e1df9cfa19f2a
return String(`[I;${uuid.replace(/-/g, '').match(/.{8}/g).map(str => Number.parseInt(str, 16)).map(num => num & 0x80000000 ? num - 0xffffffff - 1 : num).join(',')}]`)
}
module.exports = entityUUID;
+34
View File
@@ -0,0 +1,34 @@
const translations = require('../data/translations.json');
class json {
static parse (json) {
try {
return JSON.parse(json)
} catch {
return {
translate: "fnfboyfriendbot.json.parse_invalid",
fallback: translations["fnfboyfriendbot.json.parse_invalid"],
color: "red"
}
}
}
static stringify (json) {
try {
const stringify = JSON.stringify(json);
if (stringify.length > 32681) return JSON.stringify({
translate: "fnfboyfriendbot.json.stringify.too_long",
fallback: translations["fnfboyfriendbot.json.stringify.too_long"],
color: "red",
})
else return stringify;
} catch {
return JSON.stringify({
translate: "fnfboyfriendbot.json.stringify.invalid",
fallback: translations["fnfboyfriendbot.json.stringify.invalid"],
color: "red"
})
}
}
}
module.exports = json
+44
View File
@@ -0,0 +1,44 @@
const { request, statusCode, Headers, trailers, body } = require('undici');
async function websiteRequesting (url) {
const url = await request(String(url))
console.log(url)
}
module.exports = websiteRequesting;
/*
import { request } from 'undici'
const {
statusCode,
headers,
trailers,
body
} = await request('http://localhost:3000/foo')
console.log('response received', statusCode)
console.log('headers', headers)
for await (const data of body) { console.log('data', data) }
console.log('trailers', trailers)
*/
/*const https = require('https');
const http = require('http');
function websiteRequesting (url) {
if (url.startsWith('http://')) {
} else {
https.request(url, '', (res) => {
console.log(res)
})
}
}
module.exports = websiteRequesting;*/