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
This commit is contained in:
Essem 2021-04-12 11:16:12 -05:00 committed by GitHub
parent ff8a24d0e8
commit 40223ec8b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
291 changed files with 5296 additions and 5171 deletions

View file

@ -1,6 +1,6 @@
const logger = require("../utils/logger.js");
// run when eris encounters an error
module.exports = async (error, id) => {
module.exports = async (client, error, id) => {
logger.error(`An error event was sent by Eris in shard ${id}: \n${error.message}`);
};

View file

@ -2,7 +2,7 @@ const db = require("../utils/database.js");
const logger = require("../utils/logger.js");
// run when the bot is added to a guild
module.exports = async (guild) => {
module.exports = async (client, guild) => {
logger.log("info", `[GUILD JOIN] ${guild.name} (${guild.id}) added the bot.`);
await db.addGuild(guild);
};

View file

@ -1,6 +1,6 @@
const logger = require("../utils/logger.js");
// run when the bot is removed from a guild
module.exports = async (guild) => {
module.exports = async (client, guild) => {
logger.log(`[GUILD LEAVE] ${guild.name} (${guild.id}) removed the bot.`);
};

View file

@ -1,12 +1,11 @@
const fs = require("fs");
const client = require("../utils/client.js");
const database = require("../utils/database.js");
const logger = require("../utils/logger.js");
const collections = require("../utils/collections.js");
const commands = [...collections.aliases.keys(), ...collections.commands.keys()];
// run when someone sends a message
module.exports = async (message) => {
module.exports = async (client, message) => {
// ignore dms and other bots
if (message.author.bot) return;
@ -82,11 +81,12 @@ module.exports = async (message) => {
if (!cmd) return;
// actually run the command
logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`);
logger.log("log", `${message.author.username} (${message.author.id}) ran command ${command}`);
try {
await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command);
const startTime = new Date();
const result = await cmd(message, args, rawContent.replace(command, "").trim()); // we also provide the message content as a parameter for cases where we need more accuracy
const commandClass = new cmd(client, message, args, message.content.substring(prefix.length).trim().replace(command, "").trim());
const result = await commandClass.run(); // we also provide the message content as a parameter for cases where we need more accuracy
const endTime = new Date();
if (typeof result === "string" || (typeof result === "object" && result.embed)) {
await client.createMessage(message.channel.id, result);

View file

@ -1,7 +1,7 @@
const player = require("../utils/soundplayer.js");
// run when a raw packet is sent, used for sending data to lavalink
module.exports = async (packet) => {
module.exports = async (client, packet) => {
if (!player.manager) return;
switch (packet.t) {
case "VOICE_SERVER_UPDATE":

View file

@ -1,31 +0,0 @@
const client = require("../utils/client.js");
const database = require("../utils/database.js");
const logger = require("../utils/logger.js");
const messages = require("../messages.json");
const misc = require("../utils/misc.js");
const soundPlayer = require("../utils/soundplayer.js");
const helpGenerator =
process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
const first = process.env.PMTWO === "true" ? process.env.NODE_APP_INSTANCE === "0" : true;
// run when ready
module.exports = async () => {
// connect to lavalink
if (!soundPlayer.status && !soundPlayer.connected) await soundPlayer.connect();
await database.setup();
// generate docs
if (helpGenerator && first) await helpGenerator(process.env.OUTPUT);
// set activity (a.k.a. the gamer code)
(async function activityChanger() {
client.editStatus("dnd", {
name: `${misc.random(messages)} | @${client.user.username} help`,
});
setTimeout(activityChanger, 900000);
})();
if (process.env.PMTWO === "true") process.send("ready");
logger.log(`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
};

View file

@ -1,9 +1,8 @@
const soundPlayer = require("../utils/soundplayer.js");
const client = require("../utils/client.js");
const AwaitRejoin = require("../utils/awaitrejoin.js");
const { random } = require("../utils/misc.js");
module.exports = async (member, oldChannel) => {
module.exports = async (client, member, oldChannel) => {
const connection = soundPlayer.players.get(oldChannel.guild.id);
if (connection && oldChannel.id === connection.voiceChannel.id) {
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id).length === 0) {

View file

@ -1,5 +1,5 @@
const leaveHandler = require("./voiceChannelLeave.js");
module.exports = async (member, newChannel, oldChannel) => {
module.exports = async (client, member, newChannel, oldChannel) => {
await leaveHandler(member, oldChannel);
};

View file

@ -1,6 +1,6 @@
const logger = require("../utils/logger.js");
// run when eris encounters a warning
module.exports = async (warn, id) => {
module.exports = async (client, warn, id) => {
logger.warn(`A warn event was sent by Eris in shard ${id}: \n${warn.toString()}`);
};