Port player and chat parsers

This commit is contained in:
7cc5c4f330d47060 2024-08-19 14:39:45 -04:00
parent 268253f909
commit edd4b9ef2f
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
7 changed files with 27 additions and 21 deletions

View file

@ -1,5 +1,5 @@
import * as m from 'minecraft-protocol'
import * as settings from './settings.json' with {type: "json"}
import { default as settings } from './settings.json' with {type: "json"}
import { generateUser } from './util/usergen.js'
import EventEmitter from 'node:events'
import * as fs from 'fs'
@ -10,9 +10,13 @@ const botplug = [];
import { default as botplug_test } from "./plugins/testing.mjs" // We have to load plugins manually, because auto-detection does not work in this format
import { default as botplug_chat } from "./plugins/cq.mjs"
import { default as botplug_chatParse } from "./plugins/!chat.mjs"
import { default as botplug_player } from "./plugins/player.mjs"
botplug.push(botplug_test)
botplug.push(botplug_chat)
botplug.push(botplug_chatParse)
botplug.push(botplug_player)
const bpl = fs.readdirSync('plugins')
@ -66,8 +70,8 @@ const createBot = function createBot (host, oldId) {
})
}
for (const i in settings.default.servers) {
createBot(settings.default.servers[i])
for (const i in settings.servers) {
createBot(settings.servers[i])
}
//module.exports.createBot = createBot

View file

@ -1,7 +1,7 @@
const settings = require('../settings.json')
const parsePlain = require('../util/chatparse_plain.js')
const parseConsole = require('../util/chatparse_console.js')
const parse1204 = require('../util/parseNBT.js')
import { default as settings } from '../settings.json' with {type: "json"}
import { default as parsePlain } from '../util/chatparse_plain.js'
import { default as parseConsole } from '../util/chatparse_console.js'
import { default as parse1204 } from '../util/parseNBT.js'
const messageTypes = [
'',
'chat.type.emote',
@ -12,7 +12,7 @@ const messageTypes = [
'chat.type.team.text',
'chat.type.team.sent'
]
module.exports = {
export default {
load: (b) => {
b._client.on('profileless_chat', (data) => {
if (data.type === 4) {

View file

@ -1,6 +1,6 @@
const parse = require('../util/chatparse_plain')
const parseNBT = require('../util/parseNBT')
module.exports = {
import { default as parse } from '../util/chatparse_plain.js'
import { default as parseNBT } from '../util/parseNBT.js'
export default {
load: (b) => {
b.players = {}
b._client.on('player_info', (data) => {

View file

@ -1,6 +1,6 @@
const settings = require('../settings.json')
const lang = require('./mc_lang.js')
const _consoleColors = require('./consolecolors.json')
import { default as settings } from '../settings.json' with {type: "json"}
import { default as lang } from './mc_lang.js'
import { default as _consoleColors } from './consolecolors.json' with {type: "json"}
let consoleColors
let consoleColors24
@ -101,4 +101,5 @@ const parse2 = function (_data, l, resetColor) {
return `\x1B[0m\x1B[38;2;255;85;85mAn error occured while parsing a message. See console for more information.\nJSON that caused the error: ${JSON.stringify(_data)}`
}
}
module.exports = parse2
export default parse2

View file

@ -1,4 +1,4 @@
const lang = require('./mc_lang.js')
import { default as lang } from './mc_lang.js'
const parse = function (_data, l = 0) {
if (l >= 4) {
return ''
@ -52,4 +52,4 @@ const parse2 = function (_data, l) {
return `An error occured while parsing a message. See console for more information. JSON that caused the error: ${JSON.stringify(_data)}`
}
}
module.exports = parse2
export default parse2

View file

@ -1,6 +1,7 @@
const _lang = require('minecraft-data')('1.20.2').language
import { default as mcdata } from "minecraft-data"
const _lang = mcdata('1.20.2').language
const lang = Object.create(null) // Without constructor function
for (const i in _lang) {
lang[i] = _lang[i]
}
module.exports = lang
export default lang

View file

@ -1,4 +1,4 @@
const { processNbtMessage } = require('prismarine-chat')
import { processNbtMessage } from 'prismarine-chat'
const parse = function (data) {
if (typeof data.type === 'string') {
return JSON.parse(processNbtMessage(data))
@ -8,4 +8,4 @@ const parse = function (data) {
return data
}
}
module.exports = parse
export default parse