Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
// shard base
|
2021-07-05 04:15:27 +00:00
|
|
|
const { BaseClusterWorker } = require("eris-fleet");
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
// path stuff
|
|
|
|
const { readdir } = require("fs").promises;
|
|
|
|
// fancy loggings
|
|
|
|
const logger = require("./utils/logger.js");
|
|
|
|
// initialize command loader
|
|
|
|
const handler = require("./utils/handler.js");
|
|
|
|
// lavalink stuff
|
|
|
|
const sound = require("./utils/soundplayer.js");
|
|
|
|
// database stuff
|
|
|
|
const database = require("./utils/database.js");
|
|
|
|
// command collections
|
|
|
|
const collections = require("./utils/collections.js");
|
|
|
|
// playing messages
|
2021-04-23 20:03:48 +00:00
|
|
|
const { messages } = require("./messages.json");
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
// other stuff
|
|
|
|
const misc = require("./utils/misc.js");
|
|
|
|
// generate help page
|
|
|
|
const helpGenerator =
|
|
|
|
process.env.OUTPUT !== "" ? require("./utils/help.js") : null;
|
2021-07-31 05:04:38 +00:00
|
|
|
// whether a broadcast is currently in effect
|
|
|
|
let broadcast = false;
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
|
2021-07-05 04:15:27 +00:00
|
|
|
class Shard extends BaseClusterWorker {
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
constructor(bot) {
|
|
|
|
super(bot);
|
2021-07-05 04:15:27 +00:00
|
|
|
|
|
|
|
this.init();
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
// register commands and their info
|
|
|
|
const soundStatus = await sound.checkStatus();
|
|
|
|
logger.log("info", "Attempting to load commands...");
|
|
|
|
for await (const commandFile of this.getFiles("./commands/")) {
|
|
|
|
logger.log("log", `Loading command from ${commandFile}...`);
|
|
|
|
try {
|
|
|
|
await handler.load(commandFile, soundStatus);
|
|
|
|
} catch (e) {
|
|
|
|
logger.error(`Failed to register command from ${commandFile}: ${e}`);
|
|
|
|
}
|
|
|
|
}
|
2021-05-02 20:16:48 +00:00
|
|
|
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
// register events
|
|
|
|
const events = await readdir("./events/");
|
|
|
|
logger.log("info", `Attempting to load ${events.length} events...`);
|
|
|
|
for (const file of events) {
|
|
|
|
logger.log("log", `Loading event from ${file}...`);
|
|
|
|
const eventName = file.split(".")[0];
|
|
|
|
const event = require(`./events/${file}`);
|
2021-07-05 04:15:27 +00:00
|
|
|
this.bot.on(eventName, event.bind(null, this.bot, this.clusterID, this.workerID, this.ipc));
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
}
|
2021-05-02 20:16:48 +00:00
|
|
|
|
2021-04-22 14:21:58 +00:00
|
|
|
// generate docs
|
2021-05-22 00:08:26 +00:00
|
|
|
if (helpGenerator) {
|
|
|
|
await helpGenerator.generateList();
|
|
|
|
if (this.clusterID === 0 && helpGenerator) {
|
|
|
|
await helpGenerator.createPage(process.env.OUTPUT);
|
|
|
|
logger.log("info", "The help docs have been generated.");
|
|
|
|
}
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 17:31:53 +00:00
|
|
|
this.ipc.register("reload", async (message) => {
|
2021-07-06 12:53:09 +00:00
|
|
|
const result = await handler.unload(message.msg);
|
2021-04-30 17:31:53 +00:00
|
|
|
if (result) return this.ipc.broadcast("reloadFail", { result: result });
|
2021-07-06 12:53:09 +00:00
|
|
|
const result2 = await handler.load(collections.paths.get(message.msg));
|
2021-04-30 17:31:53 +00:00
|
|
|
if (result2) return this.ipc.broadcast("reloadFail", { result: result2 });
|
|
|
|
return this.ipc.broadcast("reloadSuccess");
|
|
|
|
});
|
2021-05-22 15:10:42 +00:00
|
|
|
|
2021-07-05 04:15:27 +00:00
|
|
|
this.bot.privateChannels.limit = 0;
|
|
|
|
|
2021-05-22 15:10:42 +00:00
|
|
|
this.ipc.register("soundreload", async () => {
|
|
|
|
const soundStatus = await sound.checkStatus();
|
|
|
|
if (!soundStatus) {
|
|
|
|
const length = await sound.connect(this.bot);
|
|
|
|
return this.ipc.broadcast("soundReloadSuccess", { length });
|
|
|
|
} else {
|
|
|
|
return this.ipc.broadcast("soundReloadFail");
|
|
|
|
}
|
|
|
|
});
|
2021-07-31 05:04:38 +00:00
|
|
|
|
|
|
|
this.ipc.register("playbroadcast", async (message) => {
|
|
|
|
this.bot.editStatus("dnd", {
|
|
|
|
name: `${message.msg} | @${this.bot.user.username} help`,
|
|
|
|
});
|
|
|
|
broadcast = true;
|
|
|
|
return this.ipc.broadcast("broadcastSuccess");
|
|
|
|
});
|
|
|
|
|
|
|
|
this.ipc.register("broadcastend", async () => {
|
|
|
|
this.bot.editStatus("dnd", {
|
|
|
|
name: `${misc.random(messages)} | @${this.bot.user.username} help`,
|
|
|
|
});
|
|
|
|
broadcast = false;
|
|
|
|
return this.ipc.broadcast("broadcastEnd");
|
|
|
|
});
|
2021-04-21 18:08:52 +00:00
|
|
|
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
// connect to lavalink
|
2021-07-05 04:15:27 +00:00
|
|
|
if (!sound.status && !sound.connected) sound.connect(this.bot);
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
|
2021-07-05 04:15:27 +00:00
|
|
|
database.setup();
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
|
2021-07-31 05:04:38 +00:00
|
|
|
this.activityChanger();
|
|
|
|
|
|
|
|
logger.log("info", `Started worker ${this.workerID}.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set activity (a.k.a. the gamer code)
|
|
|
|
activityChanger() {
|
|
|
|
if (!broadcast) {
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
this.bot.editStatus("dnd", {
|
|
|
|
name: `${misc.random(messages)} | @${this.bot.user.username} help`,
|
|
|
|
});
|
2021-07-31 05:04:38 +00:00
|
|
|
}
|
2021-08-01 03:26:48 +00:00
|
|
|
setTimeout(this.activityChanger.bind(this), 900000);
|
2021-07-05 04:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async* getFiles(dir) {
|
|
|
|
const dirents = await readdir(dir, { withFileTypes: true });
|
|
|
|
for (const dirent of dirents) {
|
|
|
|
if (dirent.isDirectory()) {
|
|
|
|
yield* this.getFiles(dir + dirent.name);
|
|
|
|
} else {
|
|
|
|
yield dir + (dir.charAt(dir.length - 1) !== "/" ? "/" : "") + dirent.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shutdown(done) {
|
2021-07-06 00:20:21 +00:00
|
|
|
logger.log("warn", "Shutting down...");
|
2021-07-05 04:15:27 +00:00
|
|
|
this.bot.editStatus("dnd", {
|
|
|
|
name: "Restarting/shutting down..."
|
|
|
|
});
|
|
|
|
for (const command in collections.commands) {
|
|
|
|
handler.unload(command);
|
|
|
|
}
|
|
|
|
require("./utils/database.js").stop();
|
|
|
|
done();
|
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-02 20:16:48 +00:00
|
|
|
module.exports = Shard;
|