2024-08-19 14:07:17 -04:00
|
|
|
import * as m from 'minecraft-protocol'
|
2024-08-19 14:39:45 -04:00
|
|
|
import { default as settings } from './settings.json' with {type: "json"}
|
2024-08-19 14:20:15 -04:00
|
|
|
import { generateUser } from './util/usergen.js'
|
2024-08-19 14:07:17 -04:00
|
|
|
import EventEmitter from 'node:events'
|
|
|
|
import * as fs from 'fs'
|
2024-08-12 04:33:43 -04:00
|
|
|
|
2024-08-19 14:07:17 -04:00
|
|
|
let botArray = []
|
2024-08-12 04:33:43 -04:00
|
|
|
|
2024-08-19 14:20:15 -04:00
|
|
|
const botplug = [];
|
|
|
|
|
2024-08-19 14:24:55 -04:00
|
|
|
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"
|
2024-08-19 14:39:45 -04:00
|
|
|
import { default as botplug_chatParse } from "./plugins/!chat.mjs"
|
|
|
|
import { default as botplug_player } from "./plugins/player.mjs"
|
2024-08-20 05:02:48 -04:00
|
|
|
import { default as botplug_cmd } from "./plugins/command.mjs"
|
|
|
|
import { default as botplug_cmdCore } from "./plugins/commandblock.mjs"
|
|
|
|
import { default as botplug_selfCare } from "./plugins/selfcare.mjs"
|
2024-08-19 14:20:15 -04:00
|
|
|
|
2024-08-19 14:24:55 -04:00
|
|
|
botplug.push(botplug_test)
|
|
|
|
botplug.push(botplug_chat)
|
2024-08-19 14:39:45 -04:00
|
|
|
botplug.push(botplug_chatParse)
|
|
|
|
botplug.push(botplug_player)
|
2024-08-20 05:02:48 -04:00
|
|
|
botplug.push(botplug_cmd)
|
|
|
|
botplug.push(botplug_cmdCore)
|
|
|
|
botplug.push(botplug_selfCare)
|
2024-08-19 14:20:15 -04:00
|
|
|
|
2024-08-17 09:56:26 -04:00
|
|
|
const bpl = fs.readdirSync('plugins')
|
|
|
|
|
|
|
|
const loadplug = (botno) => {
|
2024-08-19 14:20:15 -04:00
|
|
|
botplug.forEach((plug) => {
|
2024-08-12 04:33:43 -04:00
|
|
|
try {
|
|
|
|
if (plug.load) {
|
2024-08-19 14:07:17 -04:00
|
|
|
plug.load(botArray[botno])
|
2024-08-12 04:33:43 -04:00
|
|
|
}
|
|
|
|
} catch (e) { console.log(e) }
|
2024-08-19 14:20:15 -04:00
|
|
|
})
|
2024-08-12 04:33:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const createBot = function createBot (host, oldId) {
|
|
|
|
if (host.options.disabled) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const bot = new EventEmitter()
|
|
|
|
bot._client = m.createClient({
|
|
|
|
host: host.host,
|
|
|
|
port: host.port ? host.port : 25565,
|
2024-08-19 14:20:15 -04:00
|
|
|
username: generateUser(host.options.legalName),
|
2024-08-12 04:33:43 -04:00
|
|
|
version: host.version ? host.version : settings.version_mc
|
|
|
|
})
|
|
|
|
if (typeof oldId !== 'undefined') {
|
2024-08-19 14:07:17 -04:00
|
|
|
for (const i in botArray[oldId].interval) {
|
|
|
|
clearInterval(botArray[oldId].interval[i])
|
2024-08-12 04:33:43 -04:00
|
|
|
}
|
2024-08-19 14:07:17 -04:00
|
|
|
delete botArray[oldId]
|
2024-08-12 04:33:43 -04:00
|
|
|
bot.id = oldId
|
2024-08-19 14:07:17 -04:00
|
|
|
botArray[oldId] = bot
|
2024-08-12 04:33:43 -04:00
|
|
|
} else {
|
2024-08-19 14:07:17 -04:00
|
|
|
bot.id = botArray.length
|
|
|
|
botArray.push(bot)
|
2024-08-12 04:33:43 -04:00
|
|
|
}
|
2024-08-19 14:07:17 -04:00
|
|
|
|
2024-08-12 04:33:43 -04:00
|
|
|
bot.host = host
|
|
|
|
bot.interval = {}
|
|
|
|
|
|
|
|
bot.info = (msg) => {
|
|
|
|
console.log(`[${bot.id}] [info] ${msg}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
bot.displayChat = (type, msg) => {
|
|
|
|
console.log(`[${bot.id}] [${type}] ${msg}`)
|
|
|
|
}
|
|
|
|
|
2024-08-19 14:20:15 -04:00
|
|
|
loadplug(bot.id)
|
2024-08-12 04:33:43 -04:00
|
|
|
bot._client.on('error', (err) => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-08-19 14:39:45 -04:00
|
|
|
for (const i in settings.servers) {
|
|
|
|
createBot(settings.servers[i])
|
2024-08-12 04:33:43 -04:00
|
|
|
}
|
|
|
|
|
2024-08-20 05:02:48 -04:00
|
|
|
export {
|
|
|
|
botArray as bot,
|
|
|
|
createBot
|
|
|
|
}
|
2024-08-19 14:07:17 -04:00
|
|
|
//module.exports.createBot = createBot
|