Skip to content

Instantly share code, notes, and snippets.

@melmsie
Created September 15, 2018 17:54
Show Gist options
  • Save melmsie/9d1864efbae8ea322e4f44c37de47049 to your computer and use it in GitHub Desktop.
Save melmsie/9d1864efbae8ea322e4f44c37de47049 to your computer and use it in GitHub Desktop.
//Main JS file
const Eris = require('eris');
Eris.Client.prototype.setupListeners = function() {
if (!this._listeners) this._listeners = [];
for (let listener of this._listeners) {
this.removeListener(listener.eventName, listener.listener);
}
this._listeners = [];
let listenerFuncs = require('./listeners.js');
for (let listenerFunc of listenerFuncs) {
this._listeners.push({'eventName': listenerFunc.eventName, 'listener': listenerFunc.listener});
this.on(listenerFunc.eventName, listenerFunc.listener);
}
};
const config = require('./src/config.json')
const Sharder = require('eris-sharder').Master;
const sharder = new Sharder(config.token, config.path, config.options);
//File run by sharder
const Base = require('eris-sharder').Base;
class Class extends Base{
constructor(bot) {
super(bot);
}
launch() {
require('./bot.js')(this);
}
}
module.exports = Class;
//bot.js
module.exports = (cluster) => {
//whatever the fuck you would normally put in launch
let client = cluster.bot;
cluster.ipc.register('reloadbs', () => {
delete require.cache[require.resolve('./reload.js')];
require('./reload.js')();
client.setupListeners();
});
console.log(`Cluster #${cluster.clusterID} is ready`);
};
//reload.js
module.exports = function() {
delete require.cache[require.resolve('./bot.js')];
delete require.cache[require.resolve('./cache.js')];
delete require.cache[require.resolve('./cluster.js')];
delete require.cache[require.resolve('./commands.js')];
delete require.cache[require.resolve('./duel.js')];
delete require.cache[require.resolve('./functions.js')];
delete require.cache[require.resolve('./help.js')];
delete require.cache[require.resolve('./listeners.js')];
delete require.cache[require.resolve('./main.js')];
delete require.cache[require.resolve('./messageCollector.js')];
delete require.cache[require.resolve('./onMessage.js')];
delete require.cache[require.resolve('./trade.js')];
delete require.cache[require.resolve('./unhandledRejection.js')];
delete require.cache[require.resolve('./uncaughtException.js')];
};
// To reload everything, just use client.cluster.ipc.broadcast('reloadbs', {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment