This commit is contained in:
2025-05-04 19:22:31 -04:00
parent ddc6f2d167
commit 7c26d2f0a3
15 changed files with 958 additions and 318 deletions

View File

@ -3,18 +3,60 @@
const conf = require('../conf');
const {sleep, nextTick} = require('../utils');
class GuardianFarm{
constructor(args){
this.bot = args.bot;
class Plugin{
plunginsLoaded = {};
constructor(options){
this.bot = options.bot;
}
async load(pluginName, options){
if(pluginName in this.plunginsLoaded) throw new Error(`Plugin ${pluginName} already loaded`);
let plugin = new this.bot.constructor.plungins[pluginName]({...options, bot: this.bot})
this.plunginsLoaded[pluginName] = plugin;
return await plugin.init();
}
unload(pluginName){
console.log('Plugin.unload', pluginName);
if(pluginName){
try{
return this.plunginsLoaded[pluginName].unload();
delete this.plunginsLoaded[pluginName];
}catch(error){
console.error('Plugin.unload error', pluginName);
}
}
for(pluginName in this.plunginsLoaded){
console.log('Plugin.unload load', pluginName)
try{
this.plunginsLoaded[pluginName].unload();
}catch(error){
console.error(`Plugin.unload ${pluginName} Error`, error);
}
delete this.plunginsLoaded[pluginName];
}
}
}
class GuardianFarm extends Plugin{
constructor(options){
super(options);
this.isDangerous = true;
this.isAction = true;
this.onTimeListen;
}
async init(){
console.log('GuardianFarm started')
console.log('GuardianFarm started');
this.onReadyListen = this.bot.on('onReady', async ()=>{
await sleep(3000);
let lastTimeListen = this.bot.bot.time.timeOfDay;
await this.load('Swing');
this.onTimeListen = this.bot.bot.on('time', async ()=>{
let isDay = lastTimeListen < this.bot.bot.time.timeOfDay;
lastTimeListen = this.bot.bot.time.timeOfDay;
@ -23,7 +65,6 @@ class GuardianFarm{
await this.onNewDay();
}
});
await this.bot.pluginLoad('Swing');
});
@ -31,8 +72,9 @@ class GuardianFarm{
}
unload(){
super.unload();
this.onReadyListen();
this.onTimeListen();
// this.onTimeListen();
return true;
}
@ -40,10 +82,10 @@ class GuardianFarm{
async onNewDay(){
try{
console.log('GuardianFarm.onNewDay new day!');
await this.bot.pluginUnload('Swing');
await this.bot.pluginLoad('Craft');
await this.bot.pluginUnload('Craft');
await this.bot.pluginLoad('Swing');
await this.unload('Swing');
await this.load('Craft');
await this.unload('Craft');
await this.load('Swing');
}catch(error){
console.error('Error in GuardianFarm.onNewDay:', error);
}