Fixed some issues regarding eris-sharder and newer eris versions

This commit is contained in:
TheEssem 2021-04-29 16:56:32 -05:00
parent 33808685f3
commit 19922858f2
16 changed files with 61 additions and 56 deletions

1
app.js
View file

@ -47,6 +47,7 @@ const master = new Master(`Bot ${process.env.TOKEN}`, "/shard.js", {
}); });
master.on("stats", async (stats) => { master.on("stats", async (stats) => {
master.broadcast(0, Object.assign(stats, { _eventName: "stat" }));
// dbl posting // dbl posting
if (dbl) { if (dbl) {
await dbl.postStats({ await dbl.postStats({

View file

@ -1,6 +1,8 @@
class Command { class Command {
constructor(client, message, args, content) { constructor(client, cluster, ipc, message, args, content) {
this.client = client; this.client = client;
this.cluster = cluster;
this.ipc = ipc;
this.message = message; this.message = message;
this.args = args; this.args = args;
this.content = content; this.content = content;

View file

@ -2,8 +2,8 @@ const Command = require("./command.js");
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
class MusicCommand extends Command { class MusicCommand extends Command {
constructor(client, message, args, content) { constructor(client, cluster, ipc, message, args, content) {
super(client, message, args, content); super(client, cluster, ipc, message, args, content);
this.connection = soundPlayer.players.get(message.channel.guild.id); this.connection = soundPlayer.players.get(message.channel.guild.id);
} }

View file

@ -1,4 +1,5 @@
const { version } = require("../../package.json"); const { version } = require("../../package.json");
const collections = require("../../utils/collections.js");
const Command = require("../../classes/command.js"); const Command = require("../../classes/command.js");
class InfoCommand extends Command { class InfoCommand extends Command {
@ -20,7 +21,7 @@ class InfoCommand extends Command {
}, },
{ {
"name": "💬 Total Servers:", "name": "💬 Total Servers:",
"value": this.client.guilds.size "value": collections.stats.guilds ? collections.stats.guilds : `${this.client.guilds.size} (for this cluster only)`
}, },
{ {
"name": "✅ Official Server:", "name": "✅ Official Server:",

View file

@ -1,4 +1,5 @@
const { version } = require("../../package.json"); const { version } = require("../../package.json");
const collections = require("../../utils/collections.js");
const day = require("dayjs"); const day = require("dayjs");
day.extend(require("dayjs/plugin/duration")); day.extend(require("dayjs/plugin/duration"));
const os = require("os"); const os = require("os");
@ -20,15 +21,17 @@ class StatsCommand extends Command {
"value": `v${version}${process.env.NODE_ENV === "development" ? "-dev" : ""}` "value": `v${version}${process.env.NODE_ENV === "development" ? "-dev" : ""}`
}, },
{ {
"name": "Memory Usage", "name": "Cluster Memory Usage",
"value": `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB` "value": `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,
"inline": true
}, },
{ {
"name": "Shard", "name": "Total Memory Usage",
"value": this.client.guildShardMap[this.message.channel.guild.id] "value": collections.stats.totalRam ? `${collections.stats.totalRam.toFixed(2)} MB` : "Unknown",
"inline": true
}, },
{ {
"name": "Uptime", "name": "Bot Uptime",
"value": uptime "value": uptime
}, },
{ {
@ -41,11 +44,18 @@ class StatsCommand extends Command {
}, },
{ {
"name": "Library", "name": "Library",
"value": `Eris ${require("eris").VERSION}` "value": `Eris ${require("eris").VERSION}`,
"inline": true
}, },
{ {
"name": "Node.js Version", "name": "Node.js Version",
"value": process.version "value": process.version,
"inline": true
},
{
"name": "Shard",
"value": this.client.guildShardMap[this.message.channel.guild.id],
"inline": true
} }
] ]
} }

View file

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

View file

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

View file

@ -5,7 +5,7 @@ const collections = require("../utils/collections.js");
const commands = [...collections.aliases.keys(), ...collections.commands.keys()]; const commands = [...collections.aliases.keys(), ...collections.commands.keys()];
// run when someone sends a message // run when someone sends a message
module.exports = async (client, message) => { module.exports = async (client, cluster, ipc, message) => {
// ignore dms and other bots // ignore dms and other bots
if (message.author.bot) return; if (message.author.bot) return;
@ -85,7 +85,7 @@ module.exports = async (client, message) => {
try { try {
await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command); await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command);
const startTime = new Date(); const startTime = new Date();
const commandClass = new cmd(client, message, args, message.content.substring(prefix.length).trim().replace(command, "").trim()); const commandClass = new cmd(client, cluster, ipc, 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 result = await commandClass.run(); // we also provide the message content as a parameter for cases where we need more accuracy
const endTime = new Date(); const endTime = new Date();
if (typeof result === "string" || (typeof result === "object" && result.embed)) { if (typeof result === "string" || (typeof result === "object" && result.embed)) {

View file

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

View file

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

View file

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

44
package-lock.json generated
View file

@ -16,7 +16,7 @@
"duckduckgo-images-api": "^1.0.5", "duckduckgo-images-api": "^1.0.5",
"emoji-regex": "^9.2.2", "emoji-regex": "^9.2.2",
"eris": "^0.15.0", "eris": "^0.15.0",
"eris-sharder": "^1.10.0", "eris-sharder": "github:discordware/eris-sharder#eris-dev",
"file-type": "^16.1.0", "file-type": "^16.1.0",
"jsqr": "^1.3.1", "jsqr": "^1.3.1",
"lavacord": "^1.1.9", "lavacord": "^1.1.9",
@ -1163,12 +1163,12 @@
}, },
"node_modules/eris-sharder": { "node_modules/eris-sharder": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/eris-sharder/-/eris-sharder-1.10.0.tgz", "resolved": "git+ssh://git@github.com/discordware/eris-sharder.git#94b5330234ef908fa984284223f68edd3c718de2",
"integrity": "sha512-cDazqx7KKM1tpMl2+UFlxwAG7fEnGBxssf/juayVR+If+nfuzUazm0nekRre8cbU4PZMjZmQPxWmDNlOcdFfAA==", "license": "MIT",
"dependencies": { "dependencies": {
"asciiart-logo": "^0.2.6", "asciiart-logo": "^0.2.6",
"colors": "^1.1.2", "colors": "^1.1.2",
"eris": "^0.13.1", "eris": "github:abalabahaha/eris#dev",
"fancy-log": "^1.3.0" "fancy-log": "^1.3.0"
}, },
"engines": { "engines": {
@ -1176,26 +1176,20 @@
} }
}, },
"node_modules/eris-sharder/node_modules/eris": { "node_modules/eris-sharder/node_modules/eris": {
"version": "0.13.4", "version": "0.15.1-dev",
"resolved": "https://registry.npmjs.org/eris/-/eris-0.13.4.tgz", "resolved": "git+ssh://git@github.com/abalabahaha/eris.git#340ffe9118ccf8f938598c90c65418fc624608db",
"integrity": "sha512-IFA14nasCig8xp8cVCULvzBuJ0qpYqJ3XyEtm9OLdC177DYDCJ9QM2Aq+KOpejIVl7838n9AyRlLI6w9Eu3PiQ==", "license": "MIT",
"dependencies": { "dependencies": {
"ws": "^7.2.1" "ws": "^7.2.1"
}, },
"engines": { "engines": {
"node": ">=8.0.0" "node": ">=10.4.0"
}, },
"optionalDependencies": { "optionalDependencies": {
"opusscript": "^0.0.7", "opusscript": "^0.0.8",
"tweetnacl": "^1.0.1" "tweetnacl": "^1.0.1"
} }
}, },
"node_modules/eris-sharder/node_modules/opusscript": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.7.tgz",
"integrity": "sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==",
"optional": true
},
"node_modules/erlpack": { "node_modules/erlpack": {
"version": "0.1.3", "version": "0.1.3",
"resolved": "git+ssh://git@github.com/abalabahaha/erlpack.git#5d0064f9e106841e1eead711a6451f99b0d289fd", "resolved": "git+ssh://git@github.com/abalabahaha/erlpack.git#5d0064f9e106841e1eead711a6451f99b0d289fd",
@ -4841,31 +4835,23 @@
} }
}, },
"eris-sharder": { "eris-sharder": {
"version": "1.10.0", "version": "git+ssh://git@github.com/discordware/eris-sharder.git#94b5330234ef908fa984284223f68edd3c718de2",
"resolved": "https://registry.npmjs.org/eris-sharder/-/eris-sharder-1.10.0.tgz", "from": "eris-sharder@github:discordware/eris-sharder#eris-dev",
"integrity": "sha512-cDazqx7KKM1tpMl2+UFlxwAG7fEnGBxssf/juayVR+If+nfuzUazm0nekRre8cbU4PZMjZmQPxWmDNlOcdFfAA==",
"requires": { "requires": {
"asciiart-logo": "^0.2.6", "asciiart-logo": "^0.2.6",
"colors": "^1.1.2", "colors": "^1.1.2",
"eris": "^0.13.1", "eris": "github:abalabahaha/eris#dev",
"fancy-log": "^1.3.0" "fancy-log": "^1.3.0"
}, },
"dependencies": { "dependencies": {
"eris": { "eris": {
"version": "0.13.4", "version": "git+ssh://git@github.com/abalabahaha/eris.git#340ffe9118ccf8f938598c90c65418fc624608db",
"resolved": "https://registry.npmjs.org/eris/-/eris-0.13.4.tgz", "from": "eris@github:abalabahaha/eris#dev",
"integrity": "sha512-IFA14nasCig8xp8cVCULvzBuJ0qpYqJ3XyEtm9OLdC177DYDCJ9QM2Aq+KOpejIVl7838n9AyRlLI6w9Eu3PiQ==",
"requires": { "requires": {
"opusscript": "^0.0.7", "opusscript": "^0.0.8",
"tweetnacl": "^1.0.1", "tweetnacl": "^1.0.1",
"ws": "^7.2.1" "ws": "^7.2.1"
} }
},
"opusscript": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.7.tgz",
"integrity": "sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==",
"optional": true
} }
} }
}, },

View file

@ -29,7 +29,7 @@
"duckduckgo-images-api": "^1.0.5", "duckduckgo-images-api": "^1.0.5",
"emoji-regex": "^9.2.2", "emoji-regex": "^9.2.2",
"eris": "^0.15.0", "eris": "^0.15.0",
"eris-sharder": "^1.10.0", "eris-sharder": "github:discordware/eris-sharder#eris-dev",
"file-type": "^16.1.0", "file-type": "^16.1.0",
"jsqr": "^1.3.1", "jsqr": "^1.3.1",
"lavacord": "^1.1.9", "lavacord": "^1.1.9",

View file

@ -47,7 +47,7 @@ class Shard extends Base {
logger.log("log", `Loading event from ${file}...`); logger.log("log", `Loading event from ${file}...`);
const eventName = file.split(".")[0]; const eventName = file.split(".")[0];
const event = require(`./events/${file}`); const event = require(`./events/${file}`);
this.bot.on(eventName, event.bind(null, this.bot)); this.bot.on(eventName, event.bind(null, this.bot, this.clusterID, this.ipc));
} }
// connect to image api if enabled // connect to image api if enabled
@ -101,6 +101,10 @@ class Shard extends Base {
} catch { } catch {
logger.error("Might have failed to register some things"); logger.error("Might have failed to register some things");
} }
this.ipc.register("stat", (message) => {
collections.stats = message;
});
// connect to lavalink // connect to lavalink
if (!sound.status && !sound.connected) await sound.connect(this.bot); if (!sound.status && !sound.connected) await sound.connect(this.bot);
@ -117,7 +121,6 @@ class Shard extends Base {
setTimeout(activityChanger.bind(this), 900000); setTimeout(activityChanger.bind(this), 900000);
}).bind(this)(); }).bind(this)();
if (process.env.PMTWO === "true") process.send("ready");
logger.log("info", `Started cluster ${this.clusterID}.`); logger.log("info", `Started cluster ${this.clusterID}.`);
} }

View file

@ -27,4 +27,6 @@ class Cache extends Map {
} }
exports.prefixCache = new Cache(); exports.prefixCache = new Cache();
exports.disabledCache = new Cache(); exports.disabledCache = new Cache();
exports.stats = {};

View file

@ -11,12 +11,12 @@ module.exports = async (client, message, pages, timeout = 120000) => {
} }
const reactionCollector = new ReactionCollector(client, currentPage, (message, reaction, member) => emojiList.includes(reaction.name) && !member.bot, { time: timeout }); const reactionCollector = new ReactionCollector(client, currentPage, (message, reaction, member) => emojiList.includes(reaction.name) && !member.bot, { time: timeout });
reactionCollector.on("reaction", async (msg, reaction, member) => { reactionCollector.on("reaction", async (msg, reaction, member) => {
if (member === message.author.id) { if (member.id === message.author.id) {
switch (reaction.name) { switch (reaction.name) {
case "◀": case "◀":
page = page > 0 ? --page : pages.length - 1; page = page > 0 ? --page : pages.length - 1;
currentPage = await currentPage.edit(pages[page]); currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("◀", member); if (manageMessages) msg.removeReaction("◀", member.id);
break; break;
case "🔢": case "🔢":
message.channel.createMessage(`${message.author.mention}, what page do you want to jump to?`).then(askMessage => { message.channel.createMessage(`${message.author.mention}, what page do you want to jump to?`).then(askMessage => {
@ -29,7 +29,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
if (manageMessages) await response.delete(); if (manageMessages) await response.delete();
page = Number(response.content) - 1; page = Number(response.content) - 1;
currentPage = await currentPage.edit(pages[page]); currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("🔢", member); if (manageMessages) msg.removeReaction("🔢", member.id);
}); });
}).catch(error => { }).catch(error => {
throw error; throw error;
@ -38,7 +38,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
case "▶": case "▶":
page = page + 1 < pages.length ? ++page : 0; page = page + 1 < pages.length ? ++page : 0;
currentPage = await currentPage.edit(pages[page]); currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("▶", member); if (manageMessages) msg.removeReaction("▶", member.id);
break; break;
case "🗑": case "🗑":
reactionCollector.emit("end"); reactionCollector.emit("end");