From e8cb2cea8dcbd122f8bc49c41464e97946244ac9 Mon Sep 17 00:00:00 2001 From: 7cc5c4f330d47060 Date: Mon, 19 Aug 2024 14:07:17 -0400 Subject: [PATCH] Rewrite index.js and the username generator --- index.js | 46 +++++++++++++++++++++++----------------------- util/usergen.js | 3 ++- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index df126e4..436cc26 100755 --- a/index.js +++ b/index.js @@ -1,30 +1,30 @@ -const m = require('minecraft-protocol') -const settings = require('./settings.json') -const generateUser = require('./util/usergen.js') -const EventEmitter = require('node:events') -const fs = require('fs') +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' -module.exports.bot = [] +let botArray = [] const botplug = [] const bpl = fs.readdirSync('plugins') for (const i in bpl) { - if (!bpl[i].endsWith('.js')) { + /*if (!bpl[i].endsWith('.js')) { continue } try { botplug.push(require(`./plugins/${bpl[i]}`)) - } catch (e) { console.log(e) } + } catch (e) { console.log(e) }*/ } const loadplug = (botno) => { - botplug.forEach((plug) => { + /*botplug.forEach((plug) => { try { if (plug.load) { - plug.load(module.exports.bot[botno]) + plug.load(botArray[botno]) } } catch (e) { console.log(e) } - }) + })*/ } const createBot = function createBot (host, oldId) { @@ -35,21 +35,21 @@ const createBot = function createBot (host, oldId) { bot._client = m.createClient({ host: host.host, port: host.port ? host.port : 25565, - username: generateUser(host.options.legalName), + username: generateUser.generateUser(host.options.legalName), version: host.version ? host.version : settings.version_mc }) if (typeof oldId !== 'undefined') { - for (const i in module.exports.bot[oldId].interval) { - clearInterval(module.exports.bot[oldId].interval[i]) + for (const i in botArray[oldId].interval) { + clearInterval(botArray[oldId].interval[i]) } - delete module.exports.bot[oldId] + delete botArray[oldId] bot.id = oldId - module.exports.bot[oldId] = bot + botArray[oldId] = bot } else { - bot.id = module.exports.bot.length - module.exports.bot.push(bot) + bot.id = botArray.length + botArray.push(bot) } - + bot.host = host bot.interval = {} @@ -61,14 +61,14 @@ const createBot = function createBot (host, oldId) { console.log(`[${bot.id}] [${type}] ${msg}`) } - loadplug(bot.id) + //loadplug(bot.id) bot._client.on('error', (err) => { console.log(err) }) } -for (const i in settings.servers) { - createBot(settings.servers[i]) +for (const i in settings.default.servers) { + createBot(settings.default.servers[i]) } -module.exports.createBot = createBot +//module.exports.createBot = createBot diff --git a/util/usergen.js b/util/usergen.js index ce845c3..5ea79c6 100644 --- a/util/usergen.js +++ b/util/usergen.js @@ -29,10 +29,11 @@ const rsg = function (count) { } return output } -module.exports = function (legal) { +const generateUser = function (legal) { if (legal) { return Math.floor(Math.random() * 1000000).toString() } else { return rsg(6 + Math.floor(Math.random() * 3)) } } +export { generateUser } \ No newline at end of file