Add plugin auto-detection and loading
This will probably break something later, because it loads the plugins after the bot is initialized
This commit is contained in:
parent
040bb752f1
commit
1a4d9bc52e
2 changed files with 19 additions and 0 deletions
15
index.js
15
index.js
|
@ -2,9 +2,24 @@ import { createClient } from "minecraft-protocol";
|
||||||
import { default 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 { generateUser } from './util/usergen.js'
|
||||||
import EventEmitter from 'node:events'
|
import EventEmitter from 'node:events'
|
||||||
|
import { readdirSync } from "node:fs";
|
||||||
|
|
||||||
const bots = [];
|
const bots = [];
|
||||||
|
|
||||||
|
const bpl = readdirSync('plugins')
|
||||||
|
for (const plugin of bpl) {
|
||||||
|
if (!plugin.endsWith('.js')) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
import(`./plugins/${plugin}`).then((pluginItem)=>{
|
||||||
|
for(const bot of bots){
|
||||||
|
pluginItem.load(bot)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) { console.log(e) }
|
||||||
|
}
|
||||||
|
|
||||||
const createBot = function createBot (host, oldId) {
|
const createBot = function createBot (host, oldId) {
|
||||||
const bot = new EventEmitter()
|
const bot = new EventEmitter()
|
||||||
bot._client = createClient({
|
bot._client = createClient({
|
||||||
|
|
4
plugins/helloworld.js
Normal file
4
plugins/helloworld.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
const load = (b) => {
|
||||||
|
console.log(`Test plugin loaded on bot ${b.id}`)
|
||||||
|
}
|
||||||
|
export { load }
|
Loading…
Reference in a new issue