botvX_mjs/index.js

75 lines
1.7 KiB
JavaScript
Raw Normal View History

import * as m from 'minecraft-protocol'
import * as settings from './settings.json' with {type: "json"}
import * as generateUser from './util/usergen.js'
import EventEmitter from 'node:events'
import * as fs from 'fs'
2024-08-12 04:33:43 -04:00
let botArray = []
2024-08-12 04:33:43 -04:00
2024-08-17 09:56:26 -04:00
const botplug = []
const bpl = fs.readdirSync('plugins')
for (const i in bpl) {
/*if (!bpl[i].endsWith('.js')) {
2024-08-17 09:56:26 -04:00
continue
2024-08-12 04:33:43 -04:00
}
2024-08-17 09:56:26 -04:00
try {
botplug.push(require(`./plugins/${bpl[i]}`))
} catch (e) { console.log(e) }*/
2024-08-17 09:56:26 -04:00
}
const loadplug = (botno) => {
/*botplug.forEach((plug) => {
2024-08-12 04:33:43 -04:00
try {
if (plug.load) {
plug.load(botArray[botno])
2024-08-12 04:33:43 -04:00
}
} catch (e) { console.log(e) }
})*/
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,
username: generateUser.generateUser(host.options.legalName),
2024-08-12 04:33:43 -04:00
version: host.version ? host.version : settings.version_mc
})
if (typeof oldId !== 'undefined') {
for (const i in botArray[oldId].interval) {
clearInterval(botArray[oldId].interval[i])
2024-08-12 04:33:43 -04:00
}
delete botArray[oldId]
2024-08-12 04:33:43 -04:00
bot.id = oldId
botArray[oldId] = bot
2024-08-12 04:33:43 -04:00
} else {
bot.id = botArray.length
botArray.push(bot)
2024-08-12 04:33:43 -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}`)
}
//loadplug(bot.id)
2024-08-12 04:33:43 -04:00
bot._client.on('error', (err) => {
console.log(err)
})
}
for (const i in settings.default.servers) {
createBot(settings.default.servers[i])
2024-08-12 04:33:43 -04:00
}
//module.exports.createBot = createBot